Vi 基本操作指南

常用操作命令

功能 快捷键
左移一个字符 h
下移一行 j
上移一行 k
右移一个字符 l
光标跳到文件首 gg
光标跳到文件末尾 shift-g
undo u
redo ...
删除一行 dd
删除一段 先 v 选中,然后 d
拷贝/删除 先 v 选中需要拷贝的文本,,然后 y 拷贝,最后 p 粘贴
搜索 /word, 按 n 搜下一个
替换 :g/oldword/s//newword/gc
读入一个文件 :r filename

tags

  • 打 tag 命令: ctags -R
  • 在 vim 配置文件 vimrc 中增加配置项:
set tags+=/home/liupeng/devel/dev-2-2/tags
set tags+=/usr/include/tags
  • 查找某个关键字(变量/函数 ): ctrl-] , 若想跳回来 ctrl-t

csope 的使用

  • .vimrc 配置
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
cscope add /home/liupeng/devel/dev-2-2/cscope.out /home/liupeng/devel/dev-2-2
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
"map accelerate key.
nmap ts :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap tg :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap tc :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap tt :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap te :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap tf :cs find f <C-R>=expand("<cfile>")<CR><CR>

  • 对源代码建索引
    cscope -Rbq
  • 命令
    • cs find s name: 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
    • cs find g name: 查找函数、宏、枚举等定义的位置
    • cs find c name: 查找调用本函数的函数
  • SeeAlso:

终端/vim 背景色和文字颜色的修改

  • 打开终端菜单:edit/profile
  • 在 general 标签中设定字体:Nimbus Mono L/Bold/10
  • 在 colors 标签中,从 foreground and backgroud 部分修改文本颜色和背景色;从 palette 部分修改 Built-in scheme 为 XTerm

See Also

* Beginner's Guide to the Vi editor

foot bar