:e
filename` opens an existing or new file
- In cli
vim -p file1 file2... filen
opens multiple files in tab :tabe
opens a file in a new tabgt
goes forward one tabgT
goes back one tab:tabm position
moves current tab to a given position in the tab order:help tabp
brings up tab help page
:split filename
opens file in a new split window (horizontally):vsplit filename
opens file in a new split window (vertically)ctrl + w + l
andctrl + w +h
move between windows:on
closes all windows except the current window:windo command
will run a command in all open windows
:t.
will duplicate a linectrl + p
will autocomplete a wordo
adds a new line below cursor and starts insert thereO
adds a new line above cursor and starts insert theregi
goes back to last place you were in insert modegq
will reformat textgqip
will reformat a paragraphgv
to select last selected areag;
moves to previous changeg,
moves to next changectrl + o n
executes normal mode command n from insert mode (good for macros)ctrl + v
enters Visual Block Mode.=
auto indents visually selected linesJ
will combine the next line with the current line
- Creating a macro:
- Type
q
plus a letter (which register to record to) - Type the keystrokes to record
- Type
q
to stop recording - Type
@
plus the letter for the register - Type
@@
to re-run the macro
- Type
:5,10norm! @a
will run macro a on lines 5 through 10:%norm! @a
will run macro a on all lines:g/pattern/normal! @a
will run macro a on all lines matching pattern5@a
will run macro a five times
:ls
to show all buffers
- Refer to a register with
"
plus its letter or number "ayy
will copy a line to registera
"ap
will paste from registera
"Ayy
will copy a line and append it to registera
:reg
shows the content of all registers:reg num_or_letter
shows contents of a specific register- The blackhole register is named with an underscore (can truly delete text when writing it here)
>>
Indents line<<
Unindents linenum>>
indents num lines
x
deletes the current characterdd
deletes the current linedtCHAR
deletes everything up to the nearest occurrence of CHAR
:%s/search_value/replace_value/g
will replace all occurrences of search_value with replace_valueq/
brings up a command window with recent searches
$
goes to end of line0
(zero) goes to beginning of linew
moves forward a wordmoves
backward a wordL
goes to the bottom of the screenH
goes to the top of the screen}
goes forward one paragraphline_numberG
goes to a specific line numberctrl + b
moves up one pagectrl + f
moves down one pagectrl + e
scrolls down one linectrl + y
scrolls up one linectrl + z
to switch back to shell (thenfg
to bring VIM back)ctrl + i
goes to next jump locationctrl + o
goes to previous jump locationctrl + ]
jumps to definition via ctagszz
to center current line in middle of screen
v
starts selecting charactersV
starts selecting whole linesd
cuts selectiony
copies selectionp
pastes after cursorP
pastes before cursorVNUMJ
selects NUM lines downward
m
plus lowercase letter sets mark to that letter for current file.'
plus letter goes to that mark:marks
shows existing marks
zg
adds word to dictionary when it's marked as misspelled.z=
brings up correction suggestions when on misspelled word.]s
goes to next misspelled word.[s
goes to previous misspelled word.
:so $MYVIMRC
reloads your ~/.vimrc:call ReloadAllSnippets()
reloads all SnipMate snippets:qa
quit all open files:set filetype?
shows the filetype of the currently open file:! shell_command
to execute a shell command from within VIM:SyntasticInfo
to see linter used for current file.q:
brings up a command window with recent commands:cq
force-quits Vim w/ a non-zero status (good for aborting process that started Vim).:argdo command
executes command on every open buffer.:retab
replaces tabs in a file w/ your configured indentation.
- gS to split a one-liner into multiple lines
- gJ (with the cursor on the first line of a block) to join a block into a single-line statement.