vim Diffsplit Mark Regexp Copy & Paste Highlight Search & Rplace

Resize windows

command :reseze / :res

To set window height to 60

:resize 60 

To change the height by increments of 5

:res +5
:res -5

To change window width :vertical resize

:vertical resize 80
:vertical resize +5
:vertical resize -5

key C-w ...

  • C-w + / C-w - : height +1 / -1 row
  • C-w < / C-w > : width +1 / -1 column

Split window

  • C-w s / C-w v : split window horizontal / vertical
  • :split/sp [path] / :vsplit/vs [path] : split window horizontal / vertical and open a file optional

Delete window

  • C-w o / C-w C-o : will delete all other windows

Move between windows

  • C-w <ARROW> : will move to windows pointed to

Diffsplit

  • set diffopt+=iwhite : ignore white space
  • do : copy from other window
  • dp : copy to other window
  • ]c : 次の差分へ移動
  • [c : 前の差分へ移動

Mark

Normal operations

  • Each file can have mark a –– use a lowercase mark to jump within a file.
  • There is only one file mark A –– use an uppercase mark to jump between files.

Regexp

vim正規表現リファレンス

Copy & Paste

  1. y (yank) d (delete) c (change) すると、その文字列は無名レジスタに蓄えられます。
  2. "ayy とか "bdw とすると、明示的に a レジスタや b レジスタに書き込みます。
  3. 明示的にレジスタを指定して貼り付ける時は "ap"bP などとします。

レジスタを表示

  • :di
  • :reg

0 レジスタ

  1. y -> 内容1を無名レジスタに格納
  2. d -> 内容2を無名レジスタに格納、もともと無名レジスタに格納していた内容1を0レジスタに退避
  3. d -> 内容3を無名レジスタに格納、もともと無名レジスタに格納していた内容2を0レジスタに退避 しない

これで、yした内容を"0pで貼り付けできる
dを実行時は、無名レジスタ退避しない

Highlight

色がなくなったとき

set filetype=c

Search & Rplace

vim wiki

When searching:

  • ., *, , [, ^, and $ are metacharacters.
  • +, ?, |, &, {, (, and ) must be escaped to use their special function.
  • / is / (use backslash + forward slash to search for forward slash)
  • t is tab, s is whitespace (space or tab)
  • n is newline, r is CR (carriage return = Ctrl-M = ^M)
  • {#} is used for repetition. /foo.{2} will match foo and the two following characters. The is not required on the closing } so /foo.{2} will do the same thing.
  • (foo) makes a backreference to foo. Parenthesis without escapes are literally matched. Here the is required for the closing ).

When replacing:

  • r is newline, n is a null byte (0x00).
  • & is ampersand (& is the text that matches the search pattern).