Skip to content

Instantly share code, notes, and snippets.

@vpnwall-services
Last active March 21, 2024 17:22
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 vpnwall-services/64610627691637414858b08996f2c4c7 to your computer and use it in GitHub Desktop.
Save vpnwall-services/64610627691637414858b08996f2c4c7 to your computer and use it in GitHub Desktop.
[VIM 101] VIM Cookbook with helpfuls Vim common commands #index #book #vim #help #cookbook #comment #replay #macro

VIM 101 - VIM Cookbook - Helpful commands

  • Replace all contiguous spaces with a ; s/ \{2,}/ /g

  • Vim replay macro until end of buffer VG:normal @x

  • Consecutive SED :%s#eth0#ens3#g|%s#eth1#ens4#g|%s#eth2#ens5#g

  • Comment lines containing a word :%s/\(.*string\)/# \1/c

  • Activate mouse mode :set mouse=a

  • Insert range of lines from other file into current :put =readfile('/path/to/foo/foo.c')[146:226]

  • Search and replace all matches in text :%s#oldtext#newtext#g

  • Run a command inside vim :!command <mycommand>

  • Disable unwanted yellow highlight :nohl

  • Jump to line n°30 :30

  • To start recording session q <letter>

  • To stop recording session q

  • To replay recording session @ <letter>

  • Delete all lines matching a pattern :g/profile/d

  • Remove duplicates :sort u

  • Save to a new file and work on it :sav

  • Next and Prec matching words CTRL+N CTRL+P

  • Add words at end of each line selected with Visual Block mode CTRL+V :s/$/TEXT-HERE/g

  • Delete ^M character in file :e ++ff=dos

  • Delete last char of each line :%s#.\{1}$##

  • Delete first char of each line :startNumber,endNumber normal x

  • Replace in selection SHIFT+V then :s#blue#red#g

  • Sort by block of lines :g/Host/,/ForwardAgent\ yes/s/\n/§ :%sort :g/Host/s/§/\r

  • Copy/paste block of lines in a new file :<n>,<m> w new file n and m are lines numbers

  • Delete all blank spaces :g/^ /norm dw

  • Write file with sudo (opened with unprivilegied user) :w !sudo tee %

  • Paste mode set paste

  • Replace space with newline :%s# #(Ctrl + V then ENTER)#g

  • Add quotes in front and at end of each selected lines :%s/^\(.*\)$/"\1"/

  • Replace newlines with space :%s#\n# #g

  • Select all text ggVg

http://vim.wikia.com/wiki/Making_a_list_of_numbers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment