+set listchars=
+" Display tabs as ">--------".
+set listchars+=tab:>-
+" Display trailing whitespace as "-".
+set listchars+=trail:-
+" Display markers for long lines when wrapping is disabled.
+set listchars+=extends:>,precedes:<
+" Display non-breakable space as "!".
+if v:version >= 700
+ set listchars+=nbsp:!
+endif
+
+" Don't draw the vertical split separator by using space as character. Thanks
+" to scp1 in #vim on Freenode (2012-06-16 16:12 CEST) for the idea to use a
+" non-breakable space. But a simple space works as well, as long as the
+" current color scheme is not reset.
+if has('windows') && has('folding')
+ set fillchars+=vert:\ " comment to prevent trailing whitespace
+endif
+
+if has('statusline')
+ " Always display the status line even if there is only one window.
+ set laststatus=2
+
+ " If there's more than one buffer return "/<nr>" (e.g. "/05") where <nr>
+ " is the highest buffer number, otherwise return nothing. Used in
+ " 'statusline' to get an overview of available buffer numbers.
+ function! s:StatuslineBufferCount()
+ let l:bufnr = bufnr('$')
+ if l:bufnr > 1
+ let l:result = '/'
+ if exists('*printf')
+ let l:result .= printf('%02d', l:bufnr)
+ else
+ " Older Vims don't have printf() (and no .= either). Emulate
+ " "%02d".
+ if l:bufnr < 10
+ let l:result = l:result . '0'
+ endif
+ let l:result = l:result . l:bufnr
+ endif
+ return l:result
+ else
+ return ''
+ endif
+ endfunction
+
+ " Like %f but use relative filename if it's shorter than the absolute path
+ " (e.g. '../../file' vs. '~/long/path/to/file'). fnamemodify()'s ':.' is
+ " not enough because it doesn't create '../'s.
+ function! s:StatuslineRelativeFilename()
+ " Display only filename for help files.
+ if &buftype == 'help'
+ return expand('%:t')
+ endif
+ " Special case for scratch files.
+ if &buftype == 'nofile'
+ return '[Scratch]'
+ endif
+
+ let l:path = expand('%')
+ " No file.
+ if l:path == ''
+ return '[No Name]'
+ endif
+ " Path is already relative, nothing to do.
+ if stridx(l:path, '/') != 0
+ return l:path
+ endif
+
+ " Absolute path to this file.
+ let l:path = expand('%:p')
+ " Shortened path to this file, thanks to bairui in #vim on Freenode
+ " (2012-06-23 00:54) for the tip to use fnamemodify(). This is what
+ " Vim normally uses as %f (minus some exceptions).
+ let l:original_path = fnamemodify(l:path, ':~')
+ " Absolute path to the current working directory.
+ let l:cwd = getcwd()
+
+ " Working directory completely contained in path, replace it with a
+ " relative path. Happens for example when opening a file with netrw.
+ " %f displays this as absolute path, but we want a relative path of
+ " course.
+ if stridx(l:path, l:cwd) == 0
+ return strpart(l:path, strlen(l:cwd) + 1)
+ endif
+
+ let l:path_list = split(l:path, '/')
+ let l:cwd_list = split(l:cwd, '/')
+
+ " Remove the common path.
+ while l:path_list[0] == l:cwd_list[0]
+ call remove(l:path_list, 0)
+ call remove(l:cwd_list, 0)
+ endwhile
+
+ " Add as many '..' as necessary for the relative path and join the
+ " path. Thanks to Raimondi in #vim on Freenode (2012-06-23 01:13) for
+ " the hint to use repeat() instead of a loop.
+ let l:path = repeat('../', len(l:cwd_list)) . join(l:path_list, '/')
+
+ " Use the shorter path, either relative or absolute.
+ if strlen(l:path) < strlen(l:original_path)
+ return l:path
+ else
+ return l:original_path
+ endif
+ endfunction
+
+ " Display unexpected 'fileformat', 'fileencoding' and 'bomb' settings.
+ function! s:StatuslineFileFormat()
+ if &fileformat != 'unix'
+ return '[' . &fileformat . ']'
+ else
+ return ''
+ endif
+ endfunction
+ function! s:StatuslineFileEncoding()
+ if &fileencoding != '' && &fileencoding != 'utf-8'
+ \ && &filetype != 'help'
+ return '[' . &fileencoding . ']'
+ else
+ return ''
+ endif
+ endfunction
+ function! s:StatuslineFileBOMB()
+ if exists('+bomb') && &bomb
+ return '[BOM]'
+ else
+ return ''
+ endif
+ endfunction
+
+ " Return current syntax group in brackets or nothing if there's none.
+ function! s:StatuslineSyntaxGroup()
+ let l:group = synIDattr(synID(line('.'), col('.'), 1), 'name')
+ if l:group != ''
+ return '[' . l:group . '] '
+ else
+ return ''
+ endif
+ endfunction
+
+ " Short function names to make 'statusline' more readable.
+ function! SBC()
+ return s:StatuslineBufferCount()
+ endfunction
+ function! SRF()
+ return s:StatuslineRelativeFilename()
+ endfunction
+ function! SFF()
+ return s:StatuslineFileFormat()
+ endfunction
+ function! SFE()
+ return s:StatuslineFileEncoding()
+ endfunction
+ function! SFB()
+ return s:StatuslineFileBOMB()
+ endfunction
+ function! SSG()
+ return s:StatuslineSyntaxGroup()
+ endfunction
+
+ set statusline=
+ " on the left
+ set statusline+=%02n " buffer number
+ set statusline+=%{SBC()} " highest buffer number
+ set statusline+=:
+ if has('modify_fname') && v:version >= 700 " some functions need 7.0
+ set statusline+=%{SRF()} " path to current file
+ else
+ set statusline+=%f " path to current file in buffer
+ endif
+ set statusline+=\ " space after path
+ set statusline+=%h " [help] if buffer is help file
+ set statusline+=%w " [Preview] if buffer is preview buffer
+ set statusline+=%m " [+] if buffer was modified,
+ " [-] if 'modifiable' is off
+ set statusline+=%r " [RO] if buffer is read only
+ if v:version >= 700 " %#..# needs 7.0
+ set statusline+=%#Error# " display warnings
+ set statusline+=%{SFF()} " - unexpected file format
+ set statusline+=%{SFE()} " - unexpected file encoding
+ set statusline+=%{SFB()} " - unexpected file byte order mask
+ set statusline+=%## " continue with normal colors
+ endif
+
+ " on the right
+ set statusline+=%= " right align
+ set statusline+=0x%-8B\ " current character under cursor as hex
+ set statusline+=%-12.(%l,%c%V%)\ " line number (%l),
+ " column number (%c),
+ " virtual column number if different
+ " than %c (%V)
+ set statusline+=%P " position in file in percent
+endif