🗓️ 15022025 2138

VIM
NOTE

JR's very own intro to vim over here! 🤓

Command cheatsheet​

Commands in VIM generally follow this pattern

:[range][command][arguments]
PartDescriptionExample
:Starts an ex command:w, :s/...
[range]Optional line range:%, 5,10, .,$
[command]The action to performs, d, y, w, g, m
[arguments]Optional arguments, like patterns, flags, file names/pattern/, /repl/gi, file.txt

Yank & Registers Cheatsheet​

CommandDescription
"*y or "+yYank into system clipboard ("* = primary, "+ = clipboard)
"aYYank into register a (can be any letter a–z)
"0pPaste from the default yank register
"*pPaste from system clipboard
:regShow all registers and contents
yy / dd / pYank, delete, and paste using default register
"apPaste from register a

Macros​

  1. Begin recording with q command
  2. Choose register (a-z)
  3. Perform actions
  4. End recording with q command

using registers​

CommandDescription
:5,10norm! @aDo from lines 5-10
:5,$norm! @aFrom line 5 to end of file

Replace Cheatsheet​

CommandDescription
:s/pat/repl/Replace first match in current line
:s/pat/repl/gReplace all matches in current line
:.,$s/pat/repl/gReplace from current line to end
:%s/pat/repl/gReplace in entire file
:5,10s/pat/repl/gReplace from line 5 to 10
:%s/pat/repl/gcReplace in file, confirm each (c = confirm)
:%s/escaped\.pat/repl/gUse \ to escape special chars like . or *
:%s/pat/replace & more/gUse & to refer to the matched original pattern
:%s/pat/repl/giCase-insensitive replacement
:%s/pat/repl/gICase-sensitive, even if ignorecase is on
:%s/pat\nnext/repl/gReplace across multiple lines using \n
:5,10s/hello/world/gcReplace "hello" with "world" in lines 5–10, with confirm

Mapping types​

TypeDescription
Recursive (map)If the result of this mapping exists as another mapping, Vim will execute that as well
Non Recursive (noremap)Vim will execute the result of this mapping as-is, without considering further mappings