Since Vim is a text editor, much of what you do operates on files. Vim provides a number of file-related functions.
You can manipulate file path information using expand:
echom 'Current file extension is ' . expand('%:e')
When passed a filename (through %, #, or shortcuts such as <cfile>), expand lets you parse the path using these modifiers:
- :p expand to full path
- :h head (last path component removed)
- :t tail (last path component only)
- :r root (one extension removed)
- :e extension only
See :help expand() for more information about these.
You can check the file exists (aka can be read) by using filereadable:
if filereadable(expand('%')) echom 'Current file (' . expand('%:t') . ') is readable!'endif
When executed from ...