TOOL » NEOVIM » VIMSCRIPT

File

Functions

FunctionDescription
executable(fname)Check if fname is executable.
filereadable(fname)Returns true if the file is readable.
filewritable(fname)Returns true if the file is writable.
readfile(fname)Returns a list, which each entry is a file line.
writefile(list, fname, flags)Save list of text into file.

Filenames

FunctionDescription
expand()Expand a file or path.
fnamemodify()Modify a file or path.
tempname()Generate temporary filenames.

To deal with filenames and its paths we use expand() and fnamemodify().

vim
let curfile = expand('%:~:.')
let arbitrary = fnamemodify('myfile', ':p:~')

TIP

For more see help filename-modifiers.

ModifierDescription
:pExpand to full path.
:hHead (last path component removed).
:tTail (last path component only).
:rRoot (one extension removed).
:eExtension only.
:~Replaces $HOME with ~.
:.Path becomes relative to $PWD.