Vim コマンド

Vim コマンド カンニング用

Normal mode

  • * search word
  • n next search word
  • . repeart
  • vitu vs guit (replace Uppercase to lowercase)
  • dip p is Paragraph

  • dis s is sentence

  • m{a-zA-A} as mark lowcase is this file Uppecase is global

  • `{a-zA-A} as mark lowcase is this file Uppecase is global

  • :jumps

  • o previous

  • i next

  • :changes

  • g; previous chane list

  • g, next change list

  • `. latest change point

  • ^. latest insert point

  • gf jump file

  • [ previous

  • ] next

  • _d{motion} black hall rgister

  • ad{motion} ap{motion} ap use “a” register

  • “+p paste clip board

  • “%p current file name

  • ”%# altanative file name

  • “.p latest insert text

  • “:p latest exec command

  • ”/ latest search word

  • q{register} Start macro

  • q end macro

  • visual mode + “normal @a ” paralel exec

  • :argsdo normal @a paralel exec

  • /a.k.a. b{ackwoar}d a.k.a

  • /a.k.a. a.k.a

  • /\Va.k.a. a.k.a

  • /\V(%(And|D)rew) (Neil) register 1 = andrew or drew , register 2 = Neil

  • :%s//\2, \1/g

  • :%s/before/after first mach

  • :%s/before/after/g in line

  • :%%s/before/after/g global

  • :%%s/before/after/gc global and prompt

  • / latest serch word

  • :%%s/r//after/gc global and prompt

  • /\V(|)

  • :%%s//={“dog”:“man”,“man”:“dog”}[sub-match(1)]/g

  • :grep word * make quick list

  • :cnext / :cprev jump to source

  • :vim /r// ** vimgrep

Global command

// Delete html tag

  • /\v</?\w+>
  • :g//d

// delete donsn’t contain href

  • :v/href/d

  • :g/word display lines contain word

  • :g/word/yank A lines contain word regist register A(uppercase is append, lowercase is over write)

  • :g/word/t$ Paste buttom line contain word

Insert mode

  • r 0 paste register 0
  • r -p {registar} past register
  • r = calc
  • gv latest selected area
  • h delete left char
  • w delete left word
  • u delete to line first
  • 0 onetime normal mode
  • r+ paste clip board

Visual mode

  • o toggle cursol in selected area
  • gu lowwer case
  • gU upper case
  • : command for selected area
  • S’ Sorround vim
  • S” Sorround vim
  • S[ Sorround vim
  • cs”’ Sorround vim change ’ to ”

Command mode

  • /pattern search for forward

  • ?pattern search for backward

  • :s/target/replacer replace

  • :s/target/replacer/g replace global

  • :[range]delete [x] to register

  • :[range]yank [x] to register

  • :[range]put [x] to register

  • :[range]copy [address]

  • :[range]t [address] equal copy

  • :[range]move [address]

  • :[range]m[address] equal move

  • :[range]join

  • :[range]normal {command}

  • :[range]substitute/{Pattern}/{string}/[flag] replace word first word

  • :[range]global/{pattern}/[cmd] replace global

  • :1 to head

  • :$ to bottom

  • :3p to line numbe 3 and print

  • :2.5p print between line number 2 to 5

  • :%s//rw/g Replace

  • rw is select word to comman window

  • ra is select WORD to comman window

  • r0 paste register 0 to command window

  • q: history

  • :2,$!sort -t ’,’ -k2 sort for selected area

  • :e shell

  • :!{cmd} :l

  • :[rang]!{filter}

  • :bd buffer delete

  • :%% active path

  • :cd %%

  • :lcd %%

  • :!mkdir -p %%

Pattern

/#\([0-9a-fA-F]\{6}\|[0-9a-fA-F]\{3}\)
/#\([0-9a-fA-F]\{6}\)
↓
/\v#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
/\v#([0-9a-fA-F]{6})
↓
/\v#(\x{6}|\x{3})

重複

/\v<(\w+)\_s+\1>
* \_s は空白文字 改行文字

境界

/\vthe
↓
/\v<the>

入れ替え

/\v(%(And|D)rew) (Neil)
%s//\2, \1/g

強調表示の絞り込み

* ""の中を強調表示
/\v"\zs[^"]+\ze"

カーソル上の単語をコマンドラインへ

<C-r><C-w>

Match Count

:%s///gn

単語の末尾へ

/word/e

単語の末尾へ変更

//e

シングルコーテーション内選択

/\v'([^']|'\w)+'
/\v'(([^']|'\w)+)'

ダブルコーテーションへ変更

:%s//"\1"/g

統合

:%s/\v'(([^']|'\w)+)'/"\1"/g

確認

:%s/\v'(([^']|'\w)+)'/"\1"/gc

h2, h3, h4 -> h1, h2, h3

/\v\<\/?h\zs\d
:%s//\=submatch(0)-1/g

複数ワード入れ替え

/\v(<man>|<dog>)
%s//\={"dog":"man","man":"dog"}[submatch(1)]/g
Plugin abolish
:%S/{man,dog}/{dog,man}/g

Buffer 全部に実行

*Pragmatic Vim <- 対象
*Pragmatic bookshelf  <- 非対称

/Pragmatic\ze Vim
:vimgrep /<C-r>// **/*.txt
:argsdo %s//Practical/ge

Quickfix に実行

:cdo

ファイルなの{}内のソート

:g/{/ .+1,/}/-1 sort

Nerdtree

  • ” File node mappings~
  • ” double-click,
  • ” o: open in prev window
  • ” go: preview
  • ” t: open in new tab
  • ” T: open in new tab silently
  • ” middle-click,
  • ” i: open split
  • ” gi: preview split
  • ” s: open vsplit
  • ” gs: preview vsplit
  • : custom open
  • ” ----------------------------
  • ” Directory node mappings~
  • ” double-click,
  • ” o: open & close node
  • ” O: recursively open node
  • ” t: open in new tab
  • ” T: open in new tab silently
  • : custom open
  • ” x: close parent of node
  • ” X: close all child nodes of
  • ” current node recursively
  • ” middle-click,
  • ” e: explore selected dir
  • ” ----------------------------
  • ” Bookmark table mappings~
  • ” double-click,
  • ” o: open bookmark
  • ” go: preview file
  • ” go: find dir in tree
  • ” t: open in new tab
  • ” T: open in new tab silently
  • ” i: open split
  • ” gi: preview split
  • ” s: open vsplit
  • ” gs: preview vsplit
  • : custom open
  • ” D: delete bookmark
  • ” ----------------------------
  • ” Tree navigation mappings~
  • ” P: go to root
  • ” p: go to parent
  • ” K: go to first child
  • ” J: go to last child
  • : go to next sibling
  • : go to prev sibling
  • ” ----------------------------
  • ” Filesystem mappings~
  • ” C: change tree root to the
  • ” selected dir
  • ” u: move tree root up a dir
  • ” U: move tree root up a dir
  • ” but leave old root open
  • ” r: refresh cursor dir
  • ” R: refresh current root
  • ” m: Show menu
  • ” cd:change the CWD to the
  • ” selected dir
  • ” CD:change tree root to CWD
  • ” ----------------------------
  • ” Tree filtering mappings~
  • ” I: hidden files (off)
  • ” f: file filters (on)
  • ” F: files (on)
  • ” B: bookmarks (on)
  • ” ----------------------------
  • ” Custom mappings~
  • ” ----------------------------
  • ” Other mappings~
  • ” q: Close the NERDTree window
  • ” A: Zoom (maximize-minimize)
  • ” the NERDTree window
  • ” ?: toggle help
  • ” ----------------------------
  • ” Bookmark commands~
  • ” :Bookmark []
  • ” :BookmarkToRoot
  • ” :RevealBookmark
  • ” :OpenBookmark
  • ” :ClearBookmarks []
  • ” :ClearAllBookmarks
  • ” :ReadBookmarks
  • ” :WriteBookmarks
  • ” :EditBookmarks

おっさんWEBエンジニア奮闘記©2007 WEBDIMENSION