vim命令总结

cat /etc/os-release
command -v vim
vim +20 updated_file.txt : open the file and skip line 20
vim -o file1.txt file2.txt : open files in horizon screens
vim -O file1.txt file2.txt : open files in vertical screens

  • normal mode
    • i -> insert mode
    • v -> visual mode, and select para
    • shift + a: skip to the end of the line -> insert mode
    • u: undo last change
    • x: delete one char
    • dd: delete the line and copy to paste buffer
    • 0: start of line
    • hjkl: left, up, down, right
    • $: end of line
    • gg: start of file
    • shift + g: end of file
    • pageDown: next page
    • pageUp: last page
    • p: paste the para copyed in the visual mode
    • /[prara] : search certain chars, n or shift+n to another matched element
  • insert mode
    • esc->normal mode
    • : ->command mode
  • command mode
    • q -> quit
    • q! -> abort and quit
    • w [new_file_name]-> write
    • r [file_name] : read anothe file in buffer
    • e [file_name] : open file in another buffer
    • e new: open a block buffer, cant quit before save
    • badd [file_name] : open file in another buffer backgroud
    • bn : next buffer or skip to the first buffer
    • bp : last buffer
    • bd : delete buffer
    • ! [linux_command] : excute the command and give the output
    • %s/[replaced_mode]/[target_mode]/g
    • split [file_name] : open a new file in the another horizonlal screen, sp [file_name], the same file will auto sync in different screens
    • vs [file name] : open a new file in the another vertical screen
    • Ctrl+ww: switch to another screen
    • set number : appear line number
    • set nonumber : disappear line number
  • visual moder [file_name] :
    • y : copy the para and exit
    • :sort ui : sort selected line by char

make vim change persist in ~/.vimrc

" Adds line numbers, this line is annotation
set number
posted @ 2026-07-12 19:02  tanch25  阅读(7)  评论(0)    收藏  举报