0% found this document useful (0 votes)
366 views11 pages

Cheatsheet: Getting Started

mn

Uploaded by

John Le Tourneux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
366 views11 pages

Cheatsheet: Getting Started

mn

Uploaded by

John Le Tourneux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Vim - Quick Reference Cheat Sheet https://quickref.

me/vim

 QuickRef.ME  Edit page  Facebook  Twitter

Vim cheatsheet
A useful collection of Vim 8.2 quick reference cheat sheets to help you learn vim editor faster.

# Getting started
Motion Diagrams Motions Insert Mode

▼/▶ Cursor ▽/▷ Target Arrow Insert


h | j | k | l
keys i / a before/after
cursor
Left-right motions
Half-
<C-u> / <C-d> page Insert
┌───────────── |
up/down I / A start/end of
├───────────── 0 $ ──────────────┐
line
│ ┌────────── ^ fe ────────┐ │ Page
<C-b> / <C-f>
│ │ ┌─────── Fo te ───────┐│ │ up/down Insert new
│ │ │┌────── To 30| ───┐ ││ │ o / O (letter) line
│ │ ││ ┌──── ge w ───┐ │ ││ │ Words below/above
│ │ ││ │ ┌── b e ─┐ │ │ ││ │ Previous/Next
b / w Delete
│ │ ││ │ │ ┌h l┐ │ │ │ ││ │ word
▽ ▽ ▽▽ ▽ ▽ ▽▼ ▼▽ ▽ s / S char/line
echo "A cheatsheet from quickref.me" Previous/Next and insert
ge / e
end of word
Change to
Up-down motions C
Line end of line

- SCREEN 1 START Start/End of Insert at last


0 (zero) / $ gi
┌─┬─────────▷ #!/usr/bin/python line insert point
│ │ ┌───▷
│ │ │ print("Hello" ^ Start of line Exit insert
(non-blank) Esc | <C-[>
│ │ { } ▶ print("Vim" mode
│ │ │ print("!" Character
│ │ └─▷
│ │ ┌───┬───▷ print("Welcome" Move to
G gg H M L k j ▶ print("to" Fe / fe previous/next
│ │ └─▷ print("quickref.me" e
│ │ print("/vim"
Move
│ │
before/after
│ └─────▷ To / to
previous/next
│ - SCREEN 1 END
o
└──────────────▷ print("SCREEN 2"
Go to first/nth
| / n|
column

1 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Saving and Exiting

:w Save

:q Close file

Save
:wq | :x | ZZ
and quit

Save
:wqa and quit
all files

Force
:q! | ZQ
quit

Close all
:qa
files

Force
:qa! quit all
files

Write to
:w new.txt
new.txt

Save
:sav new.txt and edit
new.txt

Write to
:w !sudo tee % readonly
file

2 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Normal Mode Cut and paste Repeating

Replace Delete Repeat last


.
r x character command
character (Cut)
Repeat latest f, t, F
;
Enter Paste or T
p / P
R Replace after/before
mode Repeat latest f, t, F
Swap two ,
xp or T reversed
Undo characters
changes & Repeat last :s
u / 3u Delete to
1
times D end of line Repeat a command-
@:
(Cut) line command
Undo
changes Delete
U dw
# Operators on one word (Cut)

Delete line
dd
Join
Usage with (Cut)
Available Operators Examples
J
next line
d w d Delete
Swap two Combination Description
ddp
Redo lines
Operator Motion y Yank (copy) Delete
changes dd
<C-r> / 5 <C-r> Yank line current line
1 yy Change
c (Copy)
times Delete two
dj
Paste from lines
p"*p | "+p Paste
system
Delete to next
Visual mode clipboard dw Macros
= Formats code word
Enter visual Paste to qi Record macro i
v
Combine operators with mode g~ Toggle case Delete to
"*y | "+y system
motions to use them db beginning
Stop of
recording
clipboard q
Enter visual line gU Uppercase word
macro
V
mode In visual mode
gu Lowercase @i Delete until a
Run macro i
Delete selection dfa
Enter visual d | x char
<C-v>
block mode > Indent(Cut)
right Run macro i 7
7@i
Deletetimes
until
Replace d/hello
ggVG Select all text <s Indent left hello
selection @@ Repeat last macro
Shift text Filter through external Change
> / < ! Yank selection cc
right/left y program current line
(Copy)
Copy current
yy
line

>j Indent 2 lines

Delete a
ggdG complete
document

Indent a

3 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Counts

[count] <operator> <motion>


<operator> [count] <motion>

2dd Delete 2 lines

6yy Copy 6 lines

#d3w
Text objects
Delete 3 words

Delete 5 lines
d5j Usage Text objects Delete
downwards
    i/ p Paragraph diw Delete inner word
v p
a Indent 4 lines
>4k w Word
upwards dis Delete inner sentence
inner / Text
Operator WORD
around object di" Delete in quotes
W
Delete in quotes
da"
(including quotes)
Operate with an operator inner s Sentence
or around text blocks dip Delete a paragraph
[({< A [], (), or {} block

Selections ])}> A [], (), or {} block Misc

Select inner quotes '"` A quoted string ciw Change inner word
vi"
"..."
b A block [( ci" Change inner quotes
va" Select quotes "..."
B A block in [{ Change inner tags
cit
Select inner brackets (HTML)
vi[
[...] t A HTML tag block
Change inner
cip
Select brackets paragraph
va[
[...]
yip Yank inner paragraph
viw Select inner word
Yank paragraph
yap
Select inner (including newline)
vip
paragraph

Select more
vipip See :help text-objects
paragraph

# Multiple files

4 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Buffers Windows Tabs

Edit a file in a <C-w> s Split window Edit file in


:e file :tabe [file]
new buffer a new tab
Split window
<C-w> v
Go to the next Open if
:bn
buffer :tabf [file] exists in
<C-w> w Switch windows new tab
Go to the
:bp
previous buffer <C-w> q Quit a window Close
:tabc current
Remove file Break out into a tab
:bd <C-w> T
from buffer list
Close
:tabo
:b 5 Open buffer #5 Swap current with other tabs
<C-w> x

Go to a buffer List all


:b file :tabs
by file Decrease/Increase tabs
<C-w> - / +

List all open Go to first


:ls :tabr
buffers Decrease/Increase tab
<C-w> < / >

Open and split Go to last


:sp file :tabl
window <C-w> | Max out the width tab

Open and Equally high and Move to


<C-w> = :tabm 0
:vs file vertically split position 0
window
Go to the left/right Go to next
<C-w> h / l :tabn
:hid Hide this buffer tab

Write file and Go to the up/down Go to


:wn <C-w> j / k
move to next :tabp previous
tab
Edit all buffers
:tab ba
as tabs Normal mode

gt Go to next tab

gT Go to previous tab

2gt Go to tab number 2


# Search and Replace

5 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Search Replace LINE Replace FILE

Search :[range]s/{pattern}/{str}/[flags]
:%s/{pattern}/{str}/[flags]
/foo
forward

Search Replace Replace


:s/old/new :%s/old/new
/foo\c forward first first

Replace Replace
:s/old/new/g :%s/old/new/g
Search all all
?foo
backward
Replace Replace
Search with :s/\vold/new/g all with :%s/old/new/gc all
/\v\d+ regex (Confirm)
regex

Next matching replace Replace


n :s/old/new/gc all all
search pattern :%s/old/new/gi
(Confirm)
Previous
N Ignore
match
case Replace
:s/old/new/i
Search for replace :%s/\vold/new/g all with
* current word first regex
forward
Replace
Search for :2,6s/old/new/g between
# current word lines 2-6
backward

Ranges Global command Inverse :g

% Entire file :[range]g/{pattern}/[command :[range]v/{pattern}/[command

’<,’> Current selection


Delete lines Delete lines not
5 Line 5 :g/foo/d containing containing foo
:v/foo/d
foo
5,10 Lines 5 to 10
Delete lines
$ Last line :g/foo/d containing
foo
2,$ Lines 2 to Last
Delete lines
. Current line not
:g!/foo/d
containing
,3 Next 3 lines foo

-3, Forward 3 lines Delete all


:g/^\s*$/d
blank lines

Copy lines
:g/foo/t$ containing
foo to EOF

Move lines

6 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Flags

g Replace all occurrences

i Ignore case

I Don't ignore case

Confirm each
c
substitution

Substitute expression (magic) Examples

Replace with the :s/a\|b/xxx\0xxx/g # Modifies "a b"


& | \0
whole matched
to "xxxaxxx xxxbxxx"
:s/test/\U& file/ # Modifies "test"
Replace with the
\1...\9 to "TEST FILE"
group 0-9
:s/\(test\)/\U\1\e file/ # Modifies "test"
Uppercase next to "TEST file"
\u
letter :s/\v([abc])([efg])/\2\1/g # Modifies "af fa
bg" to "fa fa gb"
Uppercase :s/\v\w+/\u\0/g # Modifies "bla bla"
\U following to "Bla Bla"
characters
:s/\v([ab])|([cd])/\1x/g # Modifies "a b c d"
to "ax bx x x"
Lowercase next
\l :%s/.*/\L&/ # Modifies "HTML"
letter
to "html"
Lowercase :s/\v<(.)(\w*)/\u\1\L\2/g # Make every first
# Vimdiff
\L following
characters
letter of a word uppercase
:%s/^\(.*\)\n\1/\1/ # Remove duplicate
lines
Usage
End of \u, \U Editing Folds
\e :%s/<\/\=\(\w\+\)\>/\U&/g # Convert HTML-Tags
to uppercase
:[range]diffget [bufspec] zo / zO Open
:g/^pattern/s/$/mytext
$ vimdiff file1 file2 [file3] :[range]diffput [bufspec] # Find and append
zc / zC Close
$ vim -d file1 file2 [file3] text to the end
:g/pattern/normal @q # Run a macro on
Obtain za / zA Toggle
matching lines
do / :diffget (get)
/^\(.*\)\(\r\?\n\1\)\+$ # View the Open folds
difference
duplicates lines zv
for this line
:v/./,/./-j # Compress blank
dp / :diffput
difference
lines into a blank line zM Close all
:g/<p1>/,/<p2>/d # Delete inclusively
from Re-scan zR Open all
:dif<p1> to <p2>
differences
Fold more
Switch off zm
:diffo

7 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Jumping

]c Next difference

[c Previous difference

# Miscellaneous
Case Jumping Misc command-lines

Uppercase Go back to Help open


vU <C-o> :h
character previous help view

Lowercase <C-i> Go forward Reload


vu
character :edit! current
Go to file in file
gf
Toggle case cursor
~
character Move
Display hex, :2,8m0 lines 2-8
ga
Uppercase ascii value to 0
viw U
word
Clear
Lowercase :noh search
viw u
word highlights

Toggle case :sort Sort lines


viw ~
word
Open a
Uppercase
VU / gUU :ter terminal
line
window

Lowercase
Vu / guu Enable
line
Insert
:set paste
Paste
Toggle case
V~ / g~~ sub-mode
line
disable
Uppercase
gggUG Insert
all text :set nopaste
Paste
Lowercase sub-mode
ggguG
all text
Exiting
Toggle case with an
ggg~G :cq error
all text

8 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Navigating

Nearest/matching
%

Previous
[( | [{ | [<

]) | ]{ | ]> Next

Previous method
[m

Previous method
[M

Counters Tags

Increase :tag Classname Jump to first definition of Classname


<C-a>
number
<C-]> Jump to definition
Decrease
<C-x>
number g] See all definitions

<C-t> Go back to last tag


Formatting
<C-o> <C-i> Back/forward
Center lines
:ce 8
between 8 columns
:tselect Classname Find definitions of Classname

Right-align lines at
:ri 4 Find definitions of Classname (auto-
4 columns :tjump Classname
select 1st)

:le Left-align lines

See :help formatting

Marks Calculator

`^ Last position of cursor in insert mode Shows


<C-r> = 7*7 the
`. Last change in current buffer result

`" Last exited current buffer Shows


<C-r> = 10/2 the
`0 In last file edited result

'' Back to line in current buffer where jumped from Do this in INSERT mode

Back to position in current buffer where jumped

9 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Shell

Interpret
:!<shell> Shell
Command

Read in
:r!<shell> output of
shell

:r!date Insert date

Replace
:!!date current line
with date

Command line

Insert
current
word into
<C-r><C-w>
the
command
line

Paste from
<C-r>"
" register

Auto-
completion
<C-x><C-f> of path in
insert
mode

_ Tricks

Remove duplicate lines


# Also see
:sort | %!uniq -u
Devhints (devhints.io)
Vim cheatsheet (vim.rotrr.com)
To number the lines in the file
Vim documentation (vimdoc.sourceforge.net)
Interactive Vim tutorial (openvim.com)
:%!cat -n

Copy whole doc to clipboard

:%w !pbcopy # Mac OS X


P OP U L A R W EBSITE
:%w !xclip -i -sel c # GNU/Linux
Bash :%w !xsel -i -b # GNU/Linux
 QuickRef.ME
scripting SSH Policy

10 of 11 2/10/21, 11:04 AM
Vim - Quick Reference Cheat Sheet https://quickref.me/vim

Share quick reference cheat sheet for Vim Netstat About


developers. RegEX PostgreSQL
QuickRef

© 2021 QuickRef.ME, All rights reserved.     

11 of 11 2/10/21, 11:04 AM

You might also like