Scrolling keys:
- j: cursor down
- k: cursor up
- l: cursor right
- h: cursor left
- 0 (zero): beginning of line
- $: end of line
- w: word forward
- b: word backward
- H moves the cursor to the top of the screen or viewport.
- M moves the cursor to the middle of the screen or viewport.
- L moves the cursor to the bottom of the screen or viewport.
- ctrl-e: screen and cursor up 1 line
- ctrl-y: screen and cursor down 1 line
- z z: move screen and cursor to mid screen
- z t: move screen and cursor to top line
- z b: move screen and cursor to bottom line
- ctrl-u: screen and cursor up 1/2 page
- ctrl-d: screen and cursor down 1/2 page
- ctrl-b: screen and cursor up one page
- ctrl-f: screen and cursor down one page
Go:
- G: last line of file
- nG: nth line of file, with 1 for first line of file
- g-: backwards in edits
- g+: forwards in edits
- :earlier 50s: to back 50 seconds
- :earlier nf: back n file writes
- %: jump to matching bracket
- :help undo-persistence
Select:
- shift v: select lines
- ctrl v: select columns
Search:
- /: forward search
- ?: backwards search
- n: next occurrence
- N: next occurrence, opposite direction
Change:
- cw: change to next word
- cc: change entire line
- c$: change to end of line
- ci”: change inside parentheses
- ca”: change around parentheses
- cfx: change until next found occurrence of x
- :%s/search/replace/gc
- mx tells Vim to add a mark called x.
- `x tells Vim to return to the line and column for mark x.
- 'x tells Vim to return to the beginning of the line where mark x is set.
- `. moves the cursor to the line and column where the last edit was made.
- '. moves the cursor to the line where the last edit was made.
- '" moves the cursor to the last position of the cursor when you exited the previous session.
- :marks shows all marks set.
- :marks x shows the mark named x.
Jumps:
- :jumps shows the jumplist.
- Ctrl-o moves the cursor to the last jump.
- Ctrl-i moves the cursor to the previous jump.
- ctrl-w s: split horizontally (or :split, :sp)
- ctrl-w v: split vertically (or :vertical split, :vs)
- ctrl-w w: switch between windows
- ctrl-w h, j, k, l: to navigate windows
- ctrl-w _: maximize current window
- ctrl-w =: equal size all windows
- 10 ctrl-w +: increase window size by 10 lines
- ctrl-w c: close window
- ctrl-w o: close all windows but current
- :sp <filepath>: split window horizontally with another file
- :vs split window vertically
Tabs:
- :tabe <filepath>: open file
- :tabn - next window
- :tabp - previous window
- ctrl-w with arrow: move windows
- gt: jump next tab
- gT: jump previous tab
- <n>gt: jump to specific tab
- :e .: start browsing in tab
- w: next
- W: previous
- <n>gt: index of tab to jump
Column Insertion (full vim needs to be installed, won't work with vim.tiny):
- from stack overflow:
- move to the position
- column visual mode: ctl-v
- select column and row range
- column insert mode: shift-i
- perform insertion
- finish: esc
Scrolling and line numbers in .vimrc file:
" http://vim.wikia.com/wiki/Keep_your_cursor_centered_vertically_on_the_screen set scrolloff=5 " http://jeffkreeftmeijer.com/2013/vims-new-hybrid-line-number-mode/ set relativenumber set number " http://unix.stackexchange.com/questions/5310/how-can-i-disable-bells-visualbells-in-vim set visualbell set t_vb=
Kind of related, but using 'screen' to split windows (from StackExchange:
- split vertically: ctrl-a, |
- split horizontally: ctrl-a, S
- unsplit: ctrl-a, Q
- switch windows: ctrl-a, tab
- go to new region: ctrl-a, c
- new terminal (new bash prompt): ctrl-a, c
- next terminal: ctrl-a, space
- nth terminal: ctrl-a, -n-
- switch terminals: ctrl-a, "
- misc
- :set paste - don't insert tabs or spaces during insert
- :set nopaste - opposite of above Auto Indent for code paste
- alternate paste:
- :set noai - turn off auto indent
- :set ai - turn on auto indent
- :setl noai nocin nosi inde= - no auto-indent on current file
Lots of tips, tricks, and techniques at vim wikia.
- Other Vim sites:
- neovim: promoted as: "literally the future of vim"
- Learning Vim: What I Wish I Knew
- Learn Vim Progressively
- Awesome Vim Plugins
- Curated Vim links at ZEEF Links by Patrick Schanen
- Example vimrc
- How Vim killed Atom and VSCode on my Machine: compares the three and suggests neovim is the future
- Vim Is The Perfect IDE: has a very large vimrc file as an example, quite sophisticated
- Vim & Python: Making yourself at home: an intro to the .vim file structure for configurations
- Why is Vim a good Python development environment?: a bunch of introductory as well as advanced links on how to make vim more productive, with a key to Python productivity
- Vim Cheat Sheet, added 2017/11/14, stark, simple, and to the point
- How I Use Vim, added 2017/11/17, Chris Boddy
- Matching terminal and vim colors automatically!, added 2017/12/01
- Find and Replace in Vim Without Plugins, added 2017/12/14
- hacker news - 10 years of vim, added 2018/05/21
- Vim Cheat Sheet for Programmers - color coded and concise
- tpope/vim-sensible - sensible.vim: Defaults everyone can agree on - added 2019/12/23
- VIM Useful Commands - from cmake.org - added 2019/12/23
- .vimrc - added 2020/01/17 - many many plugins listed
- Vim Guide for Intermediate Users - added 2020/12/28 -
- Learn Vim the Smart Way - added 2021/05/19