0

I have a custom statusline that I build in a function. My function is mainly to perform some string substitutions in the path of the current file.

In init.vim

let g:mystatus = ''
function! UpdateStatusline()
    let g:mystatus =expand('%:p:~')
    let g:mystatus = substitute(g:mystatus, "foo", "bar", "g")   <--- make a substitution
    set statusline=%{g:mystatus}\ [l=%l]
endfunction

augroup StatuslineUpdate
    autocmd!
    autocmd BufEnter,BufWinEnter * call UpdateStatusline()
augroup END

At this point, when I open /home/daniel/foo.txt, I see /home/daniel/bar.txt [l=1]. ok.

Now I vertically split my view to open an other file (:vertical split other.txt).

I want the left statusline to show foo.txt (or bar.txt after substitution) and the right statusline to show other.txt.

The current behavior is that, when my cursor is on left, both statuslines are show bar.txt and when my cursor is on right, both show other.txt.

QUESTION 1: how to modify autocmd BufEnter,BufWinEnter * call UpdateStatusline() to only update the statusline on the side I'm going to ?

QUESTION 2: (maybe equivalent to question 1). How to have two independent statuslines ?

Laurent Claessens
  • 547
  • 1
  • 3
  • 18

1 Answers1

0

The trick is to not pass trough an intermediate variable and to directly chain the substitutions.

set statusline=%{expand('%:p:~')
                        \->substitute('foo','[bar]','')
                        \->substitute('blabla','[blublu]','')}
                        \ [l=%l]

Laurent Claessens
  • 547
  • 1
  • 3
  • 18