Operate with an operator inner or around text blocks
Text objects
Shortcut
Description
p
Paragraph
w
Word
W
WORD (surrounded by whitespace)
s
Sentence
[ ( { <
A [], (), or {} block
] ) } >
A [], (), or {} block
' " `
A quoted string
b
A block [(
B
A block in [{
t
A HTML tag block
See :help text-objects
Delete
Shortcut
Description
diw
Delete inner word
dis
Delete inner sentence
di"
Delete in quotes
da"
Delete in quotes (including quotes)
dip
Delete a paragraph
Selections
Shortcut
Description
vi"
Select inner quotes "..."
va"
Select quotes "..."
vi[
Select inner brackets [...]
va[
Select brackets [...]
viw
Select inner word
vip
Select inner paragraph
vipip
Select more paragraph
Misc
Shortcut
Description
ciw
Change inner word
ci"
Change inner quotes
cit
Change inner tags (HTML)
cip
Change inner paragraph
yip
Yank inner paragraph
yap
Yank paragraph (including newline)
Vim Multiple files
Buffers
-
-
:e file
Edit a file in a new buffer
:bn
Go to the next buffer
:bp
Go to the previous buffer
:bd
Remove file from buffer list
:b 5
Open buffer #5
:b file
Go to a buffer by file
:ls
List all open buffers
:sp file
Open and split window
:vs file
Open and vertically split window
:hid
Hide this buffer
:wn
Write file and move to next
:tab ba
Edit all buffers as tabs
Windows
-
-
s
Split window
v
Split window vertically
w
Switch windows
q
Quit a window
T
Break out into a new tab
x
Swap current with next
- / +
Decrease/Increase height
< / >
Decrease/Increase width
=
Equally high and wide
h / l
Go to the left/right window
j / k
Go to the up/down window
Tabs
Shortcut
Description
:tabe [file]
Edit file in a new tab
:tabf [file]
Open if exists in new tab
:tabc
Close current tab
:tabo
Close other tabs
:tabs
List all tabs
:tabr
Go to first tab
:tabl
Go to last tab
:tabm 0
Move to position 0
:tabn
Go to next tab
:tabp
Go to previous tab
Normal mode
Shortcut
Description
gt
Go to next tab
gT
Go to previous tab
2gt
Go to tab number 2
Vim Search and Replace
Search
-
-
/foo
Search forward
/foo\c
Search forward (case insensitive)
?foo
Search backward
/\v\d+
Search with regex
n
Next matching search pattern
N
Previous match
*
Search for current word forward
#
Search for current word backward
Replace LINE
`
:[range]s/{pattern}/{str}/[flags]
`
:s/old/new
Replace first
:s/old/new/g
Replace all
:s/\vold/new/g
Replace all with regex
:s/old/new/gc
replace all (Confirm)
:s/old/new/i
Ignore case replace first
:2,6s/old/new/g
Replace between lines 2-6
Replace FILE
`
:%s/{pattern}/{str}/[flags]
`
:%s/old/new
Replace first
:%s/old/new/g
Replace all
:%s/old/new/gc
Replace all (Confirm)
:%s/old/new/gi
Replace all (ignore case)
:%s/\vold/new/g
Replace all with regex
Ranges
-
-
%
Entire file
β<,β>
Current selection
5
Line 5
5,10
Lines 5 to 10
$
Last line
2,$
Lines 2 to Last
.
Current line
,3
Next 3 lines
-3,
Forward 3 lines
Global command
`
:[range]g/{pattern}/[command]
`
:g/foo/d
Delete lines containing foo
:g!/foo/d
Delete lines not containing foo
:g/^\s*$/d
Delete all blank lines
:g/foo/t$
Copy lines containing foo to EOF
:g/foo/m$
Move lines containing foo to EOF
:g/^/m0
Reverse a file
:g/^/t.
Duplicate every line
Inverse :g
`
:[range]v/{pattern}/[command]
`
:v/foo/d
Delete lines not containing foo(also :g!/foo/d)
Flags
-
-
g
Replace all occurrences
i
Ignore case
I
Don't ignore case
c
Confirm each substitution
Substitute expression (magic)
-
-
&
\0
\1...\9
Replace with the group 0-9
\u
Uppercase next letter
\U
Uppercase following characters
\l
Lowercase next letter
\L
Lowercase following characters
\e
End of \u, \U, \l and \L
\E
End of \u, \U, \l and \L
Examples
`
:s/a|b/xxx\0xxx/g # Modifies "a b" to "xxxaxxx xxxbxxx"
:s/test/\U& file/ # Modifies "test" to "TEST FILE"
:s/(test)/\U\1\e file/ # Modifies "test" to "TEST file"
:s/\v([abc])([efg])/\2\1/g # Modifies "af fa bg" to "fa fa gb"
:s/\v\w+/\u\0/g # Modifies "bla bla" to "Bla Bla"
:s/\v([ab])|([cd])/\1x/g # Modifies "a b c d" to "ax bx x x"
:%s/./\L&/ # Modifies "HTML" to "html"
:s/\v<(.)(\w)/\u\1\L\2/g # Make every first letter of a word uppercase
:%s/^(.)\n\1/\1/ # Remove duplicate lines
:%s/<\/=(\w+)>/\U&/g # Convert HTML-Tags to uppercase
:g/^pattern/s/$/mytext # Find and append text to the end
:g/pattern/norm! @i # Run a macro on matching lines
/^(.)(\r\?\n\1)+$ # View the duplicates lines
/\v^(.*)(\r?\n\1)+$ # View the duplicates lines (very magic)
:v/./,/./-j # Compress blank lines into a blank line
:g//,//d # Delete inclusively from to
Top comments (0)