Skip to content

折腾vim

2010 五月 2
tags: , , ,
by 荒野无灯

最首先我只安装了vim 7.2 (sudo apt-get install vim) ,后来发现还是有必要安装一下 vim-gnome .
于是

1
sudo apt-get install vim-gnome

,这样以后,发现从shell中启动gvim会出错,解决方法:
编辑 ~/.bashrc ,加入

1
2
  #解决gvim  Gtk-WARNING **: Invalid input string  问题
  export LANG="zh_CN.UTF-8"

让修改马上生效:

1
source ~/.bashrc

由于我主要是用vim来写php ,因此这里按PHP程序员的配置来折腾vim .

1
2
cd /etc/vim
vim vimrc.local

这里的vimrc.local文件是由vimrc调用的,我们不直接修改vimrc,而是新建一个名为vimrc.local的文件,然后,开始折腾吧。
vi 兼容模式(原始的 vi 功能太少了,没必要考虑兼容),按照 utf-8、gbk 的顺序来检测文件编码,并设置帮助为中文。
设置 set helplang=cn 并不能马上看到中文帮助,我们还得下载中文帮助文件。
下载地址:http://vimcdoc.sourceforge.net/
下载解码后将doc目录下面所有文件全部COPY到 /usr/share/vim/vim72/doc/ 即可。

1
2
3
4
5
6
" disable VI's compatible mode..
set nocompatible
"
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,gbk,default,latin1
" use chinese help
set helplang=cn

接下来,启用格式化高亮、行号显示,以及括号匹配、自动缩进等编辑功能:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
set t_Co=256
" Enable syntax highlight
syntax enable
"
Show line number
set nu
" show matching bracets
set showmatch
"
Basic editing options
set expandtab
set shiftwidth=2
 
au FileType html,python,vim,javascript setl shiftwidth=2
au FileType html,python,vim,javascript setl tabstop=2
au FileType java,php setl shiftwidth=4
au FileType java,php setl tabstop=4
set smarttab
set lbr
set tw=0
"Auto indent
set ai
"
Smart indet
set si
" C-style indeting
set cindent
"
Wrap lines
set wrap

下载专门的 php 插件:
下载地址:http://www.vim.org/scripts/script.php?script_id=1571
下载文件:php.tar.gz
将其中的 php.vim 复制到/usr/share/vim/vim72/syntax 目录中即可。

设置喜欢的配色方案:
载网址:http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-c.html

http://vimcolorschemetest.googlecode.com/svn/html/index-c.html

有些配色方案是只能在gui下使用的,为解决这个问题,可用gui2term.py将配色方案转换为终端配色。(具体方法可参考《将GUI配色转化为终端配色的VIM插件 –gui2term.py》
我的配置是:

1
2
3
4
5
6
7
if has("gui_running")
  set guifont=monaco\ 11
  " set color schema
  color dawn
  else
  color less
endif

其中monaco字体是程序员专用字体,dawn是浅色主题,less是深色主题。
monaco字体下载地址:http://www.gringod.com/wp-upload/MONACO.TTF
http://www.gringod.com/2006/02/24/return-of-monacottf/
http://www.brsbox.com/filebox/down/fc/c3967edfd73baf6c6b70ce058ab37db8

本站下载:
monaco ,consola字体下载:


dawn , less 配色方案:

让vim更好的支持javascript编程:jQuery : Syntax file for jQuery
http://www.vim.org/scripts/script.php?script_id=2416
把jquery.vim放到/usr/share/vim/vim72/syntax目录,然后在vimrc.local中加入如下代码:

1
au BufRead,BufNewFile *.js set syntax=jquery

还有一些有用的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
" Sets how many lines of history VIM har to remember
set history=400

"
Set to auto read when a file is changed from the outside
set autoread

" Have the mouse enabled all the time:
set mouse=a

"
Do not redraw, when running macros.. lazyredraw
set lz

" set 7 lines to the curors - when moving vertical..
set so=7

 "
The commandbar is 2 high
set cmdheight=2

" Change buffer - without saving
set hid

"
Ignore case when searching
" set ignorecase
set incsearch

"
Set magic on
set magic

" How many tenths of a second to blink
set mat=4

"
Highlight search things
set hlsearch

" Turn backup off
set nobackup
set nowb
set noswapfile

"
smart backspace
set backspace=start,indent,eol

" switch buffers with Tab
map <C-Tab> :bn<CR>
map <S-Tab> :bp<CR>

由于我们还安装了 gvim ,因此最后再运行一下:

1
cp vimrc.local gvimrc.local

,不然我们折腾了这么久的配置只对shell下的vim起作,不对gvim起作用啦。 :mrgreen:

最后看下效果:


本文参考:http://doc.linuxpk.com/53985.html

喜欢这篇文章吗?

请订阅本站 RSS feed填写您的邮件地址,订阅我们的精彩内容:,欢迎点击这里捐赠以支持荒野无灯转播到腾讯微博 转播到腾讯微博

作者:荒野无灯
出处:Hacklog【Hacklog】

声明: 本站遵循 署名-非商业性使用-相同方式共享 3.0 共享协议. 转载请注明转自Hacklog【荒野无灯weblog】

本文链接: http://ihacklog.com/?p=3753

3 Responses Post a comment
  1. 二月 17, 2012

    编辑器之神

  2. 五月 2, 2010

    哇,我又看到有人推荐我写的程序(gui2term.py)了,好高兴~

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <q cite=""> <strong>

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS