๐ List of shortcuts which I used working with Vim
Table of Contents
- scroll one page:
- Ctrl + f - down
- Ctrl + b - up
- scroll half of window:
- Ctrl + d - down
- Ctrl + u - up
- scroll one line (without moving cursor):
- Ctrl + e - down
- Ctrl + y - up
- zz - center vertically line with cursor
- move cursor on the viewport
- H - to the top
- M - to the middle
- L - to the bottom
- move cursor on the file
- gg - to the top
- G - to the bottom
- 30% - to line which is 30% of whole file
- { - move cursor to previous empty line
- } - move cursor to next empty line
- % - jump between bracket in line
``- back cursors to previous place- Ctrl + ^ - return to previous file
- Ctrl + w = - reset windows into best width & height
- move focus
- Ctrl + w h - to left window
- Ctrl + w j - to down window
- Ctrl + w k - to up window
- Ctrl + w l - to right window
- resize window
- Ctrl + w > - decrease width size
- Ctrl + w < - increase width size
- Ctrl + w - - increase size
- Ctrl + w + - decrease size
- {number}Ctrl + w _ - set window height which is set to {number} lines
- Ctrl + w _ - maximize in height
- Ctrl + w | - maximize in width
- Ctrl + w H - move focused window to the far left
- Ctrl + w J - move focused window to the bottom
- Ctrl + w K - move focused window to the top
- Ctrl + w L - move focused window to the far right
:e FILENAME- open file to edit, replaced current window with file:tabe(:tabedit) - open file in new tab:tabc(:tabclose) - close current tab
:noh(:nohl,:nohlsearch) - clear highlight after search/foo- searching textfooin whole document (forwards)?foo- searching textfooin whole document (backwards):cw- show result list after searching:%s/foo/bar/g- replace globallyfootobar*- searching word where cursor is on it (forwards)#- searching word where cursor is on it (backwards)g*- searching partial words where cursor is on it (forwards)g#- searching partial words where cursor is on it (backwards)/\<foo- searching words starting withfoo/foo\>- searching words ending withfoo/\<foo\>- searching wordsfoo
so ~/.vimrc- reload configuration in opened editor:retab- replace current whitespaces with sets in.vimrcfile:!ls- run commandlsin shell- Ctrl + a - increment number
- Ctrl + x - decrement number
- ZZ - write files and quit
- ZQ - quit all instances of vim
- Ctrl + z - hide Vim to background - use
fgin terminal to bring it to foreground - Ctrl + l - redraw Vim windows
au VimEnter * NERDTree- auto open NERDTree plugin in each editor instance
map <F9> :NERDTreeToggle <CR>- show/hide NERDTree panel on press<F9>
m{char}- save current position into{char}- `{char} - go to saved mark
:marks- display list of current saved markers
{command}{text object or motion}
- Commands
d- delete (also cut)c- change (delete, then place in insert mode)y- yank (copy)v- visual select
- Text objects
w- wordss- sentencesp- paragraphst- tags (available in XML/HTML files)
- Motions
a- alli- int- 'tilf- find forwardF- find backward
diw- "delete in word" - remove single word when cursor is on itds{- delete nearest braces{}dt.- delete text till.
caw- "change all word" (grab the whitespace)ciw- remove the word and enter to insert modeci}- remove text in parentheses and enter to insert modecit- remove text in HTML tags
yi)- copy text inside parentheses
va"- visually select all inside double quotes (including double quotes)vi"- likeva"but without double quotesvtq- visually select text tillqletter (stop before letter)vfq- visually select text tillqletter (stop after the letter)
q{char}- start recording(do the things)q- exit from recording
@{char}
The best way is to put them to file (~/.vimrc). The default path for configuration.
syntax on- enable syntax highlightingcolorscheme molokai- set editor themeset number- enable line numberset noic- don't ignore letter case, ex. in searchingset expandtab- change tabulators to spacesset tabstop=4- number of characters as indent with the TAB keyset shiftwidth=4- number of characters as indent with insertionsset mouse=a- enable mouse in the editorset background=dark- little change for brighter colorsset autoindent- enable automatic indentionset hlsearch- enable highlighting after the searching processset incsearch- run searching process after you press any char (after '/')set nowrapscan- stop navigate through search result when a file is endsset nowrap- don't wrap linesset clipboard=unnamedplus- Vim use the same buffer as OSset guifont=Inconsolata\ 12- change font in editor
Google Chrome plugin which supports Vim navigation in the browser.
More description in the article [PL]: http://piecioshka.pl/blog/2015/01/23/vimium-plugin-do-twojej-przegladarki.html
Aside from panel with the directory structure. Some useful shortcuts:
q- exitA- maximize window- Ctrl + c - change currently highlighted directory as root
- Ctrl + u - change current directory as parent
- Ctrl + p - set focus on parent dir on NERDTree list
- Ctrl + o - on dir: open list with files; on a file: edit file
- s - open file in vertical split mode
- i - open file in horizontal split mode
Comment line with simple
- \cc - comment line (recognized filetype and comment in current lang)
- \c[SPACE] - toggle comment
- \cu - remove the comment
- \cs - comment line in multiline mode
- \cy - yank line and comment it
- \c$ - comment from the cursor to end of line
- \cA - put comment delimiters and set cursor between them
Search in: files, buffers. Some shortcuts:
- Ctrl + f - move the base of searching into the left side (switch between modes)
- Ctrl + b - move the base of searching into the right side
- Ctrl + r - search by regexp mode
- Ctrl + j - like
jin a file (move cursor in search list down) - Ctrl + k - like
k - Ctrl + t - open selected file in new tab
- Ctrl + x - open selected file in half horizontal window
- Ctrl + v - open selected file in half vertical mode
- http://walking-without-crutches.heroku.com/ - TextMate vs. Vim - useful presentation
- http://walking-without-crutches.heroku.com/image/images/vi-vim-cheat-sheet.png - cool cheat sheet
- http://vimcasts.org/ - video cast about Vim
- http://www.vim.org/docs.php - full Vim documentation
- http://www.cs.swarthmore.edu/help/vim/ - tips and tricks with Vim
- https://www.maketecheasier.com/vim-keyboard-shortcuts-cheatsheet/
- https://gist.github.com/awidegreen/3854277
- https://www.computerhope.com/unix/vim.htm
- https://github.com/gmarik/vundle - plugin manager for Vim
- https://github.com/ctrlpvim/ctrlp.vim - show window with last modified files
- https://github.com/scrooloose/nerdtree - NERDTree support editor for projects navigation
- https://github.com/ervandew/supertab - show suggest after
<tab>press - https://github.com/scrooloose/syntastic - check syntax after saving file
- https://github.com/bling/vim-airline - show fancy chars in the bottom bar, some arrows, etc.
- https://github.com/majutsushi/tagbar - show outline of methods in a file
- https://github.com/tpope/vim-surround - add a possibility to wrap string with smth
- https://github.com/Townk/vim-autoclose - if you put '(' this plugin automatically puts ')'
- https://github.com/airblade/vim-gitgutter - show plus/minus when you make changes
- https://github.com/matze/vim-move - can move up/down the current line
- https://github.com/mattn/emmet-vim - plugin for emmet - successor of zen-coding
- https://github.com/scrooloose/nerdcommenter - comments line
- https://github.com/tpope/vim-markdown - highlighter for *.md files
- https://github.com/tpope/vim-fugitive - shortcuts for Git commands
You can always use this:
:h quickref:h SHORTCUT(:h dd,:h :s):exusage- open help window and scroll toEX commands(very useful when you try to check the meaning of all Vim commands)
Happy coding! โค๏ธ