【问题标题】:neovim, statusline when vectical splitneovim,垂直分裂时的状态线
【发布时间】:2023-02-23 05:04:05
【问题描述】:

我有一个在函数中构建的自定义状态行。我的功能主要是对当前文件的路径进行一些字符串替换。

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

此时,当我打开/home/daniel/foo.txt时,我看到了/home/daniel/bar.txt [l=1]。 好的。

现在我垂直拆分视图以打开另一个文件 (:vertical split other.txt)。

我希望左侧状态栏显示foo.txt(或替换后的bar.txt),右侧状态栏显示other.txt

当前的行为是,当我的光标在左边时,两个状态行都显示bar.txt,当我的光标在右边时,两个状态行都显示other.txt

问题 1:如何修改 autocmd BufEnter,BufWinEnter * call UpdateStatusline() 以仅更新我要去的那一边的状态行?

问题 2:(可能等同于问题 1)。如何拥有两条独立的状态线?

【问题讨论】:

    标签: neovim statusline


    【解决方案1】:

    诀窍是不通过中间变量并直接链接替换。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-24
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 2019-06-23
      相关资源
      最近更新 更多