Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the variable for current working directory in vim?

Tags:

file

vim

In vimscript, if I want to get the value of current working directory for current buffer (could be changed by :lcd), which variable or expression would I use to fetch that?

like image 264
steveyang Avatar asked Mar 09 '13 07:03

steveyang


People also ask

How do I change the current directory in Vim?

This can be an absolute or relative path, so :cd .. will move up one level. Or you can use :cd %:h which will also change to the directory the current file is in, but without setting autochdir. will change directory to your home directory (or on windows, print the current directory).

What is the name of the environment variable that holds current working folder?

Windows maintains the current directory in the environment variable %CD% .

What is cd in Vim?

:cd is a Vim command operating in the Vim program space and the directory it changes is associated with the Vim process. One way this is useful is if you try to edit a file without a path (e.g. foo. txt ) Vim will look in this directory for the file.

How do I open a folder in Vim?

Select a file or directory name and press Enter to open that file or directory. (For example :e /home/user displays the contents of that directory.) To return to the explorer window, press Ctrl-^ (usually Ctrl-6). You can also "edit" a directory to explore that directory.


1 Answers

let cwd = getcwd()

or

let cwd = fnamemodify('.', ':p')

. Both always return effective value for the current buffer, but determination of whether this is working directory local to buffer (i.e. changed by :lcd/'autochdir') or global one (i.e. changed by :cd/untouched since vim start) is the more interesting question. I do not know the answer for it.

like image 63
ZyX Avatar answered Oct 12 '22 19:10

ZyX