万年编辑器Vim


10/11/05。  cathayan.org版权所有,保留一切权利。转载请保留此说明。谢绝商业转载。

如果文本编辑器变得越来越重要,我想大家是不必吃惊的,因为文本似乎和网络有着某种联系,*nix系统也都喜欢它。win上面有editplus, ultraedit,都很强大,但是都是商业软件;后来我用过crimson editor, notepad++等免费的,也还可以;Linux下面各桌面系统自带的编辑器不少,gedit,bluefish,后来Carlos推荐了leafpad,确实是小巧快速,可以充当notepad的替代。

其实我还有一点Vi使用经验,以前用过一点Sun工作站(Vi正是Sun首席科学家,BSD UNIX主创人员,天才人士之一的Bill Joy的作品。vim是多个变种之一,主要作者和维护人是荷兰人士Bram Moolenaar。)的缘故,知道它分插入模式和命令模式,还会用hjkl来移动光标,平时就用这几招来对付Linux下面配置文件的编辑,也将就没有问题。有时写点小程序,翻译点文档啥的,似乎都没有问题。但在win上面,我一直用不起来,虽然我一直都装的有gVim。好像是因为在Windows上面太过于依赖鼠标,而不是习惯于打键盘了。

这一切一直延续到两周多以前,那天跑去听了水木Vim版主的一个报告,果然是深受鼓舞,又学了几招高妙的,又改了下vimrc,这两周来基本没再开过其他编辑器。这个故事告诉我们人还是社会动物,互相之间鼓动一下有时是很必要的。

版主的报告也有PDF下载可看(好像是openoffice做出来的),我从中学到不少东西。比如列编辑和map一些命令。我把jk都map到gj/gk,这样的操作比较适合文本多的,如果是程序多就未必很方便了。还从中学到了gvim,以前我一向是在term里用的,这个图形化的确实有好处,比如可以用更多字体--版主推荐bitstream vera suns mono这个字体,它可以把I1lOo0这些东西区别开来。同时gvim还在菜单上提供一些很有用的命令,如果一时记不得不妨一用。

昨天刚用一个菜单命令把人震了一把,就是语法下面的“转换成HTML”,简直是太酷了,不论你敲的是HTML,还是CSS,还是C或者Java,一个命令就转成标准的HTML代码,可以直接贴到Blog上去那种,并且还带语法高亮显示。实在是强到让人无语。

最近又挖到了中文版VimDoc,也就是文档了,这个项目我早就知道却一直没有注意过,最近才认真看了下,居然是可以安装到Vim下面来的,并且如果设好helplang=cn的话,每次敲:help就会自动使用中文版,实在是方便。据大侠说这东西应该每天有空时就过一遍,读上一百遍之后就可以成为高手了。

下面是我从各处抄来的vimrc文件,用vim转成了HTML,贴出来看个景儿:)其中多有不明白的。

[update]刚才又学了两招,在转HTML时,可以let html_no_pre=1就可以不用PRE标签,let html_use_css=1就是CSS风格,这些:help 2html即可看到。真不是一般强啊。


1 " Vim configuration file
2 set fileencodings=prc
3 set encoding=prc
4 " DEFAULT OPTIONS
5 set nocompatible " make Vim default to nicer options
6
7 " READING OPTIONS
8 set modeline modelines=1 " use settings from file being edited
9
10 " INPUT OPTIONS
11 set mouse=a " use the mouse
12
13 " DISPLAY OPTIONS
14 "set background=light " better colors for white terminals
15 set number " show line numbers
16 set ruler " show line and column information
17 set notitle " don't set change terminal's title
18 set backspace=indent,eol,start " backspaces can go over lines
19 set tabstop=4 " tabs are every 8 columns
20 set softtabstop=4
21 set shiftwidth=4
22
23
24 " jump only one 'line' when wrap set on
25 nnoremap j gj
26 nnoremap k gk
27 vnoremap j gj
28 vnoremap k gk
29 nnoremap <Down> gj
30 nnoremap <Up> gk
31 vnoremap <Down> gj
32 vnoremap <Up> gk
33 inoremap <Down> <C-o>gj
34 inoremap <Up> <C-o>gk
35
36
37 map <S-Insert> <MiddleMouse>
38 map! <S-Insert> <MiddleMouse>
39
40 imap <C-s> <C-o>:update<CR>
41
42 set cin
43 set sm
44 set et
45 set cino=:0g0t0(sus
46 set hls
47 set whichwrap=b,s,<,>,[,]
48 set fo+=mB
49 set mousemodel=popup
50 set selection=inclusive
51
52
53
54 :if version >= 600
55 set listchars=eol:$,tab:>-,trail:-,extends:>,precedes:<
56 :elseif version >= 500
57 set listchars=eol:$,tab:>-,trail:-,extends:+
58 :endif
59
60 set laststatus=2 " always show status line
61 set showmode " always show command or insert mode
62 set shortmess=lnrxI " brief messages, don't show intro
63 set showcmd " show partial commands
64 set more " use a pager for long listings
65
66 "set nowrap " do not wrap long lines
67 set wrap
68 set lbr
69 syntax on " use syntax highlighting
70
71 " Cursor movement
72 nnoremap <Down> gj
73 nnoremap <Up> gk
74 vnoremap <Down> gj
75 vnoremap <Up> gk
76 inoremap <Down> <C-o>gj
77 inoremap <Up> <C-o>gk
78
79 nnoremap <End> g$
80 nnoremap <Home> g0
81 vnoremap <End> g$
82 vnoremap <Home> g0
83 inoremap <End> <C-o>g$
84 inoremap <Home> <C-o>g0
85
86
87 if (has("gui_running"))
88 set wrap
89 set guioptions+=b
90 colo torte
91 else
92 set wrap
93 colo ron
94 endif
95
96 "set the guifont
97 if (has("gui_running"))
98 set guifont=Bitstream\ Vera\ Sans\ Mono\ 11
99 source $VIMRUNTIME/delmenu.vim
100 source $VIMRUNTIME/menu.vim
101 endif
102
103 " SAVING OPTIONS
104 set noexpandtab " don't change tabs into spaces
105 set backupext=~ " backup files end in ~
106
107 " EDITING OPTIONS
108 set autoindent " keep indenting at same level
109 set noerrorbells visualbell " flash screen instead of ringing bell
110 set esckeys " allow arrow keys in insert mode
111 set showmatch " show matching brackets
112
113 " SEARCH OPTIONS
114 set nohlsearch " don't highlight search patterns
115 set incsearch " search while typing
116 set ignorecase " make searches case-insensitive
117
118 " JavaID
119 :let java_highlight_all=1
120 :let java_highlight_java_beans=1
121
122 " MISCELLANEOUS OPTIONS
123 set dictionary=/usr/share/dict/words " get words from system dictionary
124 set magic " regexp chars have special meaning
125
126 filetype plugin on
127
128
129 " learn from carlos@linuxsir, to use multi cjk charset
130 "
131 " multi-encoding setting
132 if has("multi_byte")
133 "set bomb
134 set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1
135 " CJK environment detection and corresponding setting
136 if v:lang =~ "^zh_CN"
137 " Use cp936 to support GBK, euc-cn == gb2312
138 set encoding=cp936
139 set termencoding=cp936
140 set fileencoding=cp936
141 elseif v:lang =~ "^zh_TW"
142 " cp950, big5 or euc-tw
143 " Are they equal to each other?
144 set encoding=big5
145 set termencoding=big5
146 set fileencoding=big5
147 elseif v:lang =~ "^ko"
148 " Copied from someone's dotfile, untested
149 set encoding=euc-kr
150 set termencoding=euc-kr
151 set fileencoding=euc-kr
152 elseif v:lang =~ "^ja_JP"
153 " Copied from someone's dotfile, untested
154 set encoding=euc-jp
155 set termencoding=euc-jp
156 set fileencoding=euc-jp
157 endif
158 " Detect UTF-8 locale, and replace CJK setting if needed
159 if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
160 set encoding=utf-8
161 set termencoding=utf-8
162 set fileencoding=utf-8
163 endif
164 else
165 echoerr "Sorry, this version of (g)vim was not compiled with multi_byte"
166 endif
167

10/11/05 22:04:38,由cathayan发表。目录:电脑

Comments

21条评论

???:

notepad << ????????

于 10/11/05 22:28:20 发表  http://duller.blogspot.com

brian:

vim ?????? *nix???????
?vim????????????????????:

1. http://www.moolenaar.net/ha...
(vim??Bram Moolenaar???????????????????)

2.http://iccf-holland.org/ima...
[The vi Improved Editor] (???Bram Moolenaar, ???)
-------
2. SciTE
?????vim 3??????ruby??????
???SciTE ????
?????SciTE??????
??????????(?????????vim)
????SciTE.(???????????vim)

于 10/11/05 23:46:53 发表  http://www.cs.princeton.edu

leon.lee:

?????“?????”?
???Vi/vim??????????????“??”?????????????????
??????????Unix???????????

于 10/12/05 00:12:10 发表  http://www.antsight.com/liyi/

windix:

?vim????????????????????????????highlight????C?Java?Makefile?XML?Stylesheet?????????etc??????????????????????????????... ????????????????????

于 10/12/05 08:09:25 发表  http://www.douzi.org

windix:

?????????????????????SSH???????????????????????????GUI??????????X Forward??????????????????????????

于 10/12/05 08:18:23 发表  http://www.douzi.org

ilovevim:

????180?????????????????????Emacs??????

于 10/12/05 08:57:49 发表  

iThink:

????vim??????????????????????????????????????

于 10/12/05 09:54:00 发表  http://yackol.com/blog

Shiqi:

vim??????????hoho

于 10/12/05 13:34:58 发表  http://fsa.ia.ac.cn

kDolphin:

????????Emacs??????????????????????vim??

于 10/12/05 15:45:48 发表  http://www.kdolphin.org

rual:

?????vim?????????????
??????????vim?

于 10/14/05 09:05:36 发表  http://hailinlilin.sitesled.com

IUSR:

??????vim?win?…?vim.org???????????…
??????????~

于 10/14/05 20:55:47 发表  http://iusr.jar@gmail.com

Kiral:

????vim?autoindent????????????????????????????vim??????????C?HTML?????????????????indent???????????????????????????????????

于 10/17/05 01:10:30 发表  http://blog.i5un.com

vimania:

vim 6.4???????????bug???????
vim rules?

于 10/19/05 12:07:08 发表  

windix:

@Kiral:
??????????? gg=G ????
??????????..?????????????indent????????????????????

gvim??????????????

于 11/14/05 15:38:02 发表  http://www.douzi.org

clhu:

??indent??????????indent??????????html???indent???????html.vim????indent??????????????????????html?????indent?????????????????auto-indent??????

于 12/08/05 21:03:08 发表  http://clhu@chinaren.com

xbeta ????:

?????????????gvim???????????vim???blog???gvim????paste?
???blog??????????????
于 03/31/06 15:14:07 发表  http://blog.sina.com.cn/m/xbeta

ice_2001cn:

???????ctrl-r ctrl-o ???????????
于 04/04/06 18:42:32 发表  

??:

??vimrc
?windows?? ???????????????
?????set guifont=* ?????
????????set guifont????????
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave xterm

set ffs=unix,dos
set langmenu=none
set wmnu
language C

set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

if (has("gui_running"))
set guifont=Bitstream_Vera_Sans_Mono:h12:cANSI
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
set guioptions-=T " ?????,???????????
endif
colorscheme desert " ps_color

set stal=1 " ?????tab???tab,??????????
set formatoptions=tcrqn2mB
set ts=8 " tab?8??
set sw=4 " soft tab?4??
set bs=2 " backspace??
set ru " ????
set ic " ?????
set is " ????
set scs " ????????
set lsp=0 " space it out a little more (easier to read)
set wildignore=*.bak,*.o,*.e,*~

iab #i #include
iab #d #define
iab #e #endif

" ????cscope
set cst
set csto=1
set tags=./tags,../tags,../../tags,../../../tags,D:/tools/dev/Microsoft\ Visual\ Studio/VC98/Include/tags
set cspc=3 " show file path's last three part

set grepprg=grep\ -nH

map <F1> :Tlist<cr>
map <F2> :WMToggle<cr>
map <F3> zO
map <F4> zc
map <F5> zR
map <F6> zM
map <F7> :cn<CR>
"
set vb t_vb= " set visual bell and disable screen flash
set backup " enable backup and define the backup file
set backupext=.bak
set hlsearch " hlsearch
" allow backspacing over everything in
" the insert mode
set backspace=indent,eol,start
set dir=D:\tmp\vim
" ??swap???????
set backupdir=D:\tmp\vim
"??????????? ??????????????? ?????????
set foldmethod=syntax " marker,folder?????
set foldlevel=100 " Don't autofold anything (but I can still fold manually)
set foldopen-=search " don't open folds when you search into them
set foldopen-=undo " don't open folds when you undo stuff

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Perl
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let perl_extended_vars=1 " highlight advanced perl vars inside strings

"-------------------------------------------------------------------------------
" C-support.vim
"-------------------------------------------------------------------------------
let g:C_AuthorName = 'ws'
let g:C_AuthorRef = ''
let g:C_Email = 'Zhonglei_Li@trendmicro.com.cn'
let g:C_Company = ''
于 04/13/06 10:57:16 发表  http://loveunix.net

??:

??plugin
winmanager
bufexplore
???????????????

taglist (??ctags??)
drawit (???????)
a.vim ???.h .cpp???
DoxygenToolkit
cvim ?c???????
于 04/13/06 11:01:32 发表  http://loveunix.net

cathayan:

????????????

:pwd???????
:cd ??????
:edit . ??????????????????????????????????????????????????

Vim 7???Tab??????????
于 04/13/06 12:57:31 发表  

wangtwo:

?????? j

: )
于 06/01/09 19:00:14 发表  

Add Comments

This item is closed, it's not possible to add new comments to it or to vote on it

TrackBack