Hide unnecessary leading indent
Use of a plugin manager is recommended. vim-plug is what I use. Note that this plugin requires the wrap
option to be off to work, but you might not miss it as much with the extra room.
Plug 'fent/vim-relative-indent'
set nowrap
In order to provide for flexibility, relative-indent is not enabled by default. Using an autocmd
to enable it per buffer is recommended.
augroup relative_indent
autocmd!
" Apply to all filetypes except markdown and quickfix
autocmd FileType * :RelativeIndentEnable
autocmd FileType markdown :setlocal wrap
augroup END
Using the list
option with precedes
provides a helpful marker for when indent has been hidden.
set listchars+=precedes:<
set list
Note that using precedes
with tabbed files don't show correctly, see vim/vim#5927
If you'd like to know how many levels of indent are hidden, use w:relative_indent_level
. This can be used in your statusline for example.
This is my configuration with lightline
let g:lightline = {
\ 'active': {
\ 'left': [
\ ['relative_indent', 'mode', 'paste'],
\ ],
\ 'right': [['lineinfo'], ['percent'], ['fileformat', 'filetype']],
\ 'component_function': {
\ 'relative_indent': 'LightlineRelativeIndent',
\ },
\ }
function! LightlineRelativeIndent()
return repeat('<', get(w:, 'relative_indent_level', 0))
endfunction
sidescrolloff
can affect this plugin's ability to scroll the view. If you use vim-sensible, which does set sidescrolloff=5
, but you want to set sidescrolloff=0
you can do something like
augroup relative_indent
autocmd!
autocmd FileType * :setlocal sidescrolloff=0 | :RelativeIndentEnable
augroup END