A very simple question, is there some way to show constantly the current working directory at the bottom of the file opened by vim? Thanks.
Note this is a different question as here: How can I permanently display the path of the current file in Vim?
There we want to show the full path of the current file viewed, but what I am thinking is to show both, maybe two lines on the bottom of file: one for full path currently viewed; the other for the current working directory. These two could be different as we can open a file that's not in the current working directory.
The pwd command can be used to determine the present working directory. and the cd command can be used to change the current working directory.
Every command you run has its own current working directory. When you start a terminal emulator, your first cwd is your home directory ( /home/user on Linux, /Users/user on macOS, C:\\Users\user on Windows), and then you can use cd to change the working directory.
: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.
The current working directory is the directory in which the user is currently working in. Each time you interact with your command prompt, you are working within a directory. By default, when you log into your Linux system, your current working directory is set to your home directory.
If all that is wanted is to display the name of the current file, type Ctrl-G (or press 1 then Ctrl-G for the full path).
The command :Explore opens the file explorer window. 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).
Use Vim's built-in :cd command to change directory, followed by the NERDTree CD command (note: that's a normal-mode mapping, not an Ex : command.) (Note that tab completion will work here to complete the directory name.) Then use CD in the NERDTree pane to use the current directory as the new root.
You can do it by adding these lines in your .vimrc
set laststatus=2
set statusline=%!getcwd()
The first setting is to configure statusline to be always visible, second one is to add a current working directory to statusline.
More on
:h laststatus
:h statusline
:h getcwd()
Edit: This is an answer to OP's changed question:
It is not possible to have two-line statusline (at least to my knowledge). But it is possible to add e.g. some formatting. So
set laststatus=2
set statusline=%F
set statusline+=%=
set statusline+=%{getcwd()}
To further study I recommend to read help I mentioned before. Also this question might be of some interest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With