Display file info from inside vim editor

Get the name of current file from inside vim

For example, considering I am editing file /home/user/server.txt The following commands could be entered to display the information shown.

:echo @% user/server.txt directory/name of file (relative to the current working directory of /home)
:echo expand('%:t') server.txt name of file (=’tail’)
:echo expand('%:p') /home/user/server.txt full path
:echo expand('%:p:h') /home/user directory containing file (=’head’)
:echo expand('%:p:h:t') user First get the full path with :p (/home/user/server.txt), then get the head of that with :h (/home/user), then get the tail of that with :t (user)

For more info run :help expand

Information taken from this web page.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s