- Vim Consolidated Notes
- VimTutor
- Primeagen Guide to VIM
- Vim MIT Lecture Notes
- Surround.vim Plugin
- Practical Vim Book Notes
- Chapter 00 - Movement Commands
- Chapter 01 - The Vim Way (11 pages)
- Chapter 02 - Normal Mode (12 pages)
- Chapter 03 Insert Mode (9 pages)
- Tip 13 - Make Corrections Instantly from Insert Mode
- Tip 14 - Get Back to Normal Mode
- Tip 15 - Paste from a Register Without Leaving Insert Mode
- Tip 16 - Do Back-of-the-Envelope Calculations in Place
- Tip 17 - Insert Unusual Characters by Character Code
- Tip 18 - Insert Unusual Character by Diagraph
- Tip 19 - Overwrite Existing Text with Replace Mode
- Chapter 04 - Visual Mode (14 pages)
- Chapter 05 - Command-Line Mode (28 pages)
- Tip 27 - Meet Vim's Command Line
- Tip 28 - Execute a Command on One or More Consecutive Lines
- Tip 29 - Duplicate or Move Lines Using
:tand:mCommands - Tip 30 - Run Normal Mode Commands Across a Range
- Tip 31 - Repeat the Last Ex Command
- Tip 32 - Tab-Complete Your Ex Commands
- Tip 33 - Insert the Current Word at the Command Prompt
- Tip 34 - Recall Commands from History
- Tip 35 - Run Commands in the Shell
- Tip 36 - Run Multiple Ex Commands as a Batch
- Chapter 08 - Navigate Inside Files with Motions (22 pages)
- Tip 47 - Keep Your Fingers on the Home Row
- Tip 48 - distinguish Between Real Lines and Display Lines
- Tip 49 - Move Word-Wise
- Tip 50 - Find by Character
- Tip 51 - Search to Navigate
- Tip 52 - Trace your Selection with Precision Text Objects
- Tip 53 - Delete Around, or Change Inside
- Tip 54 - Mark Your Place and Snap Back to It
- Tip 55 - Jump Between Matching Parentheses
- Chapter 09 - Navigate Between Files with Jumps (8 pages)
- Chapter 10 - Copy and Paste (18 pages)
- Chapter 11 - Macros (21 pages)
- Tip 65 - Record and Execute a Macro
- Tip 66 - Normalize, Strike, Abort
- Tip 67 - Play Back with a Count
- Tip 68 - Repeat a Change on Contiguous Lines
- Tip 69 - Append Commands to a Macro
- Tip 70 - Act Upon a Collection of Files
- Tip 71 - Evaluate an Iterator to Number Items in a List
- Tip 72 - Edit the Contents of a Macro
- Internet Article Notes
The basic movement in vim is accomplished with the right-hand, home row keys:
h (left) j (down) k (up) l (right)
:q! - Discards changes and exits vim
x - Deletes the character under the cursor (or to the right)
i - Inserts text before the highlighted character (or to the left)
A - appends text to the end of the line (very handy)
:wq - Saves changes and quits vim
dw - [delete] to start of next [word], excluding first character - places cursor just to left of next word (no space)
de - [delete] to end of current word, including last character - places cursor to left of next word with a space
d$ - [delete] to end of [line]
The first letter is an operator followed by a motion
Motions can be modified via counts (e.g. 3w, 2e)
Operators, Counts, and Motions can be combined (e.g d3w)
dd - deletes an entire line
u - undo previous action
U - undo all actions on current line
CTRL-R - undo the last undo
p - put previously deleted text after cursor (below current line)
r - replaces the currently highlighted character (to the right)
c - change operator
ce - change to end of word
cc - change entire line
c$ - change to end of line - equivalent to C
CTRL-G - File name, status and cursor location
G - Go to end of file
gg - Go to beginning of file
#G - Go to # line number
/pattern - search for pattern and place cursor
n - search next forward
N - search next backward
?pattern - search for pattern in reverse and place cursor there
CTRL-O - hop to previous location
CTRL-I - hop to newer position
CTRL-W - switches windows
% - hops to matching bracket
:s/old/new/[g] - substitute command (for a single line)
:#,#s/old/new - change occurrence in between line number
:%s/old/new/[g] - change occurrence in entire file
:![COMMAND] - allows for external command execution
v - Visual inspection mode
:w FILENAME - write current file to FILENAME
:r - Retrieve command
o - Open a line BELOW the current line and changes to INSERT mode
O - Open a line ABOVE the current line and changes to INSERT mode
a - INSERT text after the cursor
A - INSERT text at the end of line
i - INSERT text before the cursor
R - REPLACE mode
y - YANK operator
yy - yank whole line
yw - yank word
:set OPTION - sets an OPTION
SOME OPTIONS:
ic - ignore case
is - incremental search (show partial matches)
hls - highlight search matches
noOPTION - turns off option
:help - Enter online vim help documentation
CTRL-D - Command line completion
CTRL-W - Jump to another window
- YouTube
- keys:
w b h j k l y p d v V :w <esc>- basic movement:
h j k l - Word-hop forward/back:
w b - Copy/Paste:
y p - Delete:
d - Visual/Visual-line mode:
v V - Save:
w - Enter Normal mode:
<esc>
- basic movement:
- YouTube
- keys:
o O p P a I A / ? n N * #- Insert line below/above:
o O - Paste line below/above:
p P - Insert mode at first/last non-empty character on line:
I A - Forward/Backward Search and Next/Previous match:
/ ? n N - Search forward/backward on current word:
* #
- Insert line below/above:
- YouTube
- keys:
f t F T ; , x s c D C S- Jump to/before character on current line forward/back and next/previous match:
f t F T ; , - Delete single character and also go into insert mode:
x s - Delete word and go into insert mode:
dw cw - Delete reset of line and also insert mode:
D C - Delete entire line and go into insert mode:
S
- Jump to/before character on current line forward/back and next/previous match:
Esc - Enter NORMAL mode
i - Enter INSERT mode BEFORE cursor
a - Enter INSERT mode AFTER cursor
A - Enter INSERT mode AFTER end of line
R - Enter REPLACE mode until hit ESC
r - Enter REPLACE mode for a single next character
v - Enter VISUAL mode
V - Enter VISUAL line mode
CTRL-V - Enter VISUAL block mode
: - Enter COMMAND-LINE mode
^ - Move to first non-blank character in a line
H - Move to TOP of screen
M - Move to MIDDLE of screen
L - Move to BOTTOM of screen
CTRL-u - SCROLL Up
CTRL-d - SCROLL Down
#G - Jump to line number
~ - Flips the character under cursor
ci( - change content INSIDE current parentheses
da' - deletes single quote content INCLUSIVE (AROUND)
:sp - split panel (HORIZONTAL)
vsp - split panel (VERTICAL)
Also completed [EXERCISES]
- Plugins to read about:
surround.vimrepeat.vimmatchit.vim
cs[old][new]- change surround
ds[old]- delete surround
ysiw[new]- yank surround + text objectyss[new]- yank surround entire line
t/T/f/F - toward a character and forward to character
; and , - next/previous instance of above
* and # - find next/previous instance of current word
< > = - indentation related commands
vim -u NONE -N - start vim in default mode
The dot command lets us repeat the last change. It is the most powerful and versatile command in Vim.
- The
dotcommand is a micro macro. haha!
- Use combined shortcuts like
Ato be more efficient.
f{char}which searches for the given character can be combined with;and.to be super powerful.
- Handy commands and their reverse:
.: Repeat the last change.ureverses the last change.;: Forward line search next char.,reverse line search previous char. Equivalent toF{char}.n: Forward search next char.Nreverse search previous char.:s/target/replacement: Perform forward substitution. Repeat using&and undo usingu.qx{changes}q: Perform a macro.ureverses the macro.
*Searches for the next occurrence of the word under the cursor.nLet's you repeat the previous search. Handy for quick search/edits, repeat.*,cw,edit,*,.Boom!
- The goal: One Keystroke to Move, One Keystroke to Execute
Normalmode is Vim's natural resting mode- Just as a painter spends a fraction of their time applying paint, programmers spend a fraction of their time composing code.
- Make
Normalyour default (make it a habit)
- Entering Insert mode and leaving to Normal typically corresponds to an
undoable chunk
dawdelete a word (works great with the.operator)- Develop a habit of making your changes repeatable wherever possible, then Vim will reward you for it
<C-a>adds a number to the current line<C-x>subtracts a number to the current line
- No real useful advice here other than don't over count when a repeat might suffice
dapdeletes a paragraph- An
actionis composed from anoperatorfollowed by amotion
<C-u>- deletes back to start of line (also works in the terminal)<C-w>- deletes back to start of word (also works in the terminal)
zz- redraws screen with the current line in the middle
<C-r>- pastes from register
<C-r>=- pastes from expression register (didn't work in neovim inside vscode)
<C-v>- inserts a character by character code (didn't work in neovim inside vscode)
<C-k>{char1}{char2}- inserts a character by diagraph (didn't work in neovim inside vscode)
R and gR- Replace mode and Virtual Replace moder and gr- Single-shot replace mode and virtual replace mode
c- In visual mode, deletes the selected text and changes into Insert mode- Useful for wrapping changed selected text with quotes or brackets!!!
v- character-wise Visual modeV- line-wise Visual mode<C-v>- block-wise Visual modegv- reselect the last visual selectionogo to end of highlighted text (ping-pong cursor)ois handy for redefining the begin/end points of the selection
.- repeats the edit on the previously selected text when using visual-line modevit- visual select in-between tags
gU- uppercase the following motion- As a general rule, we should prefer operator commands over this Visual mode equivalents when working through a repetitive set of changes
- Fancy visual block-mode kung-fu
- Not that block mode works like you think it should but you won't see the multiple cursor effect until you re-enter normal mode
- Visual block-mode is actually quite useful. Similar to vscode native multi-cursor functionality
- Note
iandawhile in visual or operator-pending mode represent theinsideandaroundpart of atext object
In the beginning, there was ed. ed begat ex, and ex begat vi, and vi begat Vim.
- The Old Testament of UnixIn the beginning, there was ed, ed begat ex, and ex begat vi, and vi begat Vim
- The Old Testament of Unix
- Ex commands strike far and wide
:d- delete range and place in register:y- yank range and place in register:put- [line] put [x] register at specified line:normal- apply normal commands to given range[range]- range #,#%- symbol for entire file
:t- copy range to address:m- move range to address:[range] copy/move {address}
:normal A;- Add semicolon at the end of all lines:normal i//- Comment out all lines (JS)
@:- repeat last Ex command; use@@- after one repeat for multiple repeats<C-o>- goes one step back in the jump list (may not work because of my fancy ctrl scheme)
- Remember to make use of tab completions in Ex mod
<C-d>- invokes completion menu
<C-r><C-w>- inserts current word in command line prompt (Doesn't work in vscode) :
q:- opens command line menu (doesn't work in vscode)
:!- runs command in shell (doesn't work in vscode)- In vscode, output of external command is sent to neovim output console
%- in command line mode, % represents the current file name:shell- opens (interactive) shell in command line mode (return to vim by typingexit):write {cmd}- buffer is provided as input to cmd:read {cmd}- output of cmd is placed in buffer
:source- to execute a vim script; don't need leading::argdo source [filename]- to run script on multiple files
- Just a reminder to use
h (left), j (down), k (up), l (right)for movement in place of the arrow keys
gj and gk- move down/up display line wise^- move to first non-blank character of a display line- Basically prefix the real line movement keys with
gto get the analogues display line movement
w- move forward to start of next wordb- move backward to start of current/previous worde- move forward to end of current/next wordge- move backward to end of previous wordW, B, E, gE- WORD movements
f{char}- move by character in current line, alsoF, t, T
/{pattern}- search forward for pattern,?{pattern}- search backward for pattern- Consider setting
hlsearchandincsearchsettings; relates keysnandNo hop - Using the
d{motion}in combination with/{pattern}search is a powerful combination
t- Text Object to reference HTML tagsi- Inside text objecta- All text objectb- parentheses delimiterB- curly brackets delimiter- Set of possible delimiters include:
), }, ], >, ', ", backtick, t, b, B
i/a w/W/s/p- Text objects are powerful when combined withword,WORD,sentence,paragraph- Simple tip to use
awhendeleting andiwhenchanging
m{a-zA-Z}- mark a place in the file (capital are global)- ``{mark}` - go to the marked place
double-backticks- go to last jump in file- ``.` - go to last change location
%- jumps between matching set of bracketsS"- surround the selection with double quotes (surround.vim)
<C-o>- goes backwards through the jump list<C-i>- goes forwards through the jump listmotions- move around within a filejumps- move around between files:jumps- list the jump list(, )- jump to previous/next sentence{, }- jump to previous/next paragraph
g; and g,- go to previous/next changebacktick.- go to last changegi- go to last insertion and enter insert mode
gf- navigates to filename under cursor (go to file)bundler.vim- might be a useful plugin to incorporate to enhance gf power<C-]>- jump to method definition from invocation (may need some initial config to work)
m[Capital]- sets a global markbacktick[Capital]- navigates to a global mark- Handy trick, set
mV, to init.vim for easy jumping to the vimrc file - Handy trick, set
mS, to .zshrc for easy jumping to the zshrc file - Before going on a jump journey, set the global mark
mMand return withbacktickMto get back to the mark
xp- transpose the next to characters using the unnamed register -- useful!!!ddp- transpose the next two linesyyp- line-wise copy and paste
"{register}[delete | yank | put]- copy to a namedregister_- theblack holeregister (e.g._d{motion}nothing escapes a black hole)""- theunnamed registerx,s,d{motion},c{motion},y{motion}- all write to register:reg- inspect registers- lowercase registers
overrideany existing text; uppercase registersappendto existing content "+- named register that reference the system clipboard- Not sure how, but I also have normal
CMD+CandCMD+Vfunctional
v{motion}p- replace visual selection with unnamed register content- Think of it this way: the visual selection in the document swaps places with the text in the register. Is it a feature? Is it a bug? You decide.
p/P- inserts register textafterandbeforecursor position<ctrl-r>{register}- inserts register text while in INSERT or COMMAND modegp/gP- alter the position of the cursor after the put operation. This is useful for pasting a block of text into a document.
- Not relevant since I don't use nvim in terminal often
:reg{register}- inspects the content of the given register; useful to examine macros@{register}- executes the contents of the specified register@@- executes the contents of the last executed macro- macros can be executed
serialor inparallel
- The golden rule is this: when recording a macro, ensure that every command is repeatable.
w, b, e, ge- are more reliable movements when recording a macro
n@{register}- repeats a macron times or until failure
:'<,'>normal @{register}- repeat macro on each of highlighted lines
- use
q{A-Z}- to append to an existing macro
- not useful since I don't use vim to manipulate across multiple files
- super niche. not going to bother with this tip until other tips are muscle memory
- makes use of
expression register, "=
- skipping this as well, since I should first master basic macro syntax
blah blah