vimrc:Vim initializations
2013-06-21
启动vim时,~/.vimrc文件会被自动读取,该文件可以包含一些设置甚至脚本.
1、The vimrc file contains optional runtime configuration settings to initialize Vim when it starts. On Unix based systems, the file is named .vimrc, while on Windows systems it is named _vimrc.
2、Location of vimrc
These commands are useful to see what directories your Vim is using:
:version
:echo expand('~')
:echo $HOME
:echo $VIM
:echo $VIMRUNTIME
/etc/vimrc
~/.vimrc
3、Opening vimrc
:e $MYVIMRC
:e $MYGVIMRC
you could type :e $M then press Tab until you see the desired variable.
4、Sourcing vimrc
:so $MYVIMRC
" Alternative that can be used if vimrc is the current file:
:so %
5、注释:
“开头
6、字符模式
~ 普通、可视、选择和操作符等待
n 普通
v 可视和选择
s 选择
x 可视
o 操作符等待
! 插入和命令行
i 插入
l 插入、命令行和 Lang-Arg 模式的 ":lmap" 映射
c 命令行
7、map相关
map
map td :tabnew .输入td等价于输入 :tabnew . 。
nmap nmap是:map的普通模式板,也就是说其绑定的键只作用于普通模式
noremap 和:map命令相对,作用模式和命令格式都相同
noremap ts td是和:map不同的是,此时td再不会做进一步扫描解释
unmap
unmap是对应取消:map绑定的{lhs},作用模式相同,命令格式 :unmap {lhs}。
inoremap
mapclear时对应取消所有:map绑定的,慎用!
7、vimrc自动补全实例
:inoremap ( ()i
:inoremap ) =ClosePair(')'):inoremap { {}O
:inoremap } =ClosePair('}'):inoremap [ []i
:inoremap ] =ClosePair(']'):inoremap " ""i
:inoremap ' ''i
8、Ctrl+V粘贴
inoremap :set pastemui+mv'uV'v=:set nopaste
9、自动缩进4个字符
set cindent shiftwidth=4
set smartindent
10、encode&lang
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set langmenu=zh_CN.UTF-8
set helplang=cn
11、map实例
nmap dk d$
12、函数实例
map :call CompileRunGcc()
func! CompileRunGcc()
exec "w"
exec "!gcc % -o % :call CompileRunGpp()
func! CompileRunGpp()
exec "w"
exec "!g++ % -o %#
13、filetype plugin indent on
文件类型探测
使用文件类型相关的插件
自动缩进功能
14、set tags=/usr/share/vim70/tags
使用标签(tag),文件可以在vim查看函数调用关系,类、结构、宏等的定义,可以在任意标签中跳转、返回....
Tag文件中保存了诸如函数、类、结构、宏等的名字
分类:Linux | 标签: vi |
相关日志