motion is cursor move
- basic:
- move:
hjkl
or<arrow>
- word:
w
: next word heade
word tail,b
: last word head orshift+<arrow>
- line:
^/$
: start/end of line0
: start of line %
: match pair of()
[]
{}
<>
- move in file:
gg
topG
bottom 5gg
or5G
jump to line 5ctrl+b/f
(back/fore) full screen scroll ORshift+<arrow>
ctrl+u/d
(up/down) 1/2 screen scroll{}
jump paragraph50%
goto 50% of file
2.advanced
H
M
L
: scroll to top/middle/bottom of the screenfx
- jump to next occurrence of character xFx
backwardtx
- jump to before next occurrence of character xTx
backward;
repeat previous f, t, F or T movement,
repeat previous f, t, F or T movement, backwards
- Note : all motion can spec a quantity like
d3w
,9<down>
move won't change the cursor position
-
zz
frame cursor -
ctrl-o
: navi back(out)ctrl-i
: navi fore(in) -
ctrl-]
: enter
some verb need a motion
: dw
=d
+w
verb can have a quantity like 3x
9dl
- list:
- cut/delete
d+
where+
=dd
dw
d$
=D
,daw
delete a word - join line
J
- delete at cursor:
x
- copy/yank
y+
:yy
yw
y$
- put/paste:
p
paste after curP
paste before cur - replace 1 char:
r
:ra
replace toa
- undo
u
/ undo lineU
redoctrl-r
.
repeat last change- g-command like
gJ
see:help g
g~~
toggle casegU
upper casegUe
gu
lower caseguu
- change
c
(delete and enter insert):cc
=S
cl
=s
c$
=C
caw
- object:
a+
a object,aw
a wordas
a sentenceab
a block()
aB
a block{}
i+
inner object,iw
inner wordis
inner sentenceib
inner block
-
insert mode:
i
insert(before)o
open(new line)a
append(after)ea
frequently used^n
next find^j
new line^t
tab line^d
revert tab line^i
insert tab^u
delete left^w
delete left word<insert>
toggle replace mode
-
replace mode:
R
-
visual mode(marking mode):
v
: enter visual modeV
enter visual line modectrl+v
: enter visual block modeo O
: move cursor to corner
<>
shift left/right (with tab)u U ~
casey d
copy/delete
``
goto last jump"
last edit.
last change`a
goto ama
set mark a; mark name [0-9a-z]:marks
list marks:jump
jump history:changes
change historyy`a
yank to a mark
- search:
- regex: http://www.vimregex.com/
/
: search forward?
: search backward*/#
: search with cur wordn/N
: to next/previous- search is a
verb
, can use like a verb:d/the<Enter>
//
/?
/&
last search:s/\v(\w+)/\u\1/g
use\v
to mimic perl regex
- substitute:
- substitute/replace
:substitute
, mostly use:s
- syntax:
:[range]substitute/from/to/[flags]
:s/thee/the
default is cur line%s/thee/the
%
all line
:s/thee/the/gc
replace all and confirm
- flag:
g
all,c
confirm,p
print,i/I
case ignore
- range:
1,5
line 1 to 5,5
line 5.
: cur line,.w
write cur line.,$
cur to last line.,.+4
cur to next 4 line%
the whole file't,'b
from mark t to mark b'<,'>
visual selection,<
is visual start,>
is visual end.,/patter
cur to next line that match pattern.,?pattern
cur to prev line that match pattern/Section 1/+,/Section 2/-
non-inclusively search for section 1 and section 2/Section 1/;/Subsection/-,/Subsection/+
:/Section/+ y
:// normal p
- global:
:[range]global/{pattern}/{command}
search pattern and exec a command- :g+//+s/foobar/barfoo/g
-
pattern(regex):
/\<the\>
\< \>
word boundary^$
line boundary. \s \d \w \a
\l=lower \u=upper
same as regex
-
option
hlsearch
=hls
nohlsearch
wrapscan
incsearch
=is
- show file info:
ctrl-g
- quit with write:
ZZ
- commands, start with
:
:!
shell command::!ls ~/dev
:set
set var:set ic
=set ignorecase
:set history=1000
set value,:set history
get value:set iskeyword&
set to default value
:options
show options<ctrl-d>/<tab>
auto complete
1.file
:file a.txt
change file name:r
read and merge in:r !ls
read the stdout of ls:w
write file::w README.md
:write >> logfile
append:saveas
:edit
2.multi file
:ls
:args
:args FILES
:next
:prev
first
:last
- quick jump, to last
<ctrl+^>
-
basic
- split window
:split
:split a.txt
:new
:3split alpha.c
window size is 3 line
- window commands:
:close
:only
- command all
qall
wall
wqall
- split window
-
ctrl-w
: input window commandw
: jump windowq
: close window<arrow>
move window+/-
: window sizes
v
splitH
J
resplitx
exchange<arrow>
: move windowf
Split current window in two. Edit file name under cursor.d
goto definition
-
vsplit:
:vsplit
:vnew
-
tab:
-
:tabnew
:tabedit
:tabclose
:tabonly
:tabmove
:tabnext
:tabprevious
-
gt
gT
jump tab5gt
jump tab 5 -
ctrl-w gf
:Open a new tab page and edit the file name under the cursor. -
options:
winheight
- register(think as named clipboard)
-
:reg
show; reg name is[0-9a-z]
-
"xy
yank to x"xp
put from x;- use uppercase for append mode:
"Xy
append to x + $
is clipboard:"+y
yank to system clipboard- register cross session; stored in
~/.viminfo
- use uppercase for append mode:
-
in insert mode:
^r
insert register
Tip Special registers:
0 - last yank
" - unnamed register, last delete or yank
% - current file name
# - alternate file name
* - clipboard contents (X11 primary)
+ - clipboard contents (X11 clipboard)
/ - last search pattern
: - last command-line
. - last inserted text
- - last small (less than a line) delete
= - expression register
_ - black hole register
- macro
- macro is the same thing as reg ,stored in
reg
qa
start recode macro aq
stop@a
play macro a@@
repeat last macroqA/word<Enter>q
append to macro a
.
repeat last change
- macro is the same thing as reg ,stored in
>>
<<
>%
indent block>ib
inner block>at
tag==
indent current line=$
indent all=%
indent to block]p
paste and indent
gq+
,help gq
gqap
:gq
formatap
a paragraphgggqG
:gg
go file startgq
formatG
end of file
* `:help`: show help
* `:help w` `help ctrl-d`: show help of `command`s
put init.vim
here
~/.config/nvim/init.vim (Unix and OSX)
~/AppData/Local/nvim/init.vim (Windows)
set backup
set backupext=.bak
set patchmode=.orig
set backspace=indent,eol,start
set autoindent
set history=50
set ruler
set showcmd
set incsearch
set hlsearch
set sidescroll=10
set whichwrap=b,s
set list # show tab symbol
set listchars=tab:>-,trail:- # set tab style
autowrite
syntax on
$VIMRUNTIME/colors
path of theme:colorscheme evening
like shortcut or macro
:map <F5> i{<Esc>ea}<Esc>
press F5
:map \p i(<Esc>ea)<Esc>
:map \c i{<Esc>ea}<Esc>
press \ + p
quickly
There are two types of plugins:
- global plugin: Used for all kinds of files
- filetype plugin: Only used for a specific type of file
~/.vimrc
- package and plugin are basically the same thing
packadd vimball
load packagemkdir -p ~/.local/share/nvim/site/pack/fancy
put the package here
-
There are two types of plugins:
- global plugin: Used for all kinds of files
- filetype plugin: Only used for a specific type of file
-
help standard-plugin-list
-
$VIMRUNTIME/plugin
$VIMRUNTIME/macros
system plugin path -
~/.local/share/nvim/site/plugin
user plugin path
~/.local/share/nvim/site/ftplugin
path
The generic names for the filetype plugins are:
ftplugin/<filetype>.vim
ftplugin/<filetype>_<name>.vim
ftplugin/<filetype>/<name>.vim
Here <name>
can be any name that you prefer.
Examples for the "stuff" filetype on Unix:
~/.local/share/nvim/site/ftplugin/stuff.vim
~/.local/share/nvim/site/ftplugin/stuff_def.vim
~/.local/share/nvim/site/ftplugin/stuff/header.vim