-
-
Notifications
You must be signed in to change notification settings - Fork 2
1.2. Vim Notes
shinokada edited this page Feb 16, 2014
·
2 revisions
vimtutor
:h learnvim
:so %
. (dot)
:edit! # get into the earliest saved state.
# indent a line
>>
# Indent three lines.
>>j.j. or >3> or 3>>
# Indent from the current line to the end of the file
>G
# Change
c
# Change word/Word to abc
cwabc # cWabc
# To delete the character under the cursor.
x
# Delete three characters
x... # or 3x
# To delete the current line
dd
# Delete two lines
dd. # or d2d or 2dd
# Delete upto the end of line and ready to type.
C # or c$, c stands for change
# Delete one letter and enters Insert mode.
s # or cl
# Delete the line and enters Insert mode.
S # or ^C
# Delete a word
daw
# Delete backward
db
# Delete forward
dw
# Delete up to the second comma
d2t,
vim vikia: Moving around All the right move
# move to the beginning of the line
0
# move to the end of the line
$
# move to the first non-blank
^
# go to the last non-blank character of line
g_
# word, end and back
w # W
e # E
b # B
# Jump forward/backward one sentence.
) # (
# Jump forward/backward one paragraph
} # {
# Move to the beginning of the line and chnage to the insert mode.
I or ^i
# Move to the end of line and enters Insert mode.
A # or $a
# move backward by word
b
# move forward by word
w
# move to the beginning of the line
0
# find, find backward
f # F
# find till, find till backward
t # T
# Replace mode, enter insert mode with typing over existing characters
R
# Append, move to the end of line and insert mode
A
# Open below. Insert a new line under the current line and enters Insert mode.
o # or A<CR>
# Open above. Insert a new line above the current line and enters Insert mode.
O # or ko
# Undo, redo and undo all in the line
u
^R
U
ZZ, :x, :wq # write and quit
:q! # without write and quit
:e! # return to the original
:w! # to overwrite
:w filename # to save to a newfile
:h # or :help
ZZ # to end help
# on a tag
^] # will move to that tag
# going back
^t
# get the help on yank
:h yank
# get the help on ^A
:h ^a
# get the help on ^h with the insert mode
:h i_^h
# find +
f+
# s deletes the character and then enters insert mode
# enter changes space + space
s +
# repeat the last search
;
# repat
.
# repeat search and replace
;.
# Change till ?
ct? # or ct<letter>
# Change and find ?
cf? # or cf<letter>
# scan line for next character
fx
# scan line for previous charcter
Fx
# scan line for next character and move to the left of the letter x
tx
# scan line for previous character and move to the right of the letter x
Tx
# scan document for next match
/pattern<CR>
# scan document for previous match
?pattern<CR>
# will search for the word under the cursor
*
# clear word(cw)(and change to insert mode) and type new word
cwnewword<ESC>
# next search
n
# repeat the change
.
# repeat fx, Fx, tx, Tx
;
# reverse fx, Fx, tx, Tx
,
# repeat /pattern or ?pattern
n
# reverse /pattern or ?pattern
N
s[ubstitute]
:s/target/replacement
# repeat substitue
&
# reverse it
u
# g-flag for global
:s/foo/bar/g # Change each 'foo' to 'bar' in the current line.
:%s/foo/bar/g # Change each 'foo' to 'bar' in all lines.
:set spell spelllang=en_us
# set locally
:setlocal spell spelllang=en_us
# turn off spelling
:set nospell
# find next misspelled word
]s
# find previous misspelled word
[s
# find alternatives
z= # and type number
# add 1 to a number at or after the cursor. This will look ahead for a digit and jumps to it.
<C-a> # ctrl+a
# subtract 1 from a number
<C-x>
# add 10 to a number
10<C-a>
# subtract 180
180<C-x>
# opening vim with multiple files
vim -p file1 file2
# toggle between files
gt # gT
<C-v> # select lines
I#<Esc>
# yank all lines
:%y+
# paste
p
Hit <kbd>ctrl-z</kbd> to go to terminal. Type <kbd>fg</kbd> to go back to vim.
:%normal 2x
:%s/^ # Note: there are two spaces after ^.
# Move indentation to left for every line:
:%normal <<
Vim | Normal |
---|---|
put | paste |
yank | copy |
delete(and kepp it in a register) | cut |
# to increase one
<C-a>
# to decrease one
<C-x>
Important: The Tables of Content are generated. Any change will be overridden on the next update.
For more information: GitHub Wikifier