Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display name of the current file in vim?

Tags:

vim

vi

People also ask

How do I find the current file name and number of lines in vim?

Pressing ctrl-g will reveal the filename, current line, the line count, your current position as a percentage, and your cursor's current column number.

Is current file name is shown in status bar?

Answer. Explanation: The current file name is shown in the Title bar.

How do I rename the current file in vim?

Navigate to the file, press R , and change the name. Press Enter to edit the file.

How do I view a full file in vi editor?

You can use the search function in vi (or vim which is more likely what you are running). In command mode, type / and the regular expression you want to search for. Show activity on this post.


: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