Add custom statusline in vim

This commit is contained in:
Dave Gallant
2021-02-05 22:56:03 -05:00
parent 7f2028aa7d
commit da274e33de
2 changed files with 28 additions and 4 deletions

6
flake.lock generated
View File

@@ -7,11 +7,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1612396114, "lastModified": 1612561117,
"narHash": "sha256-W9B49pT2/Zzjd5GsGmjxCHcWdmBDTUVKdLrocGxA/Sc=", "narHash": "sha256-UEB+5KCINGyaAfkgqWeUhUwyBxTrlTLO+FjbYCG4exk=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "3f2f7f8efa57cb820d947b07a5a513764a45b462", "rev": "d4202875831a2d1b9dd3002d89b8c794af9e5a43",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -7,7 +7,6 @@
set hlsearch set hlsearch
set ignorecase set ignorecase
set incsearch set incsearch
set laststatus=2
set mouse=a set mouse=a
set nocompatible set nocompatible
set noswapfile set noswapfile
@@ -21,6 +20,31 @@
set tabstop=2 set tabstop=2
set wildmenu set wildmenu
" Custom statusline
function! GitBranch()
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! StatuslineGit()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
endfunction
set statusline=
set statusline+=%#PmenuSel#
set statusline+=%{StatuslineGit()}
set statusline+=%#LineNr#
set statusline+=\ %f
set statusline+=%m
set statusline+=%=
set statusline+=%#CursorColumn#
set statusline+=\ %y
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\[%{&fileformat}\]
set statusline+=\ %p%%
set statusline+=\ %l:%c
" Remember line number " Remember line number
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif