vim
Contents
About
Compiled in features
To determine vims capabilities run vim --version
+ means compiled in
- means not compiled in
Example on Debian 11
1 vim --version
2 VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 31 2021 15:40:05)
3 Included patches: 1-3565
4 Modified by team+vim@tracker.debian.org
5 Compiled by team+vim@tracker.debian.org
6 Huge version with X11-Athena GUI. Features included (+) or not (-):
7 +acl +file_in_path +mouse_urxvt -tag_any_white
8 +arabic +find_in_path +mouse_xterm +tcl
9 +autocmd +float +multi_byte +termguicolors
10 +autochdir +folding +multi_lang +terminal
11 -autoservername -footer -mzscheme +terminfo
12 +balloon_eval +fork() +netbeans_intg +termresponse
13 +balloon_eval_term +gettext +num64 +textobjects
14 +browse -hangul_input +packages +textprop
15 ++builtin_terms +iconv +path_extra +timers
16 +byte_offset +insert_expand +perl +title
17 +channel +ipv6 +persistent_undo +toolbar
18 +cindent +job +popupwin +user_commands
19 +clientserver +jumplist +postscript +vartabs
20 +clipboard +keymap +printer +vertsplit
21 +cmdline_compl +lambda +profile +virtualedit
22 +cmdline_hist +langmap -python +visual
23 +cmdline_info +libcall +python3 +visualextra
24 +comments +linebreak +quickfix +viminfo
25 +conceal +lispindent +reltime +vreplace
26 +cryptv +listcmds +rightleft +wildignore
27 +cscope +localmap +ruby +wildmenu
28 +cursorbind +lua +scrollbind +windows
29 +cursorshape +menu +signs +writebackup
30 +dialog_con_gui +mksession +smartindent +X11
31 +diff +modify_fname +sodium +xfontset
32 +digraphs +mouse +sound +xim
33 -dnd +mouseshape +spell +xpm
34 -ebcdic +mouse_dec +startuptime +xsmp_interact
35 +emacs_tags +mouse_gpm +statusline +xterm_clipboard
36 +eval -mouse_jsbterm -sun_workshop -xterm_save
37 +ex_extra +mouse_netterm +syntax
38 +extra_search +mouse_sgr +tag_binary
39 -farsi -mouse_sysmouse -tag_old_static
40 system vimrc file: "$VIM/vimrc"
41 user vimrc file: "$HOME/.vimrc"
42 2nd user vimrc file: "~/.vim/vimrc"
43 user exrc file: "$HOME/.exrc"
44 system gvimrc file: "$VIM/gvimrc"
45 user gvimrc file: "$HOME/.gvimrc"
46 2nd user gvimrc file: "~/.vim/gvimrc"
47 defaults file: "$VIMRUNTIME/defaults.vim"
48 system menu file: "$VIMRUNTIME/menu.vim"
49 fall-back for $VIM: "/usr/share/vim"
50 Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_ATHENA -Wdate-time -g -O2 -ffile-prefix-map=/build/vim-Co0v4N/vim-8.2.3565=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
51 Linking: gcc -L. -Wl,-z,relro -Wl,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lXaw -lXmu -lXext -lXt -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -ldl -lm -ltinfo -lselinux -lcanberra -lsodium -lacl -lattr -lgpm -ldl -L/usr/lib -llua5.2 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.32/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.9/config-3.9-x86_64-linux-gnu -lpython3.9 -lcrypt -lpthread -ldl -lutil -lm -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.7 -lm -L/usr/lib
Example on NixOS LiveCD
1 VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jan 01 1980 00:00:00)
2 Included patches: 1-3451
3 Compiled by nixbld
4 Huge version without GUI. Features included (+) or not (-):
5 +acl +file_in_path +mouse_urxvt -tag_any_white
6 +arabic +find_in_path +mouse_xterm -tcl
7 +autocmd +float +multi_byte +termguicolors
8 +autochdir +folding +multi_lang +terminal
9 -autoservername -footer -mzscheme +terminfo
10 -balloon_eval +fork() +netbeans_intg +termresponse
11 +balloon_eval_term +gettext +num64 +textobjects
12 -browse -hangul_input +packages +textprop
13 ++builtin_terms +iconv +path_extra +timers
14 +byte_offset +insert_expand -perl +title
15 +channel +ipv6 +persistent_undo -toolbar
16 +cindent +job +popupwin +user_commands
17 -clientserver +jumplist +postscript +vartabs
18 -clipboard +keymap +printer +vertsplit
19 +cmdline_compl +lambda +profile +virtualedit
20 +cmdline_hist +langmap -python +visual
21 +cmdline_info +libcall -python3 +visualextra
22 +comments +linebreak +quickfix +viminfo
23 +conceal +lispindent +reltime +vreplace
24 +cryptv +listcmds +rightleft +wildignore
25 +cscope +localmap -ruby +wildmenu
26 +cursorbind -lua +scrollbind +windows
27 +cursorshape +menu +signs +writebackup
28 +dialog_con +mksession +smartindent -X11
29 +diff +modify_fname -sodium -xfontset
30 +digraphs +mouse -sound -xim
31 -dnd -mouseshape +spell -xpm
32 -ebcdic +mouse_dec +startuptime -xsmp
33 +emacs_tags -mouse_gpm +statusline -xterm_clipboard
34 +eval -mouse_jsbterm -sun_workshop -xterm_save
35 +ex_extra +mouse_netterm +syntax
36 +extra_search +mouse_sgr +tag_binary
37 -farsi -mouse_sysmouse -tag_old_static
38 system vimrc file: "$VIM/vimrc"
39 user vimrc file: "$HOME/.vimrc"
40 2nd user vimrc file: "~/.vim/vimrc"
41 user exrc file: "$HOME/.exrc"
42 defaults file: "$VIMRUNTIME/defaults.vim"
43 fall-back for $VIM: "
44 /nix/store/hglqk4g9ajgk135fdhapm9rns95c3f88-vim-8.2.3451/share/vim"
45 Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
46 Linking: gcc -Wl,--as-needed -o vim -lm -ltinfo -ldl
Basic Adjustments
You can override /etc/vim/vimrc with /etc/vim/vimrc.local Create a local copy of /etc/vim/vimrc to let maintainer provide more distribution vimrc, that we don't want to interact during system upgrades. Try to acomplish this in vim itself, because a simple copy will create a ugly source recursion.
or just simply copy it and deal with the error
1 cp /etc/vim/vimrc{,.local}
Configure vim globally:
skip defaults (mouse mode is irritating)
- Enable syntax-highlighting
background=dark
- jump to last position
- enable indentation plugin
- show (partial)cmd in status line
- matching brackets
Remove source from the end of file to avoid a sourcing loop
/etc/vim/vimrc.local
1 " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
2 " the call to :runtime you can find below. If you wish to change any of those
3 " settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
4 " will be overwritten everytime an upgrade of the vim packages is performed.
5 " It is recommended to make changes after sourcing debian.vim since it alters
6 " the value of the 'compatible' option.
7
8 " This line should not be removed as it ensures that various options are
9 " properly set to work with the Vim-related packages available in Debian.
10 runtime! debian.vim
11
12 " Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
13 " This happens after /etc/vim/vimrc(.local) are loaded, so it will override
14 " any settings in these files.
15 " If you don't want that to happen, uncomment the below line to prevent
16 " defaults.vim from being loaded.
17 let g:skip_defaults_vim = 1
18
19 " Uncomment the next line to make Vim more Vi-compatible
20 " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
21 " options, so any other options should be set AFTER setting 'compatible'.
22 "set compatible
23
24 " Vim5 and later versions support syntax highlighting. Uncommenting the next
25 " line enables syntax highlighting by default.
26 syntax on
27
28 " If using a dark background within the editing area and syntax highlighting
29 " turn on this option as well
30 set background=dark
31
32 " Uncomment the following to have Vim jump to the last position when
33 " reopening a file
34 au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
35
36 " Uncomment the following to have Vim load indentation rules and plugins
37 " according to the detected filetype.
38 filetype plugin indent on
39
40 " The following are commented out as they cause vim to behave a lot
41 " differently from regular Vi. They are highly recommended though.
42 set showcmd " Show (partial) command in status line.
43 set showmatch " Show matching brackets.
44 "set ignorecase " Do case insensitive matching
45 "set smartcase " Do smart case matching
46 "set incsearch " Incremental search
47 "set autowrite " Automatically save before commands like :next and :make
48 "set hidden " Hide buffers when they are abandoned
49 "set mouse=a " Enable mouse usage (all modes)
DiffOrig
Found in :help recover
~/.vimrc
Copy to registers
Docs
Usage
Need support in vim for +xterm_clipboard Please see #Compiled in features
:registers or short :reg show content of all registers. May be filtered with optional register name like
:reg a b 2 + *Write and access registers with "
"*yy yank selection into the x11-selection
"+yy yank selection into the x11-clipboard
Vim offers the + and * registers to reference the system clipboard (:help quoteplus and :help quotestar). Note that on some systems, + and * are the same, while on others they are different. Generally on Linux, + and * are different:
+ corresponds to the desktop clipboard (XA_SECONDARY) that is accessed using CTRL-C, CTRL-X, and CTRL-V,
while * corresponds to the X11 primary selection (XA_PRIMARY), which stores the mouse selection and is pasted using the middle mouse button in most applications.
We can use these registers like any other register.
Tabs
Tabs are very useful. You can open many files in tabs using the option vim -p. This can be combined with xargs to find files by a pattern and open them in a vim tab
This way you can easily hit the default maximum number of tabs (10). But you can easily raise the limit in
~/.vimrc
1 set tabpagemax=20
Resizing split-screen
Please see the help page
:h window-resize
1 ==============================================================================
2 6. Window resizing window-resize
3
4 CTRL-W_=
5 CTRL-W = Make all windows (almost) equally high and wide, but use
6 'winheight' and 'winwidth' for the current window.
7 Windows with 'winfixheight' set keep their height and windows
8 with 'winfixwidth' set keep their width.
9
10 :res[ize] -N :res :resize CTRL-W_-
11 CTRL-W - Decrease current window height by N (default 1).
12 If used after :vertical: decrease width by N.
13
14 :res[ize] +N CTRL-W_+
15 CTRL-W + Increase current window height by N (default 1).
16 If used after :vertical: increase width by N.
17
18 :res[ize] [N]
19 CTRL-W CTRL-_ CTRL-W_CTRL-_ CTRL-W__
20 CTRL-W _ Set current window height to N (default: highest possible).
21
22 :{winnr}res[ize] [+-]N
23 Like :resize above, but apply the size to window {winnr}
24 instead of the current window.
25
26 z{nr}<CR> Set current window height to {nr}.
27
28 CTRL-W_<
29 CTRL-W < Decrease current window width by N (default 1).
30
31 CTRL-W_>
32 CTRL-W > Increase current window width by N (default 1).
33
34 :vertical res[ize] [N] :vertical-resize CTRL-W_bar
35 CTRL-W | Set current window width to N (default: widest possible).
colorscheme
List all color profiles
Dark, high contrast, usable in vimdiff
1 delek, murphy, slate, zellner
Change profile in vim
1 :colorscheme slate
I like "slate" ~/.vimrc
1 colorscheme slate
Synchronous scrolling of two buffers
# Open two buffers e.g. with :vsp # :set scrollbind # :syncbind
addon management
vim-pathogen
1 aptitude install vim-pathogen
~/.vimrc
1 execute pathogen#infect()
vim-addon-manager
- Please see:
man 5 vim-registry
man 5 vim-addon-manager
If a debian package provides integration with vim-registry basically a descriptive file in /usr/share/vim/registry it may be managed with the addon manager.
With the following command you can find packages, that register in vim-registry.
apt-file search /usr/share/vim/registry
Notable are especially apparmor, nginx and nftables.
Output hidden in comment.
List addons
vim-addon-manager
Or better parseable with the option -q|--query
(output hidden in comment)
User-scope install and removal
System-wide install and removal
addons
vim-youcompleteme
1 aptitude install vim-youcompleteme
~/.vimrc
vim-syntastic
1 aptitude install vim-syntastic
nerdtree
~/.vimrc
nerdtree-git-plugin
vim-nftables
- Please see also:
Syntax highlighting and indendation for nftables
1 apt install vim-nftables
Enable vim-nftables system-wide
1 vim-addon-manager -w install nftables
vim-easy-align
Install vim-easy-align
1 apt install vim-easy-align
Configure vim-easy-align ~/.vimrc
VIM mode digraph
vim.dot
1 digraph vim_mode {
2
3 graph [fontname="monospace"];
4 node [fontname="monospace"];
5 edge [fontname="monospace"];
6
7 labelloc="t";
8 label="VIM MODE DIAGRAPH";
9
10 SHELL -> NORMAL [label="vim",weight=100];
11 NORMAL -> SHELL [label="ZZ"];
12 NORMAL [shape="box"];
13 NORMAL -> INSERT [label="iIaAoOsS INS",weight=105]
14 INSERT -> NORMAL [label="ESC"];
15 INSERT -> REPLACE [label="INS"];
16 REPLACE -> INSERT [label="INS"];
17 NORMAL -> REPLACE [label="rR"];
18 REPLACE -> NORMAL [label="ESC"];
19 NORMAL -> VISUAL [label="vV^v"];
20 VISUAL -> NORMAL [label="ESC"];
21 VISUAL -> EXECUTE [label=":"];
22 VISUAL -> INSERT [label="IA"];
23 VISUAL -> REPLACE [label="r"];
24 NORMAL -> EXECUTE [label=":",weight=100];
25 EXECUTE -> NORMAL [label="ESC"];
26 EXECUTE -> SHELL [label="x wq q q!"];
27 }
Create svgs
Cheat Sheet
Source http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
Download the zip files
Modelines
- Has some security implications.
:help auto-setting :help modeline :help 'modeline' determines whether to look for modelines :help 'modelines' number of lines checked to find each modeline
- modelines maybe disabled in the system vimrc for security
enable it with :set modeline in session or .?vimrc
- Determine the file format's comment character or sequence
e.g. # ; -- // {* *} <!-- --> and leave space behind
- Place the modeline within 5 lines close to top or bottom
- Two syntaxes
- Without "set", no text can follow the options.
# vim: syntax=named:sw=4:ts=4:
- With "set", the modeline ends at the first colon not following a backslash.
# vim: set syntax=named sw=4 ts=4:
- Without "set", no text can follow the options.
Syntax
Nginx
~/.vim/filetype.vim
1 au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif
Formatting
Retab
Set desired tabstop an
Visualize whitespaces more readable then with :set list
~/.vimrc
1 nnoremap <F3> :<C-U>setlocal lcs=tab:>-,trail:-,eol:$ list! list? <CR>
Set options for indenting shell scripts
\ is a vim-script line-continuation
~/.vimrc
Use with
1 gg=G
gg … beginning of file
= … indent
G … end of file
vim-shfmt
Install
~/.vimrc