How to display the name of file which I am currently editing with vim on terminal title?
Solution 1
You must to have/create a file named .vimrc
in your home directory with the following code inside:
let &titlestring = $USER . "@" . hostname() . " " . expand("%:p")
if &term == "screen"
set t_ts=^[k
set t_fs=^[\
endif
if &term == "screen" || &term == "xterm"
set title
endif
Source: gnome-terminal does not allow changing the title
Solution 2
The current (accepted) answer doesn't work if you switch files/buffers within one of your vim sessions. The title won't get updated.
The following is enough to have automatically updated titles in gnome-terminal also when you switch files by using :e foo.txt
, :b0
, :b#
, etc.
Just place this in your ~/.vimrc
file:
autocmd BufEnter * let &titlestring = ' ' . expand("%:t")
set title
System: Ubuntu 14.10, vim 7.4.273, gnome-terminal 3.6.2-0ubunt.
Solution 3
Simply add
set title
to your ~/.vimrc
.
Example title: testfile (~/Documents) - VIM
Solution 4
You can append the name of the file you are editing in a tab in the following manner:
- go to the Menu on top of the terminal. Terminal-> Set Title-> Here you append the name of the file you are currently editing
e.g. when you open the terminal , the heading of the terminal shows only "~". pwd shows /home/xxx/
Suppose at this location, you are editing a file ABC.cpp, you can set title of the tab to "~/ABC.cpp" by appending "/ABC.cpp" in Set Title field.
Similarly, you can repeat this for other tabs too.
Related videos on Youtube
malhar
Updated on September 18, 2022Comments
-
malhar over 1 year
I am editing multiple files located in the same folder, in multiple tabs, on a single terminal.
pwd
(directory in which I am currently working) is displayed on the top of the heading of the terminal, but not the name of the file I am editing. It gets confusing when working with multiple files in the same directory.How to display the name of the current file on the top of the terminal in addition to the
pwd
.I am running
vim
in a bash shell ingnome-terminal
, on 12.04 LTS.-
terdon about 10 yearsEditing using what editor? In which shell? Which terminal emulator?
-
malhar about 10 years@terdon - Editing using Vim,bash Shell, xterm emulator
-
terdon about 10 yearsPlease edit your question to add extra info, it is hard to read and easy to miss in the comments. You can then ping the user who asked for the information by leaving a comment and including a
@
before their username. For example, to ping me:@terdon
. -
terdon about 10 years
xterm
has no tabs. Are you sure this isxterm
?echo $TERM
usually does not return the name of your terminal emulator if that's what you did. -
malhar about 10 years@terdon Yes, I did use echo$TERM. it outputs "xterm". I am using 64 bit ubuntu 12.04 LTS default terminal. Are there any other ways to check details of emulator.
-
-
Radu Rădeanu about 10 yearsAnd you will do these changes every time when you edit another file? Sounds painful...
-
Victor Sergienko over 6 yearsShouldn't
set title
be on the same line, after|
? -
Victor Sergienko over 6 yearsRelated to the question: to restore the title after exiting vim, add
set titleold=
to.vimrc
. -
user10089632 about 6 yearsThat's the single answer that worked for me and is the shortest.
-
Tinmarino over 4 yearsTo create ^[, which is escape, you need to enter CTRL+V <Esc>