lastbuf.vim 撤销最后关闭的buffer
登陆 Awesome WM

vim tips

Rykka posted @ 2011年12月03日 11:26 in archlinux with tags vim , 4057 阅读

1.delimiter in :s :g :v  Tip 406
 :s+/usr+/usr/local+
 :s#/usr#/usr/local#

代替:s/\/usr/\/usr\/local/

2.range in :s :g :v Tip 1611

可以用search

:/this/,/that/s/this/that/

‘;’会在运行中将cursor移动过去,而‘,’不会移动cursor

:1,+1 与:1;+1

3. 给当前文件加入行号

:%s/^/\=line('.').' '/

如果要使行号整齐,

可以用

:%s/^/\=line('.')."\t"/

或者

:%s/^/\=printf("% 4d ",line('.'))/ 

4. string "" 和 literal string ''

string里的"\"和'"'需要用"\"转义,

literal string 里的 "'"需要 用 "''"转义

"\"" == '"'

"\\" == '\'

"'"  == ''''

在literal string里可以用 <Ctrl-Q>{press} 来输入特殊字符

与 "\<press>" 相同

即 "\<C-W>" 与 '' 里直接输入的特殊字符相同。

 

5. '[[:graph:]]' 和 '[!-~]' 和 '[\d33-\d126]' 等价

可以通过这个脚本来验证

for i in range(3,226)
    let oi = printf("%o",i)
    exe "let oi = " . "\"\\". oi . "\""
    echo i ':' oi oi =~ '[[:graph:]]' oi =~ '[!-~]' oi =~ '[\d33-\d126]'
endfor


6. 使用regiser重复相似的工作。

let @a = "$"
let @b = "la\<c-r>a\<esc>"
let @c = "20@b"

那么在source了这段脚本后,'@c' 则会重复20次插入@a的字符 '$'

要改变插入字符,只需要改变@a

更深入的话,可以插入表达式

比如'@c'给每行插入行号


let @a = "printf('% 4d ',line('.'))"
let @b = "I\<c-r>=\<c-r>a\<CR>\<esc>j"
let @c = "gg999@b"


 

 

 

 

 

 

Avatar_small
依云 说:
2011年12月21日 14:10

http://tip.vim-cn.com/


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter