Skip to content

Instantly share code, notes, and snippets.

@ericbn ericbn/.vimrc
Last active Nov 22, 2019

Embed
What would you like to do?
Vim Powerline-like status line without the need of any plugin
" Statusline (requires Powerline font)
set statusline=
set statusline+=%(%{&buflisted?bufnr('%'):''}\ \ %)
set statusline+=%< " Truncate line here
set statusline+=%f\ " File path, as typed or relative to current directory
set statusline+=%{&modified?'+\ ':''}
set statusline+=%{&readonly?'\ ':''}
set statusline+=%= " Separation point between left and right aligned items
set statusline+=\ %{&filetype!=#''?&filetype:'none'}
set statusline+=%(\ %{(&bomb\|\|&fileencoding!~#'^$\\\|utf-8'?'\ '.&fileencoding.(&bomb?'-bom':''):'')
\.(&fileformat!=#(has('win32')?'dos':'unix')?'\ '.&fileformat:'')}%)
set statusline+=%(\ \ %{&modifiable?(&expandtab?'et\ ':'noet\ ').&shiftwidth:''}%)
set statusline+=\
set statusline+=\ %{&number?'':printf('%2d,',line('.'))} " Line number
set statusline+=%-2v " Virtual column number
set statusline+=\ %2p%% " Percentage through file in lines as in |CTRL-G|
" ------------------------ 8< ------------------------
" Statusline with highlight groups (requires Powerline font, using Solarized theme)
set statusline=
set statusline+=%(%{&buflisted?bufnr('%'):''}\ \ %)
set statusline+=%< " Truncate line here
set statusline+=%f\ " File path, as typed or relative to current directory
set statusline+=%{&modified?'+\ ':''}
set statusline+=%{&readonly?'\ ':''}
set statusline+=%1*\ " Set highlight group to User1
set statusline+=%= " Separation point between left and right aligned items
set statusline+=\ %{&filetype!=#''?&filetype:'none'}
set statusline+=%(\ %{(&bomb\|\|&fileencoding!~#'^$\\\|utf-8'?'\ '.&fileencoding.(&bomb?'-bom':''):'')
\.(&fileformat!=#(has('win32')?'dos':'unix')?'\ '.&fileformat:'')}%)
set statusline+=%(\ \ %{&modifiable?(&expandtab?'et\ ':'noet\ ').&shiftwidth:''}%)
set statusline+=\ %* " Restore normal highlight
set statusline+=\ %{&number?'':printf('%2d,',line('.'))} " Line number
set statusline+=%-2v " Virtual column number
set statusline+=\ %2p%% " Percentage through file in lines as in |CTRL-G|
" Logic for customizing the User1 highlight group is the following
" - if StatusLine colors are reverse, then User1 is not reverse and User1 fg = StatusLine fg
hi StatusLine cterm=reverse gui=reverse ctermfg=14 ctermbg=8 guifg=#93a1a1 guibg=#002732
hi StatusLineNC cterm=reverse gui=reverse ctermfg=11 ctermbg=0 guifg=#657b83 guibg=#073642
hi User1 ctermfg=14 ctermbg=0 guifg=#93a1a1 guibg=#073642
@ericbn

This comment has been minimized.

Copy link
Owner Author

ericbn commented Sep 27, 2016

screen shot

With highlight group

screen shot 2017-04-21 at 7 26 05 am

screen shot 2017-04-26 at 1 32 51 pm

@ericbn

This comment has been minimized.

Copy link
Owner Author

ericbn commented Apr 21, 2017

If you use vim-sleuth, you might want to replace

set statusline+=%(\ \ %{&modifiable?(&expandtab?'et\ ':'noet\ ').&shiftwidth:''}%)

by

set statusline+=%(\ \ %{&modifiable?SleuthIndicator():''}%)
@tiberiuichim

This comment has been minimized.

Copy link

tiberiuichim commented Apr 26, 2017

I use this instead of SleuthIndicator():

function! LightLineBufSettings()
    let et = &et ==# 1 ? "•" : "➜"
    return ('│ts│'. &tabstop . '│sw│'. &shiftwidth . '│et│' . et . '│')
endfunction
@jonathaw

This comment has been minimized.

Copy link

jonathaw commented Jun 30, 2017

great status line configuration!
I can't get vim to load this status line on startup. i copied the code into a file under .vim/plugin/ and added a so ~/.vim/plugin/file to my .vimrc, but the status line will only load after i manually source the vimrc from within a vim session.

any idea as to why this is happening?

thanks

@ericbn

This comment has been minimized.

Copy link
Owner Author

ericbn commented Jul 1, 2017

@jonathaw, you can set the statusline directly on your vimrc file. Only if you already made your vimrc modular, then I'd assume you know where else to put these settings.

EDIT: If no statusline appears, you should add set laststatus=2 to your vimrc too. If this still does not solve your issue, you might want to check if a plugin is not interfering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.