现在的
工作是在 unix 平台,平时是用 UE 的 ftp 功能来写代码的,有时候文件大了,传输就很慢,而且经常不是很稳定。
下定决心要学学 Vim (现在应该没有人用原始的 vi 了吧),在经过二周的使用后,发现 Vim 实在是非常不错的一个 editor,
现在我在 Windows 上也装了一个 Vim,使用起来颇为顺手,基本上已经替代了 UE。
下面介绍一些我在使用 Vim 的过程中得到的一些心得:
1. 在使用 Vim 之前一定要进行一些设置,否则你使用起来肯定会很不爽,下面是我的配置
1 " ==============================================
2 " General settings
3 " ==============================================
4
5 set nocp
6 set ru
7 " 使用cindent
8 set cin
9 set cino = :0g0t0(sus
10
11 set sm
12 set ai
13 " 缩近
14 set sw=4
15 set ts=4
16 " 不展开tab为空格,反之set et
17 set noet
18
19 set lbr
20 set hls
21 set backspace = indent , eol , start
22 set whichwrap = b , s , < , > , [ , ]
23 set fo+ = mB
24 set selectmode =
25 set mousemodel = popup
26 set keymodel =
27 set selection = inclusive
28 set matchpairs+ = <:>
29
30 " ==============================================
31 " Cursor movement
32 " ==============================================
33 nnoremap
gj
34 nnoremap gk
35 vnoremap gj
36 vnoremap gk
37 inoremap gj
38 inoremap gk
39
40 nnoremap g$
41 nnoremap g0
42 vnoremap g$
43 vnoremap g0
44 inoremap g$
45 inoremap g0
46
47 nmap :confirm bd
48 vmap :confirm bd
49 omap :confirm bd
50 map! :confirm bd
51
52 " 打开语法高亮
53 syntax on
54 " 使用语法进行折叠
55 set foldmethod=syntax
56
57 if (has( " gui_running " ))
58 set nowrap
59 set guioptions+=b
60 colo inkpot
61 else
62 set wrap
63 colo ron
64 endif
65
66 " 设置swap文件的目录
67 set dir = D:\vim\tmp
68 " 设置备份文件的目录
69 set backupdir=D:\vim\bak
70
71 " 设置 leader 的快捷键,原来的“\”太远了,而且位置还不固定
72 let mapleader = " , "
这里是一些基本设置
如果有什么不太清楚的,可以在 Vim 里 normal 模式下
:h 关键字
查看帮助
2. Vim教程
推荐先看看Vim自带的Tutor(这可是位好老师)
用vimtutor启动Vim
或者在Vim里面用:h tutor来启动
中文教程我推荐李果正的《大家来学Vim》
这里还有Vim的键位示意图,可以打出来随时查看哦
3. Vim的插件
有几个插件强烈推荐
(1) A.vim 在同名的cpp和h文件之间切换 vim.org/scripts/script.php?script_id=31
(2) NERD_comments:超强的注释插件,支持很多语言的注释风格,按照上面的设置,只需要",cc"
就可以添加注释了 vim.org/scripts/script.php?script_id=1218
(3) csupport:写C/C++代码必备 vim.org/scripts/script.php?script_id=213
(4) LargeFile:再也不用担心打开大文件会慢了 vim.org/scripts/script.php?script_id=1506
(5) TipOfTheDay:多读读vim的tips会有很多收获的,记得要经常更新tips文件啊 vim.org/scripts/script.php?script_id=88
(6) cppomnicomplete:提供C++中类/对象成员的补全(需要Vim7) vim.org/scripts/script.php?script_id=1520
(7) ColorSamplerPack:提供上百种颜色主题,必有一款适合你,不过大多数都是在GUI下才有相应的效果 vim.org/scripts/script.php?script_id=625
(8) vimcdoc:汉化的vim帮助 vimcdoc.sourceforge.net/
3. 在telnet中使用vim的颜色
如果是在linux中使用telnet,SecureCRT会自动使用合适的颜色来显示vim不同的颜色,但是如果在其他unix下就会无法显示正确的颜色,所有的东西都是同一种颜色。
在.vimrc中加入(^[的输入方式是Ctrl-v然后输入Esc):
if !has("gui_running")
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
endif
并在SecureCRT的模拟终端类型选择ANSI,并钩上ANSI Color,就可以显示不