vim使用笔记
********************************************************************************
----1----一般模式下按shift+Z+Z,相当于:wq
********************************************************************************
----2----VIM实现插入递增数字比如想将第11行至17行的a修改成a1,a2,a3.可以这样子做
: let i = 1 | 11,17g/\<a\>/s//\=i/ | let i+=1
:help :g 可以查看g命令的帮助
:[range]g[lobal]/{pattern}/[cmd] ()
Execute the Ex command [cmd] (default ":p") on thelines within [range] where {pattern} matches.
h: :s
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
For each line in [range] replace a match of {pattern}
with {string}.
When the {string} starts with "\=" it is evaluated as an expression, see
|sub-replace-expression|. You can use that for any special characters.
在执行一次查找操作后,Vim会记住本次所使用的模式(pattern)和偏移量(±nlines)。下一次使用时,只需要指定查找的方向(和/或新的偏移量)即可。
h: :/
/{pattern}[/] the next line where {pattern} matches *:/*
\/ the next line where the previously used search
pattern matches
/{pattern} 正向查找指定模式pattern
/ 使用上一次模式和偏移模式进行正向查找,即当匹配模式为空时,表示以上一次匹配成功的模式
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
For each line in [range] replace a match of {pattern}
with {string}.
When the {string} starts with "\=" it is evaluated as an expression, see
|sub-replace-expression|. You can use that for any special characters.
在执行一次查找操作后,Vim会记住本次所使用的模式(pattern)和偏移量(±nlines)。下一次使用时,只需要指定查找的方向(和/或新的偏移量)即可。
h: :/
/{pattern}[/] the next line where {pattern} matches *:/*
\/ the next line where the previously used search
pattern matches
/{pattern} 正向查找指定模式pattern
/ 使用上一次模式和偏移模式进行正向查找,即当匹配模式为空时,表示以上一次匹配成功的模式
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
For each line in [range] replace a match of {pattern}
with {string}.
When the {string} starts with "\=" it is evaluated as an expression, see
|sub-replace-expression|. You can use that for any special characters.
********************************************************************************
----3----VIM在.c文件跳转到头文件,打开相应的头文件 光标移到头文件上:gf
便可以打开相应的头文件了
ctrl+o
便返回到.c文件
********************************************************************************
----4----、VIM多标签切换:tabnew [++opt选项] [+cmd] 文件 建立对指定文件新的tab
:tabc 关闭当前的tab
:tabo 关闭所有其他的tab
标准模式下:
gt , gT 可以直接在各个tab之间切换。
********************************************************************************
----4----vim多窗口:new默认就是打开一个水平分割的新窗口。另外一个命令就是:split
垂直分割了,命令是:vsplit
直接连续按两次ctrl+w组合键,vim会自动跳到下一个窗口
或者通过组合键ctrl+w,然后通过j/k,来定位窗口
********************************************************************************
将多个空格替换成一个空格
正则表达式中:* 表示 匹配0或多个正好在它之前的那个字符
:%s/ * / /g
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
资料收藏