On 2019-12-15, Igor <igor2x@gmail.com> wrote:
> 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
I'd do it as follows:
fun! MyStatusLine()
return "Opened_file: %{resolve(expand('%:p'))}"
\ . "%{getcwd() == resolve(expand('%:p:h'))"
\ . "? ''"
\ . ": ' Current_working_directory:'.getcwd()}"
endf
set statusline=%!MyStatusLine()
When a status line's definition becomes a tad complicated, I prefer to
use a function.
Hope this helps,
Life.
--
--
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/qt62gf%2454fg%241%40blaine.gmane.org.
No comments:
Post a Comment