Skip to content

Instantly share code, notes, and snippets.

@leimingyu
Last active October 26, 2023 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leimingyu/3458e5db7b542217b18c9495bf3275bd to your computer and use it in GitHub Desktop.
Save leimingyu/3458e5db7b542217b18c9495bf3275bd to your computer and use it in GitHub Desktop.
vim cheat sheet
  1. go to the begging of the line
type: 0
  1. go to the end of the line
type: $
  1. undo
type: u
  1. redo
type: ctrl + r
  1. move word by word
type: w
  1. move backwards by word
type : b
  1. replace current char
type : r , then type new char on current char location
  1. delete current line
type: dd
  1. delete current word
type: dw
  1. delete current char
type : x
  1. copy current line
type: yy
  1. paste after a line
type : p
  1. paste before a line
type : P
  1. repeat previous one simple action
type :  .
  1. move the below line to append current line
type: J
  1. go to bottom of the file
type : G
  1. go to top of the file
type : gg
  1. go to top/middle/bottom of the screen
type : H
type : M
type : L
  1. move to the end of the word
type : e
  1. search a pattern
type : /<pattern>
then type : n , to search forwards
or type: N, to search backwards
  1. show linenumber
type ":set number"

to no show the linenumber, type ":set nonumber"
  1. open file at linenumber n
type "vim +n targetFile" on the commandline
  1. search occurrence of the pattern old to new, and confirm the replacement each time
type ":%s/old/new/gc"

without confirmation, you can type ":%s/old/new/g"

  1. mark a line, then visit back later
to mark a line, press m, then a letter/symbol
to revisit, press single quote, then press the pre-defined letter/symbol
  1. go to a specific line number
<lineNumber>G
  1. forward/backward one screen
forward press: ctrl + f
backward press: ctrl + b
  1. split screen verticaly to show anotherFile
:vsplit <anotherFile>
  1. create or decrease number by 1
use Ctrl+A to increment (add to) the number under the cursor
use Ctrl+X to decrement it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment