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 
-
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章