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:


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


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

/Libarary/Application Support
| improve this answer | |
  • When I try: set statusline+=%{substitute(getcwd(),$HOME,'~')} I get the error: E119: Not enough arguments for function: substitute. – ruohola Jun 8 '19 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 '19 at 16:31
  • Thanks, this works perfectly! – ruohola Jun 8 '19 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.