Sunday, December 15, 2019

How to display 'current working directory' in status bar only if it differs from current file path?

In Vim 8.2 I have two information in my status line:
- full path to my current opened file
- full path to current working directory

I have set the following commands:
set laststatus=2                              " always display status line
set statusline=Opened_file:                   " label
set statusline+=%{resolve(expand('%:p'))}     " display full file path of opened file
set statusline+=\ \                           " two spaces
set statusline+=Current_working_directory:    " label
set statusline+=%{getcwd()}\ \                " display current working directory


Sample status line:
Opened_file:/home/myname/myfile.txt  Current_working_directory:/home/myname

What I would like to do is, to display current_working_directory only if it
is different then opened file.

In above example I would like to have status line (without second part; from above cmd list without last three cmd's):
Opened_file:/home/myname/myfile.txt

But if my current working directory is /opt, then I would like to have displayed
both information:
Opened_file:/home/myname/myfile.txt  Current_working_directory:/opt


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/35275211-d1e5-464c-9ab5-d9398ef809ee%40googlegroups.com.

No comments:

Post a Comment