This article will be updated continuously and will contain useful configurations, tricks, life-hacks for VIM editor.
Contents:
Tabs or spaces?
There are two functions that will setup respective formatting either with spaces or tabs:
function! UseTabs()
set tabstop=4 " Size of a hard tabstop (ts).
set shiftwidth=4 " Size of an indentation (sw).
set noexpandtab " Always uses tabs instead of space characters (noet).
set autoindent " Copy indent from current line when starting a new line (ai).
endfunction
function! UseSpaces()
set tabstop=2 " Size of a hard tabstop (ts).
set shiftwidth=2 " Size of an indentation (sw).
set expandtab " Always uses spaces instead of tab characters (et).
set softtabstop=0 " Number of spaces a <Tab> counts for. When 0, featuer is off (sts).
set autoindent " Copy indent from current line when starting a new line.
set smarttab " Inserts blanks on a <Tab> key (as per sw, ts and sts).
endfunction
Add those to the ~/.vimrc
file.
They can be called in the command mode:
:call UseTabs()
:call UseSpaces()
Source: https://stackoverflow.com/a/48390668/7551001
Display hidden characters
To display special/hidden characters like tabs, spaces, caret return and so on, use the next commands:
:set list
:set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»