Skip to content

Latest commit

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

VIM cheat sheet

Translations

ToDo

  • add more info about:
    • search
    • replace
    • go to line
    • go to char in line
    • replace current symbol
  • add Screencast GIFs with show-cases
  • create github.io page with copyable by click commands
  • add best about VIM (vim ide, plugins and other awesome-vim)

Exit, saving, edit

CommandDescription
:qexit from file
:wsave file/write file content
:ereload file content
!run command anyway (force run)
:wqyou can combine commands (in this example, the file will be saved and closed)
:xsame as :wq
ZZsame as :wq
:q!you can combine commands (force quit anyway, for example, after the changes made, without saving them)

Common usage

CommandDescription
iinsert / enter mode
ainsert / enter mode
ESC (Ctrl+[)usual mode
hjklmoving cursor in different directions
oadd a line after the current
Shift+oadd a line before the current
uundo the last command
Ctrl+rundo the undo the last command(redo) / repeat the last command
ggmove cursor to the top of the file
Shift+gmove cursor to the end of the file
Shift+amove cursor to the end of the line and go into edit mode
Shift+vswitch to visual mode
dddelete current (selected) line/lines (cut)
yycopy current (selected) line/lines
ppaste from clipboard (internal vim clipboard)
/start typing search phrase
nnext search result
Shift+nprevious search result
^move cursor to beginning of line
$move cursor to end of line
Ctrl+bmove one screen back
Ctrl+fmove one screen forward
create new bookmark with name 'a'
'amove to bookmark 'a'

Windows

CommandDescription
ctrl+w ssplit window horizontally
ctrl+w vsplit window vertically
ctrl+w <movement_key>move to window
ctrl+w Kmove current window to top
ctrl+w _maximize size of current window
ctrl+w = align all windows

Tabs

CommandDescription
:tabnew [filename]open new tab
:tabf pat*ernopen new tab by pattern
:tabslist opened tabs
gt или :tabnnext tab
g Shift+t или :tabpprevious tab
:tabfirst или :tabfirfirst tab
:tablastlast tab
:tabm nmove tab to n (from 0)
:tabdo commandapply command to all tabs

Useful links

Config for .vimrc

Use 4 spaces instead of tab

Add to file ~/.vimrc:

set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab

Use arrows to move through document

Add to file ~/.vimrc:

:set nocompatible

I warn you that using arrows to navigate in VIM is a bad manner, because of ten-finger print (you have to remove your right hand from its usual position), speed slows down etc. (google it yourself)

Other

  • Show line numbers: set number
  • Highlight search: set hlsearch
  • Ignore case match in search: set ignorecase
  • Dynamically highlight search on typing: set incsearch
  • Always show status row: set laststatus=2
  • Always show file title: set title

Indent settings

It could be a little bit annoying while editing some files (e.g. yaml) vim will autoindent your file.

Add this to your .vimrc file to disable auto-indent when typing # (hash) in Yaml files and set Tab and auto-indent to 2 spaces for yaml files

autocmd Filetype yaml setlocal indentkeys-=0# tabstop=2 shiftwidth=2

To debug your current indent settings use this command:

:verbose set autoindent? smartindent? cindent? cinkeys? indentexpr?

read more about this here and here

Enable .vimrc for sudo

Best practice is to use sudoedit instead of sudo vim. You should be doing that anyway. Make sure your EDITOR environment variable is set to vim (probably already is, or vim is the default; you can set it in your .profile analog if need be).

  • You can check current EDITOR value by this command: echo $EDITOR
  • To set EDITOR value: export EDITOR='vim'

Set Vim as default editor

To set vim as editor by default - add the following line to the ~/.bashrc file: export EDITOR='vim'

License

Contributors