LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 794|回复: 3

vim中把用正则表达式匹配的字符串写到一个新文件的方法

[复制链接]
发表于 2006-9-27 13:36:23 | 显示全部楼层 |阅读模式
redirect selected parts to a new file
1:  :g/patten/y A   Append to the
                     contents of the register if its name is given
                     uppercase {A-Z}
     create a file in vim
     "ap
2:delete unwanted lines
     :g/^[^0-9]\+\n/d
3:   :redir >> tmp
     :g/^\d\+/p
     :redir END
  "send output of previous global command to a new window
     :nmap <F5>  :redir @a<CR>:g//<CR>:redir END<CR>:new<CR>: put! a<CR><CR>
发表于 2006-9-27 18:40:15 | 显示全部楼层
太复杂,记不住
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-27 22:01:33 | 显示全部楼层
map <F5> :redir @a<CR>:g//<CR>:redir END<CR>:new<CR>: put! a<CR><CR>
把上面一行保存在/etc/vim/vimrc.local或者~/.vimrc中.
使用方法是:
用vim打开文档.
:g/regular expression/p
然后按F5键.

很简单吧, 前提是你会使用regular expression正则表达式. 有一本书专门介绍它的, 网上有电子版, 找找吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-27 22:03:04 | 显示全部楼层
第一贴是三种方法实现这个功能, 不要弄混了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表