Vim 基本设置
2009-11-19 21:08
218 查看
在Linux下面开发,Vim是首选工具。但是系统默认安装的VIM,通常没有将一些常规设置配好。如:彩显,高亮,自动缩进,自动记忆,TAB步长等。这就给使用者造成很多不便,本人将就这些问题,分享一下自己的实际经验。
要想得到一个好用的VIM,我们首先要安装完整版的VIM。
sudo apt-get install vim-full
安装好后,我们可以继续往下走。
接下来的设置,完全针对VIM的配置文件 /
etc/vim/vimrc
.
打开这个文件,你会发现有很多有用的功能,默认被屏蔽掉了,你要做的就是打开这些功能
1. Vim
中语法彩色显示
" Vim5 and later versions support syntax highlighting.
Uncommenting the next
" line enables syntax highlighting by
default.
syntax on
2. VIM 自动缩进
" Uncomment the following to have Vim load indentation rules
according to the
" detected filetype. Per default Debian Vim only load
filetype specific
" plugins.
if has("autocmd")
filetype indent on
endif
3. VIM自动记忆上一次文件打开的位置
" Uncomment the following to have Vim jump to the last
position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'/"") > 0 &&
line("'/"") <= line("$")
/| exe "normal! g'/"" | endif
endif
打开这个设置后,发现
VIM的位置记忆功能并没有工作。我用
sudo方式打开文件后,发现
VIM是可以工作的。 到网上查了一下,终于搞清楚怎么回事。原来,这个功能是依赖于用户目录下
(/home/<user>/)的
.viminfo文件,这个文件默认权限是不可写。于是更改了该文件的权限:
sudo chmod 666 ~/.viminfo
好,现在可以正常工作了。
4. 其他
设置 TAB步长, 在vimrc 添加一句 “set ts=<n>"
在
scratchbox环境下,
vim
配置文件路径:
/scratchbox/tools/share/vim/vimrc
要想得到一个好用的VIM,我们首先要安装完整版的VIM。
sudo apt-get install vim-full
安装好后,我们可以继续往下走。
接下来的设置,完全针对VIM的配置文件 /
etc/vim/vimrc
.
打开这个文件,你会发现有很多有用的功能,默认被屏蔽掉了,你要做的就是打开这些功能
1. Vim
中语法彩色显示
" Vim5 and later versions support syntax highlighting.
Uncommenting the next
" line enables syntax highlighting by
default.
syntax on
2. VIM 自动缩进
" Uncomment the following to have Vim load indentation rules
according to the
" detected filetype. Per default Debian Vim only load
filetype specific
" plugins.
if has("autocmd")
filetype indent on
endif
3. VIM自动记忆上一次文件打开的位置
" Uncomment the following to have Vim jump to the last
position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'/"") > 0 &&
line("'/"") <= line("$")
/| exe "normal! g'/"" | endif
endif
打开这个设置后,发现
VIM的位置记忆功能并没有工作。我用
sudo方式打开文件后,发现
VIM是可以工作的。 到网上查了一下,终于搞清楚怎么回事。原来,这个功能是依赖于用户目录下
(/home/<user>/)的
.viminfo文件,这个文件默认权限是不可写。于是更改了该文件的权限:
sudo chmod 666 ~/.viminfo
好,现在可以正常工作了。
4. 其他
设置 TAB步长, 在vimrc 添加一句 “set ts=<n>"
在
scratchbox环境下,
vim
配置文件路径:
/scratchbox/tools/share/vim/vimrc