Another Japan in the World

Jun Aruga's blog, who lived in Japan, Singapore, live in Czech Republic. Mainly about IT and travel.

Vim command cheat list

My Vim Manual

Sorry Vim. I have used you many times, for a long time.
But I did not understand you deeply.
Now it is time to do it.

Help

  • Basic: :help
  • About Normal Mode: :help x
  • About Visual Mode: :help v_u
  • Grep: :helpgrep word

File open/close

  • Open new file: :e file_path
  • Save as a new file: :w file_path
  • open file with finding file. : :find file_path [enter] at directory. and search manually.

Moving page

  • Forward: Ctrl+]
  • Back: Ctrl+t or Ctrl+o
  • Enable mouse to jump: :set mouse=a => Enable mouse to jump for only xterm and GUI.

Moving cursor

  • N moving key, such as 3, j => Move 3 to buttom.
  • Top of line: ^
  • End of line: $
  • Middle of line: gm
  • Find and go to char position: N f{char}
  • Move to line N: N G, or :N (default last line)
  • Move to line N: N gg, or :N (default first line)
  • Word forward: N w
  • Word forward (blank skip): N W
  • Move to Middle of v lines: M
  • Move to Nth line from the buttom. : N L
  • Paging down: Ctrl+f
  • Paging up: Ctrl+b
  • Paging down (1/2 window): Ctrl+
  • Paging up (1/2 window): Ctrl+u
  • Current line at top of window. : zt
  • Current line at center of window. : zz
  • Current line at buttom of window. : zb

Inserting text

  • Insert to new line below N line of current line: o
  • Insert to new line above N line of current line: O
  • Insert the contents of [file]: :r [file]
  • Insert the contents of {command}: :r! {command}

Changing text

  • Change N words: c N w
  • Change N lines: [N] S

Replacing text

  • :s/{pattern}/{string}/[g][c]

Pattern Search

  • Repeat last search: /

Marks and motions

  • Do mark: m{a-zA-Z}

Below in the case of mark character: "a".

  • Move to mark: ma
  • Print marks lines: :marks

Tags

Print tag list: :tags

Moving page

  • Forward: Ctrl+]
  • Back: Ctrl+t

Key mapping

  • map {lhs} {rhs}: map {lhs} to {rhs} in Normal and Visual mode.
  • map! {lhs} {rhs}: map {lhs} to {rhs} in Insert and Command mode.

Split Window

windows.txt

vim -o file1 fileN
Open N files by N windows

vim -o2 file1 fileN
Open N files by 2 windows

  • Split: Ctrl+w, s or :split
  • Vertical Split: Ctrl+w, v or :vsplit
  • Split and New: Ctrl+w, n or :new
  • Virtically Split and New: :vnew
  • Split and View (read only) {file}: :sview {file}
  • List buffers: :ls
  • Delete buffer: :bd or :bw

http://stackoverflow.com/questions/1269648/how-do-i-close-a-single-buffer-out-of-many-in-vim

  • Move button: Ctrl+w, j
  • Move top: Ctrl+w, j
  • Move left: Ctrl+w, h
  • Move right: Ctrl+w, l
  • Move below/right: Ctrl+w, w
  • Move above/left: Ctrl+w, W
  • Rotate windows: Ctrl+w, r
  • Exchange current window with next one.: Ctrl+w, x

Window resizing

  • Equal: Ctrl+w, =
  • Smaller: Ctrl+w, [N]-
  • Bigger: Ctrl+w, [N]+
  • Change N lines of the window: Ctrl+w, [N]_

Argument and buffer list commands

  • :ls
  • :buffers
  • display number of buffer: :args
  • :bn or :bN
  • Open buffer N: :buffer N

Tab Page

  • New tab: :tabnew file_name
  • Next tab: gt
  • Prev tab: gT

http://d.hatena.ne.jp/m1204080/20101028/1288287527

Visual mode

later

Remove all ads