Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show constantly current working directory in vim

Tags:

vim

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.

like image 763
wiswit Avatar asked Oct 09 '15 08:10

wiswit


People also ask

Which method display 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.

How do I change the current directory in Vim?

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.

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.

Where is the current working directory stored?

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.

How do I get full path of file in Gvim?

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).

How do I open a folder in Vim?

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).

How do I change directory in NERDTree?

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.


1 Answers

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.

like image 124
ryuichiro Avatar answered Nov 04 '22 01:11

ryuichiro