VIM Basics

text jump

  • w/W: skip forward by word
  • b/B: jump back by word
  • $: end of line
  • 0: the beginning of the line, use ^ for the beginning of a non-empty line
  • { }: Paragraph jump
  • f{character}: jump to the first letter at the beginning of {} in this line, F jumps back


Text Editor:

  • ci" delete everything inside the quotes
  • dW delete a word
  • add after p
  • add before P


Find and replace:

  • /find down, n next n previous
  • ? look up
  • []s/Pattern/ReplaceWith/g [] can be % for full text or "a,b" for a specific range, gi for ignoring case, gc for independent confirmation
  • Visual input V in Normal
  • V}% to replace in a range
  • When looking for a pattern, you can use \zs to exit the matched characters


Macros and batch processing:

  • q start recording followed by name, then press end
  • Called by @name; @@ will call a recently executed script


Cursor/Page Movement:

  • CTRL-F/B full screen page
  • CTRL-D/U half screen page
  • H current head; M current middle; L current tail
  • zt put the current line at the top of the page
  • zb put the current line at the end of the page
  • zz puts the current line in the middle
  • m{} can record the current position in {}
  • '{} jump back via {}


Using the command line:

  • :!{CMD} invoke command line
  • read !{CMD} import command line input into VIM, using tricks can be used to import remote code into VIM through r !curl --slient http://address
  • You can send specific blocks to the OS through visual mode. After combing through the command line, the results are sent back to VIM


Multi-file operation:

  • : ls view
  • : bnext next
  • : bp previous
  • : bf first


Multi-window operation:

  • vsplit {EDIT_DOC} left and right points
  • split {EDIT_DOC} up and down
  • CTRL+W hjkl move between windows
  • CTRL+W HJKL move the window up, down, left and right
  • CTRL+W +/- Add and subtract lines
  • CTRL+W <> Add or subtract columns


Indent and collapse:

  • >> indent
  • << Cancel indentation, support cross-line operation through 6<<, support block operation through VISUAL MODE
  • You can enter VISUAL LINE mode by SHIFT+V for batch indentation
  • = Blocks can be selected through VISUAL MODE and then batch FORMAT
  • =G, reformat entire file (cursor at file header)
  • CTRL+T/D can control indentation (INSERT MODE)
  • 5zf fold the next N lines, zo open the fold zc close zd delete
  • zf% find the current {} matching range to fold
  • zi disable fold
  • #set fdm=syntax


help:

  • help: {theme}
  • CTRL+} to open a link

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327041572&siteId=291194637