Tools - Editor - Vim

闷骚的程序员

move

** in word (character) unit**

FunctionButton
onk
downj
Lefth
rightl

In words

FunctionButton
previous word endingge
next word startw
Beginning of this word (if already at the beginning of this word, skip to the beginning of the previous word)b
At the end of this word (if it is at the end of this word, skip to the end of the next word)e

in units of screen

FunctionButton
Page downCTRL-f
Page upCTRL-b
Half page downCTRL-d
Half page upCTRL-u
Go up one lineCTRL-y
Next lineCTRL-e
Cursor moves to the top of the screenH
Move cursor to middle of screenM
Cursor moves to the bottom of the screenL
Move the cursor to the top of the screenzt
Move the cursor to the middle of the screenzz
The cursor position moves to the bottom of the screenzb

Line number

FunctionButton
skip to line num:num or numG or numgg

document

FunctionButton
skip to file headergg
Skip to end of fileG

edit

copy

FunctionButton
Copy the word under the cursoryiw
Copy the line where the cursor isyy

paste

FunctionButton
Paste after cursorp
Paste before cursorP

cut

FunctionButton
Cut selectiond
Cut the line where the cursor is locateddd

replace

FunctionButton
Replace str1 with str2 in full text:%s/str1/str2/g
Replace str1 with str2 in lines 1 to 5:1,5s/str1/str2/g

upper and lower case

FunctionButton
Swap the case of the selected content~
Convert the selection to lowercasegu
Convert the selection to uppercasegU
lowercase the current lineguu
Uppercase the current linegUU
Replace matches with uppercase:%s/xxx/\U&/g
Replace matches with lowercase:%s/xxx/\L&/g

Note: & represents all regular expression matches, and \1, ‘\2’, …, \9 represent the 1st to 9th matches.

choose

FunctionButton
Select the last selected areagv
Select bracketed areavi{, vi[, vi(
FunctionButton
Find string down/str
Look up string?str
find nextn
Find previousN
Go down to the word under the cursor*
Go down to the word under the cursor#

Regular expressions

FunctionButton
Match left word boundary\<
Match word right boundary\>
Deduplication:g/^\(.*\)$\n\1/d

Commonly used

FunctionButton
delete blank lines:g/^$/d
undo/UNDOu
redo/REDOC-r
Count lines/words/characters/bytesg C-g
Remove UTF-8 BOM:set nobomb
Keep UTF-8 BOM:set bomb

Global

FunctionButton
quit:q
Enforce!
Execute external commands:!

file operations

FunctionButton
open:e
Open file dialog:bro e
save:w
Save As Dialog:brow
View history file list:ol
View and open history files:bro ol
Rename current file:f filename

vimdiff

FunctionButton 
Move to previous difference[c 
move to next difference]c 
This diff uses the current file’sdp 
This diff uses thedoof the other file
Manual refresh re-diff:diffupdate 

Buffer

FunctionButton
View Buffer List:ls
Go to the next Buffer in the Buffer list:bn
Go to the previous Buffer in the Buffer list:bp
Go to Buffer number num in the Buffer list:bnum
A Buffer you were in before:b#
Remove Buffer number num from the Buffer list:bdnum

Combining commands

Commands can be combined using |, such as cmd1 | cmd2.

code

FunctionButton
Format codegg=G
Remove line numbers at the beginning of lines 1-20:1,20s/^\\s\*[0-9]\*\\s\*//g
Expand Collapse AllzR
Expand current level foldzr
Collapse allzM
current level collapsezm
Toggle collapse/expandza
Recursively collapse/expand the current large blockzA
Collapse current blockzc
Recursively fold the current large blockzC
Expand current blockzo
Recursively expand the current large blockzO
format json data:%!python -m json.tool
Indent current line>>
Unindent current line<<

modeline

Writing:

 vim: set ft=markdown:
 vim: ft=markdown

// vim: noai:ts=4:sw=4
/* vim: noai:ts=4:sw=4 */

Plugins

####CtrlP

Basic keys C-p

FunctionButton
Refresh listF5
switch file/buffer/MRUC-f/b
Toggle full path search/filename searchC-d
Toggle regular expression modeC-r
Previous/next optionsC-k/j
Open file in new tab/vertical split/horizontal splitC-t/v/x
Select the previous/next record in historyC-p/n
Create a file and its parent pathC-y
Mark and open multiple filesC-z C-o
Exit CtrlPC-c

LeaderF

FunctionButton
Open fileLeader-f
open bufferLeader-b
Open MRULeader-m (custom)
exitC-c
Toggle between fuzzy search and regular searchC-r
PasteC-v
Clear inputC-u
Previous/next optionsC-k/j
Open file in new tab/vertical split/horizontal splitC-t/]/v
Refresh listF5

vim-table-mode

FunctionButton
Delete columnLeader-tdc
delete lineLeader-tdd
Reformatting tableLeader-tr

markdown-preview.nvim

FunctionButton
PreviewF5
Stop previewF6

Export PDF: After previewing, use the “Print” function of the browser, select “Save as PDF” for the printer, cancel “Header and Footer”, and then click Save.

Command Line

Jump to a specified line when opening Vim:

vim +[num] filename

num indicates the line number, if not filled, it will jump to the end of the file.

Information

Search

    Table of Contents