Content #
g_ 移动到当前行的最后一个非空字符上。 $ 移动到行尾,在visual mode下,会移动到最后一个字符的后面。
若光标在行首,使用"vg_“之后,再用"c"命令可修改当前行,但如果使用"v$“命令,再用"c"命令的话,当前行会被删除,下一行会顶上来,在输入结束后还得输入换行符。
An operator is a command that waits for you to enter a movement command, and then does something on the text between where you currently are and where the movement would take you. Some examples of operators are: d, y, c.
:onoremap p i(
在代码的函数参数中按dp,可删除所有参数。按cp会删除后进入插入模式。
:onoremap b /return<cr>
在函数体代码中按db,可删除从当前位置开始直到return所在位置之间的所有代码。
定义新的operator-pending movement的步骤如下:
:onoremap in( :<c-u>normal! f(vi(<cr>
“<c-u>”: remove the range that Vim may insert. “normal!”: simulate pressing keys in normal mode. “<cr>”: executes the :normal! command. 按下cin(,会删除当前行的小括号中的内容,并进入插入模式。
...Vim会为每个autocmd创建auto command,无法区分这些autocmd的功能是否为重复的。像下面的autocmd:
autocmd BufWrite * :sleep 200m
每次source后都会增加延迟。
不同的位置定义同名的autocommand group:
augroup testgroup
autocmd BufWrite * :echom "Foo"
autocmd BufWrite * :echom "Bar"
augroup END
...
augroup testgroup
autocmd BufWrite * :echom "Baz"
augroup END
Vim会将多个autocmd自动组合在一起。如果要避免重复,可以在group中清除原先的group的内容。
augroup testgroup
autocmd!
autocmd BufWrite * :echom "Cats"
augroup END
:help autocmd-groups
autocmd一般结构如下:
:autocmd BufNewFile * :write
“BufNewFile” - the event to watch for “*” - a pattern to filter the event “:wrtie” - the command to run
结合buffer-local abbreviation和autocmd:
:autocmd FileType python :iabbrev <buffer> iff if:<left>
:autocmd FileType javascript :iabbrev <buffer> iff if ()<left>
查看所有autocmd事件:
:help autocmd-events
Vim will substitute an abbreviation when you type any “non-keyword character” after an abbreviation. “Non-keyword character” means any character not in the iskeyword option.
Run this command:
:set iskeyword?
You should see something like iskeyword=@,48-57,_,192-255. This format is very complicated, but in essence it means that all of the following are considered “keyword characters”:
• The underscore character (_). • All alphabetic ASCII characters, both upper and lower case, and their accented versions. • Any characters with an ASCII value between 48 and 57 (the digits zero through nine). • Any characters with an ASCII value between 192 and 255 (some special ASCII characters).
...Nonrecursive Mapping Keyword Characters Abbreviations与Mappings的区别 Buffer-Local Mappings and Options autocmd structure Autocommand Groups Operator-Pending Mappings execute与normal! 两个移动到行尾命令的区别 gi与g; Variables and Options Coercion of Strings to Integers Explicit Case Sensitive or Insensitive Comparisons Function Varargs Always use normal! 脚本中使用<c-u>的含义 Magic and Literal Strings and Very Magic Paths in Vim Folding Theory visual模式下用gv命令恢复选择区域 Especially Useful Help Topics global命令