Vim Editor

Regex

  • Hit 'Esc' [COMMAND Mode]

  • Hit 'i' [INSERT mode]

  • /word [Search-word] ; Hit Enter ;n -Move down search ; Shift +n - Move up search

    • eg: To replace all spaces with a comma(,) : :%s/\s\+/,/g

  • w [Write]

  • wq [Write and quit]

  • q! [Quit without saving]

  • Search and replace :%s/matchstring/replacewith/gc [g- Whole doc; c- Ask for each]

  • Delete first 17 characters from every line: :1,$s/^.................//

  • Delete the last character from every line: :%s/.\{1}$//

  • Replace ' , ' with a new line. : :%s/,/\r/g

  • Remove all lines that do not contain a string: :g!/price/d

  • Remove all lines that contain a string: :g/MOBILE/d

  • Delete lines dd [Delete single line] 5dd [Deletes 5 lines]

  • Copy current line yy

  • p -Paste

  • u -Undo

  • x -Delete character

  • Ctrl+ r -Redo

  • Number each line : :set number

  • Merge 100 lines into one line: j100

  • Sort : :sort

  • Remove duplicates: sort u

  • Append <text> at the start of each line : :%s!^!<insert text here>!

  • Replace the first character in all lines to uppercase : :%s/^./\u&/g

  • Remove trailing white-spaces from each line: :%s/\s\+$//e

Last updated