practical-vim 讀書筆記

vim command:
Normal Mode
. repeat j.
; repeat f{char} , back f{char}
cw db dw
<C-a> <C-x>
gU gu uppercase and lowercase
<< and >> intend shift
~ 大小寫一個字符,光標再後移一位
Insert Mode
<C-h> 向前刪除一個字符(backspace)
<C-w> 向前刪除一個單詞(空格或其他符號隔開)
<C-u>
<Esc> and <C-[> 回到normal mode
<C-o> Insert Normal mode  <C-o>zz
<C-r>0 paste <C-r>{register} <C-r>=
<C-v>{code} input unusual characters ga
<C-k> digraph :h digraphgs-default
gR virtual replace
Visual Mode
v and V <C-v> gv  最後一次選擇塊 o Go to the end of highlighted text
:normal . or :normal @q
set shiftwidth=4 softtapstop=4 expandtap
U Uppercase select characters
Command-Line Mode
:d :y
:{start},{end}
:% all
:/pattern/,/pattern/
:[range]copy{address} 簡寫:t :co
:[range]move{address} 簡寫:m
:!sort -t',' -k2 分隔符-t'' -k2 表示第二塊也要參與排序
:read !{cmd} 插入shell命令的標準輸出
:[range]write !{cmd} 將[range]部分作爲shell命令的標準輸入
第二部分 文件
    :'<,'>m$ 將選擇的塊移動到文件結尾
:'<,'>normal. 對每一行做normlal mode . 命令 normal 表示可以在後面接上所有normal mode  命令。
@: 表示重複最後一條命令行模式的命令。
<C-r><C-w> 複製光標的單詞到命令行
:helptags ~/.vim/doc 生成幫助標籤
:bdelete N1 N2 N3
:N,M bdelete  刪除緩存文件 簡寫:bd
:args 命令將文件名作爲參數,shell 命令的輸出
<C-w>s and <C-w>v 將窗口水平分割和垂直分割 :edit {filename}後面加這條命令
:sp {} :vs {}
:cl <C-w>c 關閉活動窗口 :on[ly] <C-w>o 保持活動窗口,關閉其他窗口
:h window-resize 調節窗口大小的命令
<C-w>= Equalize width and height of all windows
<C-w>_ Maximize height of the active window
<C-w>| Maximize width of the active window
[N]<C-w>_ Set active window height to [N] rows
[N]<C-w>| Set active window width to [N] columns
如何使用Tabs
    :tabe[dit] {filename} 在新的標籤中打開{filename}
    <C-w>T 將當前窗口移動到新標籤
    :tabc[lose]
    :tabo[nly]
   切換標籤
    :tabn[ext] {N} {N}gt Switch to tab page number {N}
    :tabn[ext] gt Switch to the next tab page
    :tabp[revious] gT Switch to the previous tab page
:edit %:h or :edit %%
:find 命令 首先要配置'path' set: path+=
第三部分 更快地跳轉 
:h motion.txt  motions 的作用
gj and gk 在顯示行移動
ge 移動到前一個單詞的結尾
word 和 WORD 的不同 簡單說就是WORD 比 word 大
w e b ge 和 W E B gE
f{char} t{char}
Text Objects :h text-objects
    i or a 開頭 i可記爲inside a可記爲around
    ab or a)
    aB or a}
    at    A pair of <xml>tags</xml>
    it    Inside of <xml>tags</xml>
    d{motion} 與aw,as,ap最搭配,c{motion} 與iw
打標記 mark
m{a-zA-Z} 命令 `{mark} 跳轉到標記
% 在各種括號之間跳轉,`` 會跳上一個括號位置
    matchit.vim 插件會增強%命令的功能,詳情:h matchit-install
    runtime macros/matchit.vim
在文件之間跳轉
    <C-o> 和 <C-i>
    :jumps 查看跳轉歷史
第四部分 寄存器
  複製和粘貼
    xp 交換後面的兩個字符
    ddp 交換後面的兩行
    P 在光標之前的位置粘貼
    "_d{motion} performs a true deletion. _寄存器是黑洞寄存器
    :delete c :put c
    "+p or <C-r>+ 從外面粘貼到vim
    交換兩個單詞
    de mm WW ve p `m P
    gp 和 gP 可以將光標跳轉到粘貼的後面
    宏
        q 命令 和@ 命令
    使用 qq;.q 命令可重複 .命令 [N]@q
    使用f 和 t 命令若出錯,則宏命令停止執行
    使用visual mode 並行執行宏命令
    使用大寫的寄存器名字,在寄存器後面增加內容
    使用:argdo 命令對多個文件操作
    let i=1 變量 <C-r>=i
    可以對寄存器中的任意位置的值修改
第五部分 模式
   模式開關 
    \c and \C 表示的大小寫忽略
    \v 模式開關 詳情見:h \v 
    \x 表示十六進制的表示符號 :h /character-classes
    \V verynomagic literal 開關 
    使用括號 得到子匹配
    /\v<(\w+)\_s+\1> 匹配所有接連的相同單詞
    \v<word> 只匹配word \w 匹配所有單詞 \W 匹配所有除了單詞之外的東西。
    匹配的界限
        \zs and \ze  見:h /\zs 
    使用反斜線和?
        escape({string}, {chars}) 見:h escape()
    <C-r>=escape(@{寄存器}, getcmdtype().'\') 見:h getcmdtype()
    搜索
    /<C-r><C-w> 搜索光標的單詞
    /{word}/e 光標停在搜索到的單詞尾部
    \1 表示搜到的
    在visual mode 中,*表示搜索光標的單詞
    substitute 命令 搜索替換
  :[range]s[ubstitute]/{pattern}/{string}/[flags]  
    \r Insert a carriage return
    \t Insert a tab character
    \\ Insert a single backslash
    \1 Insert the first submatch
    \2 Insert the second submatch (and so on, up to \9 )
    \0 Insert the entire matched pattern
    & Insert the entire matched pattern
    ~ Use {string} from the previous invocation of :substitute
    \={Vim script} Evaluate {Vim script} expression; use result as replacement {string}
  在替代命令中做計算
    submatch(0) h: submatch()
  對所有文件做替換操作
  :argdo %s 命令
  Global 命令
  :global see :h g
  [range] global[!] /{pattern}/ [cmd]
  :g  :v
  :sort 排序

使用工具
  ctags
    sudo apt-get install exuberant-ctags
    <C-]> 和g<C-]> 跳轉到光標的定義位置 <C-t> 回跳
    :tselect or :tnext  :tprev :tfirst :tlast ,]b [b [B ]B
    :tag {keyword} or :tjump {keyword}
    :tag /{pattern} or :tjump /{pattern} 
  vimgrep or grep  
    :vim[grep][!] /{pattern}/[g][j] {file} ...

  :set spell 檢查拼寫錯誤
    [s ]s z=
    zg 將此單詞加入spell file
    zw 將單詞移除spell file
    zug revert zg or zw 操作
    在insert mode <C-x>s

在選項後面加上 ! 反向 加上? 查看選項值 加上&恢復爲默認值
tabstop tab字符的列數 ts 
-
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章