2

I have the following (simplified) statusline config in my vimrc:

set laststatus=2
set statusline=
set statusline+=%{getcwd()}

When I'm somewhere in my home directory on macOS, my statusline looks like this:

/Users/ruohola/dotfiles/vim

But I would want it to just show it like this:

~/dotfiles/vim

And when I would be somewhere in the root directory the path should just be shown normally e.g:

/Libarary/Application Support
1
substitute(getcwd(),$HOME,'~','')
  • When I try: set statusline+=%{substitute(getcwd(),$HOME,'~')} I get the error: E119: Not enough arguments for function: substitute. – ruohola Jun 8 at 16:28
  • I think there’s a flags argument. I put a blank string in but check the help – D. Ben Knoble Jun 8 at 16:31
  • Thanks, this works perfectly! – ruohola Jun 8 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.