开发者

Display name of the current file in vim?

How开发者_高级运维 do you display the filename of the file you are working on in vim?


:f (:file) will do same as <C-G>. :f! will give a untruncated version, if applicable.


ctrl+g will do it.

Also, I like to have:

set statusline="%f%m%r%h%w [%Y] [0x%02.2B]%< %F%=%4v,%4l %3p%% of %L"

Which produces:

foo.c [C] [0x23]<code/foo.c   1,   1   2% of 50

Also, as someone mentioned (but now deleted) % will be replaced with the current filename. For example:

:!echo "current file: %"
current file: foo.c
Press ENTER or type command to continue


set the status line. more info with :help statusline

These commands can go in your .vimrc file, or you can enter them as commands while in vim by typing ':' in command mode.

First, set last status to 2 using the following:

set laststatus=2

Then set status line to %f for short file name.

set statusline=%f

For the full path to the file, use %F.


:set title to display file name in window title bar.


Why so complicated? Control-G will do the job


To show the full path for any file, including resolved symlinks, use the following.

:echo resolve(expand('%:p'))

This can be added to your statusbar by adding the line below to your ~./vimrc

set statusline +=%{resolve(expand('%:p'))}\ %*


I use the amazing vimrc from amix: https://github.com/amix/vimrc

It uses the lightline.vim pluging and displays the filename on the status bar.

The great thing about using the amix/vimrc is that this plugin takes care of most of the customization, its very stable, and has been tested by 1000s of people, as you can check by looking at the number of github stars.. and the infrequent issues.

Its also updated quite frequently.

P.S.: not the author of either of the plugins.. just a fan :)


I also needed to put this in my .vimrc file:

set noruler
set laststatus=2

Then I could put something like set statusline="%f%m%r%h%w [%Y] [0x%02.2B]%< %F%=%4v,%4l %3p%% of %L" in my .vimrc file and after restarting my terminal the statusline displays properly.


One of the above suggestions had to be changed to

set statusline=%f%m%r%h%w\ [%Y]\ [0x%02.2B]%<\ %F%4v,%4l\ %3p%%\ of\ %L\ lines

to get it working. Also

set laststatus=2

was used.


To display it at the top, add this to your ~/.vimrc:

" Statusline at the top (use tabline)
set tabline=%F\ %y  " only the format
set showtabline=2   " this turns on the tabline
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜