Tools - Editor - Vim

move

in units of characters (characters)

FunctionsButtons
onk
downj
lefth
rightl

in words

FunctionsButtons
previous word endingge
the beginning of the next wordw
The beginning of this word (if already at the beginning of this word, skip to the beginning of the previous word)b
The end of this word (skip to the end of the next word if it is already at the end of this word)e

In screen units

FunctionsButtons
Page downCTRL-f
page upCTRL-b
Turn half a page downCTRL-d
Turn half a page upCTRL-u
Go up one lineCTRL-y
Go down one lineCTRL-e
Move the cursor to the top of the screenH
Move the cursor to the middle of the screenM
Move the cursor to the bottom of the screenL
Move the cursor position to the top of the screenzt
Move the cursor position to the middle of the screenzz
Move the cursor position to the bottom of the screenzb

line number

FunctionsButtons
jump to line num:num or numG or numgg

document

FunctionsButtons
Jump to the beginning of the filegg
Jump to end of fileG

edit

copy

FunctionsButtons
Copy the word under the cursoryiw
Copy the line where the cursor is locatedyy

paste

FunctionsButtons
paste after cursorp
Paste before cursorP

cut

FunctionsButtons
cut selectiond
Cut the line where the cursor is locateddd

replace

FunctionsButtons
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

Case

FunctionsButtons
Swap case selection~
Convert all selected content to lowercasegu
Convert selection to uppercasegU
lowercase the current lineguu
Make the current line uppercasegUU
Replace matches with uppercase:%s/xxx/\U&/g
Replace matches with lowercase:%s/xxx/\L&/g

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

choose

FunctionsButtons
Select the last selected regiongv
Select the area inside the bracketsvi{, vi[, vi(
FunctionsButtons
Find strings down/str
look up string?str
find nextn
Find PreviousN
Find the word under the cursor*
Find the word under the cursor#

Regular Expressions

FunctionsButtons
matches word left boundary\<
matches the right edge of a word\>
deduplication:g/^\(.*\)$\n\1/d

Commonly used

FunctionsButtons
delete empty lines:g/^$/d
Undo/UNDOu
redo/REDOC-r
Count lines/words/chars/bytesg C-g
Remove UTF-8 BOM:set nobomb
Preserve UTF-8 BOM:set bomb

Global

FunctionsButtons
exit:q
Mandatory!
Execute external command:!

File Operations

FunctionsButtons
open:e
open file dialog:bro e
save:w
Save As Dialog:brow
view a list of historical files:ol
view and open history files:bro ol
Rename the current file:f filename

vimdiff

FunctionsButtons
move to previous difference[c
move to next difference]c
The diff point uses thedp of the current file
This diff usesdo from other files
Manually refresh and re-diff:diffupdate

Buffer

FunctionsButtons
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 have been in before:b#
Delete num buffers from the Buffer list:bdnum

Combine commands

You can use | to combine commands, such as cmd1 | cmd2.

code

FunctionsButtons
formatting codegg=G
Remove the line number at the beginning of line 1-20:1,20s/^\\s\*[0-9]\*\\s\*//g
Expand All CollapsezR
Expand the current level of foldingzr
Collapse AllzM
current level collapsezm
Toggle collapse/expandza
Recursively fold/expand the current large blockzA
Collapse the 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 the 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

FunctionsButtons
Refresh listF5
switch file/buffer/MRUC-f/b
Toggle full path search/filename searchC-d
toggle regex modeC-r
Previous/Next optionC-k/j
Open file in new tab/vertical split/horizontal splitC-t /v/x
The previous/next record of history selectionC-p/n
create file and its parent directoryC-y
mark and open multiple filesC-z C-o
Exit CtrlPC-c

LeaderF

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

vim-table-mode

FunctionsButtons
drop columnLeader-tdc
delete lineLeader-tdd
Reformat tableLeader-tr

markdown-preview.nvim

FunctionsButtons
PreviewF5
stop previewF6

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

Command Line

Jump to the specified line when opening Vim:

vim +[num] filename

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

Document Information

Search

    Table of Contents