terminal text editor
Purpose
- Only list the useful keys that I’m unfamiliar with here.
Offical Website
man vim
- Home : http://www.vim.org/
- Docs : http://www.vim.org/docs.php
- Vim documentation: help : http://vimdoc.sourceforge.net/htmldoc/
Recommended
- Vim Cheat Sheet - Image
- Vim cheatsheet : https://devhints.io/vim
- Interactive Vim tutorial : https://openvim.com/
- SpaceVim : https://spacevim.org/ - Modern Vim Distribution
My config files
- .vimrc : for Vim & NeoVim in terminal
- .cvimrc : for Chrome 'cVim' Plugin
- How to Use : https://droidrant.com/using-cvim
- Source Code : https://github.com/1995eaton/chromium-vim
- .ideavimrc : for JetBrains 'IdeaVim' Plugin
^ o
|^ i
[ Prev | Next ] Cursor Pos{
|}
[ Prev | Next ] Blank Linew
|⇧ W
Head of Next [ Word / Str ]e
|⇧ E
Tail of Next [ Word / Str ]b
|⇧ B
Head of Prev [ Word / Str ]ge
|gE
Tail of Prev [ Word / Str ];
Repeat the last manipulation aboutf
t
⇧ F
⇧ T
0
Head of Line^
=⇧ 6
Head of Line ( Non-Whitespace )$
=⇧ 4
End of Line"
Switch to some Register-
Head of Prev Line⇧ +
Head of Next Line
Mimic Emacs in Insert Mode
^ b
=←
^ f
=→
^ p
=↑
^ n
=↓
^ a
=Home
^ e
=End
^ k
Del to End of Line^ u
Del to Head of Line^ t
Exchange Chars ( Before & After Cursor )
Powered by plugin
^ ]
Find Declaration^ t
Back from Declaration
`^
Last position of cursor in insert mode'^
Head of line of last position of cursor in insert mode
`.
Last change'.
Head of line of last change
``
Last jump''
Head of line of last jump
- It's a Vim plugin. spf13-vim makes it easier to use:
- In normal mode
,
,,
( Twice ) then input a cursor motion instruction,- such as
w
,e
,b
,f*
,F*
,t*
,T*
or etc.
- such as
- The screen will display some keycues.
- If you input one of the keycues, then your cursor will get to the specified place.
- In normal mode
ciw
Del Wordcaw
Del Word including the Following Spaces 凵dw
Del until Head of Next Wordde
Del to End of Cur Wordci*
Select & Manipulate the string surrounded by*
.ca*
Select & Manipulate the string surrounded by*
including*
.
Paragraph
vip
Select paragraph ( same as⇧ V
,⇧ }
? )vipip
Select more paragraphs ( better :⇧ V
,⇧ }
,⇧ }
, … )yip
Yank inner paragraphyap
Yank paragraph (including newline) ( better thanyip
)
x
Del Char Forward ⌦⇧ X
Del Char Backward ⌫s
Del Char Forward & then Insert⇧ S
Del Current Line & then Insert⇧ C
Del to End of Line & then Insert⇧ D
Del to End of Line
xp
Exchange the Current Char and the Next Charddp
Exchange the Current Line and the Next Line
⇧ Y
Copy from the cursor to the end of line⇧ K
Join curren line and next line without breaking]p
Paste under the current indentation level
⇧ ~
Toggle Case & Mv Cursor to Next chargu
to Lowercase- or
u
after selecting range
- or
gU
to Uppercase- or
⇧ U
after selecting range
- or
guu
|gugu
Lowercase current linegUU
|gUgU
Lowercase current line
In Normal Mode
^ a
Increase Num^ x
Decrease Num
Example
- In normal mode
^ v
then select a block area ⇧ I
then type some string to insert⎋
,⎋
( Twice ) to apply the insertion at each line heading of the selected block area
gf
Open Path where cursor is
^ s
=:w
Save ( valid in both Insert & Normal Mode )⇧ ZZ
Save & Quit⇧ ZQ
Quit without Saving
^w
,n
=:new<CR>
New Horizontal Split ( editing new empty buffer )^w
,s
=:split<CR>
Split Window Horizontally ( editing current buffer )^w
,v
=:vsplit<CR>
Split Window Vertically ( editing current buffer )^w
,c
=:close<CR>
Close Window^w
,o
=:only<CR>
Close All Windows But only the Current^w
,w
Go to Next window^w
,p
Go to Prev window^w
,↑
Go to window Above^w
,↓
Go to window Below^w
,←
Go to window on Left^w
,→
Go to window on Right
:tabe [path/to/file]<CR>
|:tabedit [path/to/file]<CR>
Open Existing File in New Tab:tabp
Previous Tab:tabn
Next Tab:edit [path/to/file]<CR>
Open Existing File in Current Tab:tabnew<CR>
Open New Empty Tab:tabc<CR>
Close Current Tab:tabo<CR>
Close all Other Tabs But only the Current
Custom
,
,t
=:tabedit<space>
,
,e
=:edit<space>
L
=gt
=:tabn<CR>
Next TabH
=gT
=:tabp<CR>
Prev Tab,
,a
=1gt
to Tab 1,
,s
=2gt
to Tab 2- … d f g h j k …
,
,l
=9gt
to Tab 9,
,;
=10gt
to Tab 10,
,1
=11gt
to Tab 11,
,2
=12gt
to Tab 12- …
,
,9
=19gt
to Tab 19,
,0
=20gt
to Tab 20,
,W
=:tabm<space>-1<CR>
Move Tab Left,
,E
=:tabm<space>+1<CR>
Move Tab Right
.
Repeat Command;
Repeat Movement : f / F / t / T
q a~z|A~Z
Start Recording Macro marked asa~z|A~Z
q
Stop Recording@ a~z|A~Z
Play Macro marked asa~z|A~Z
@@
Repeat Macro that you last used
:%s/search_str/replace_str/gci
:
switch to Command Mode%
find each occurence ofsearch_str
s
replace operationg
replace globallyc
ask for confirmationi
case insensitive ,I
case sensitive
:s/foo/bar/
- On each line, replace the first occurrence of "foo" with "bar".
:'<,'>s/foo/bar/g
'<,'>
replace within a visual selection (when compiled with +visual)
:5,12$/foo/bar/g
5
,12
start from line 5 to the line 12
:.,$/foo/bar/g
.
,$
start from the current line to the last line
:.,+2s/foo/bar/g
.
,+2
start from the current line to the next two lines
:'a,'bs/foo/bar/g
'a
,'b
start from the mark a to the mark b
:g/^baz/s/foo/bar/g
- Change each 'foo' to 'bar' in each line starting with 'baz'
- Reference : Search and replace & Vim 字符串替换及小技巧
ga
Show ASCII of Charg8
Goto UTF-8 of Char
Custom
,
,h
=:set noh<CR>
Deactivate Highlighted,
,n
=:set nu!<CR>
Toggle Absolute Line Number,
,r
=:set rnu!<CR>
Toggle Relative Line Number
- Save all the current
:map
and:set
settings to a file.- See
:help mkexrc
for details.
- See
:mkvimrc
# or
:mkexrc
- 直接从命令行中获取内容并输出到文件中, 例如
:r !ls
:scriptnames
查看使用到的文件 : 有没有使用.vimrc
?vim -u path/to/.vimrc
手动指定配置文件