对每行添加
1. under visual mode 2. : normal <command>
VIM: 命令
:e some_path # 打开文件并写 :r !some_command # 读取命令的输出 :% TOhtml<cr> #打印html :qa 全部窗口
批量操作
vim * qa {Micro} q :argdo normal @a :qa 或者 vim *.cpp # Start Vim, defining the argument list to # contain all the C++ files. You are now in the # first file. qq # Start recording into the q register :%s/\<GetResp\>/GetAnswer/ge # Do the replacements in the first file. :wnext # Write this file and move to the next one. q # Stop recording. @q # Execute the q register. This will replay the # substitution and ":wnext". You can verify # that this doesn't produce an error message. 999@q # Execute the q register on the remaining files.
光标退回
c-o
Ctags
c-]
c-t
VIM windows
C-w + v:vsplit
c-w + o:only
c-w + r:rotate
c-w + T:put to new windows
切换大小写
~:交换
gu: lowercase
gU: uppercase
visual:U 全部大写
滚动屏幕
c-y && c-e
##转换HTML
ToHTML
多文件编辑
args *.txt 打开文件进入buffer
标记
mx:打标记x
'x:跳往标记x
#'a - 'z lowercase marks, valid within one file
#'A - 'Z uppercase marks, also called file marks, valid between files
#'0 - '9 numbered marks, set from .viminfo file
'0返回上次
宏
修改宏 G Go to the end of the file. o<Esc> Create an empty line. "np Put the text from the n register. You now see the commands you typed as text in the file. {edits} Change the commands that were wrong. This is just like editing text. 0 Go to the start of the line. "ny$ Yank the corrected commands into the n register. dd Delete the scratch line. 追加宏(使用大写字母) qC/word<Enter>q
替换
:[range]substitute/from/to/[flags]
range=%: 所有行eg :%s/Professor/Teacher/
flags=g: 替换每行的所有个,否则只替换每行的第一个
:1,5s/this/that/g 从第一行到第五行
:.,.+4 相对行
:.write otherfile 只写当前行
:.,$s/yes/no/ 从开头到结尾
:%s/\<four\>/4/g 单词边界
替换执行
:[range]global/{pattern}/{command} :g+//+s/foobar/barfoo/g # This starts with ":g". That is short for ":global", just like ":s" is short # for ":substitute". Then the pattern, enclosed in plus characters. Since the # pattern we are looking for contains a slash, this uses the plus character to # separate the pattern. Next comes the substitute command that changes "foobar" # into "barfoo".
读入外部程序的output
read !ls
悬挂
c-z
fg 恢复
外部程序读与写
:!{program} execute {program}
:r !{program} execute {program} and read its output
:w !{program} execute {program} and send text to its input
session
:mksession vimbook.vim
:source vimbook.vim
读入外部path
:set path+=c:/prog/include
隐藏更新编辑
:hide edit two.txt
数字自增加
c-a
3 c-a 增加三
c-x 减少
外部程序模式
#The Ex mode commands you need are as follows: > %s/-person-/Jones/g write tempfile quit #You put these commands in the file "change.vim". Now to run the editor in #batch mode, use this shell script: > for file in *.txt; do vim -e -s $file < change.vim lpr -r tempfile done #The for-done loop is a shell construct to repeat the two lines in between, #while the $file variable is set to a different file name each time. #The second line runs the Vim editor in Ex mode (-e argument) on the file #$file and reads commands from the file "change.vim". The -s argument tells #Vim to operate in silent mode. In other words, do not keep outputting the #:prompt, or any other prompt for that matter. #The "lpr -r tempfile" command prints the resulting "tempfile" and deletes #it (that's what the -r argument does).
删除一段
dip d} da}
倒置行
:g/^/m0
复制
" copy everthing to text
noremap <leader>cp :%y+<CR>
块移动
><
块执行
vmode+ <S-:>
文件类型
echo &filetype
撤销
Ctr-r