22

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 in gnome-terminal, on 12.04 LTS.

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
malhar
  • 323

5 Answers5

15

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

enter image description here

Source: gnome-terminal does not allow changing the title

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
8

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.

muru
  • 207,228
6

Simply add

set title

to your ~/.vimrc.

Example title: testfile (~/Documents) - VIM

pouellet
  • 118
1

You can append the name of the file you are editing in a tab in the following manner:

  1. 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.

user223882
  • 683
  • 8
  • 10
0

This also changes the window title if you rename a buffer:

set title
augroup WindowTitleGroup
  autocmd!
  autocmd BufEnter,BufFilePost * let &titlestring = expand('%:t')
augroup end

Putting the command in a group avoids executing the command multiple times when sourcing vimrc more than once.

This works nicely with vim-eunuch that lets you rename a file using :Rename.