tips
45 tips Vim
One command, setting or habit at a time about Vim: what it does, the line to copy and a caveat or two.
Linux and shell 44
-
Pastes the word under the cursor into a command or search you are typing in Vim.
:%s/<Ctrl-r><Ctrl-w>/newname/g -
An empty pattern in a substitute command reuses your last search, so you can look first and replace after.
/oldname -
Reads text from a pipe into a new Vim buffer so you can search and edit it.
find . -name "*.conf" | vim - -
Starts Vim with default settings and no personal config, to find out whether your setup causes a problem.
vim --clean file.txt -
Rewraps a paragraph or a selection to a fixed line width, such as 72 characters.
:set textwidth=72 -
Opens a file with Vim's navigation and search, but blocks accidental saves.
view /etc/fstab -
Opens a file browser inside Vim to pick another file.
:Ex -
Picks a recently edited file from a numbered list.
:browse oldfiles -
Returns to previous cursor spots after a search or a jump.
Ctrl-o -
Starts Vim with the cursor on a line or search match.
vim +/listen /etc/nginx/nginx.conf -
Pastes your last copy even after a delete replaced it.
"0p -
Brings back your previous selection to work on it again.
gv -
Replaces lines in the buffer with the output of a command.
:%!sort -u -
Re-indents a file using Vim's indent rules for the language.
gg=G -
Jumps to the next place a word appears without typing it.
* -
Opens a path from your text without typing it.
gf -
Applies the same change to all buffers in one go.
:bufdo %s/oldhost/newhost/ge | update -
Compares two files and moves differences between them.
vimdiff nginx.conf nginx.conf.new -
Converts a file with Windows line endings back to Unix ones.
:set ff=unix -
Identifies odd characters by their decimal, hex and octal code.
ga -
Puts files next to each other in one Vim screen.
:vsplit config.example.yml -
Searches a whole project from inside Vim and jumps through results.
:vimgrep /TODO/ **/*.py -
Calculates something and inserts the answer while you type.
Ctrl-r =19*23<Enter> -
Changes the case of a word, a line or a selection.
gUiw -
Runs a shell or a command inside Vim, next to your file.
:terminal -
Bookmarks a spot in a file so you can return to it.
ma -
Adds a prefix to a column of lines in one edit.
Ctrl-v -
Changes the next search match, then repeats it where you choose.
/oldName -
Makes invisible whitespace visible while you edit.
:set list listchars=tab:>-,trail:~,eol:$ -
Records a series of keystrokes once and repeats it on other lines.
qa -
Collapses indented blocks so you can see a file's outline.
:set foldmethod=indent -
Opens your Vim command history as a buffer, so you can edit an old command and rerun it.
(move to the line with k, edit it) -
Saves Vim undo history in a file so you can still undo after reopening the document.
set undofile -
Jumps back to the place where you last left Insert mode and starts typing again there.
gi back to where you stopped typing, in Insert mode -
Counts how many times a pattern appears in the file, using the substitute command's n flag.
:%s/error//gn -
Adds to or subtracts from numbers in Vim, or numbers a list in one go.
Ctrl-A add 1 to the number at or after the cursor -
Jumps back to the places you edited in Vim, newest first.
`. go to the last change -
Repeats a set of normal-mode keystrokes on every line in a range.
:%norm A; -
Highlights misspelled words in Vim and lets you pick a correction from a list.
:setlocal spell spelllang=en_us -
Deletes all lines containing a pattern, or all lines not containing it, in one command.
:g/^#/d -
Runs a shell command and inserts what it prints below the current line.
:r !date -
Sorts the lines of a file or a selection, with options for numbers, case and duplicates.
:sort -
Writes all modified buffers to disk in one command, and optionally exits Vim.
:wa -
Jumps the text back or forward in time instead of stepping through undo one change at a time.
:earlier 10m
Sessions and shortcuts 1
-
Saves the open files and window layout to a file so you can restore it later.
:mksession
Nothing in this filter yet.