12月 26th, 2009[分享] Vim小技巧几则

一、中文帮助手册页

Vim7.2中文手册页下载:官方地址    我的Dropbox存档

内有详细的使用帮助和说明,默认vim会自动根据系统的当前locale选择显示语言。

如果要强制使用英文手册页,可以:set helplang=en,或切换中文手册页:set helplang=cn

二、启用拼写检查

:set spell或者:setlocal spell spelllang=en_us

它打开 ’spell’ 选项并指定检查美国英语。

注意:Vim只检查单词的拼写,不做语法检查。

要搜索下一个拼写有问题的单词:

*]s*
]s            移动到光标之后下一个拼写有问题的单词。命令前的计数可以
用来重复。适用 ‘wrapscan’。

*[s*
[s            类似于 “]s” 但反向搜索。寻找光标之前拼写有问题的单词。
不能识别分散在两行的单词,因而可能停在不被高亮为坏词的
单词上。但不会停在行首没有大写开头的单词上。

*]S*
]S            类似于 “]s” 但只检查坏词,不检查偏僻词或其它区域的词。

*[S*
[S            类似于 “]S” 但反向搜索。

要加入词汇到自定义的单词列表:

*zg*
zg            把光标所在的单词作为一个好 (good) 词加入到 ’spellfile’
的第一个名字对应的文件。命令前加上计数指示使用
’spellfile’ 的第几个项目。计数 2 使用第二个项目。

可视模式下把选择的字符序列作为一个单词 (包括空白!)。
如果光标在标为坏词的文本上,使用标注的文本。
否则使用非单词字符分隔的光标所在的单词。

如果该单词在其它拼写文件里被显式标注为坏词,结果无法预
测。

详情继续:help spell,以上内容节选自vim的中文帮助手册页。
三、在vim中快速查字典(Linux only)

该功能需要使用到命令行版的stardict,请安装sdvc

ubuntu用户使用apt-get即可迅速安装sdvc

$ sudo apt-get install sdvc

至此,准备工作结束。

下面开始编辑vim的配置文件在vim中光标移动到单词上,使用shift+f可以新分割出来一个窗口显示单词的翻译。

复制粘贴以下内容到~/.vimrc

———————– 我是分割线开始,不要复制我 ———————————

” 使用F查询光标所在处的单词的中文
function!  Mydict()
let  expl=system(’sdcv  -n  ‘  .
\   expand(”<cword>”))
windo  if
\  expand(”%”)==”diCt-tmp”  |
\  q!|endif
50vsp  diCt-tmp
setlocal  buftype=nofile  bufhidden=hide  noswapfile
1s/^/\=expl/
1
endfunction
nmap  F  :call  Mydict()<cr><C-W><C-W>

———————– 我是分割线结束,不要复制我 ———————————

如果在gvim中使用则在~/.gvimrc中添加:

———————– 我是分割线开始,不要复制我 ———————————

function  Mybln()
let  expl=system(’sdcv  -n  ‘  .
\  v:beval_text  .
\  ‘|fmt  -cstw  40′)
return  expl
endfunction

set  bexpr=Mybln()
set  beval

———————– 我是分割线结束,不要复制我 ———————————

四、在长行中轻松移动

编辑.vimrc,加入以下内容:

———————– 我是分割线开始,不要复制我 ———————————
” 解决超长行移动的困难
” 重新定义<UP> <DOWN>
:nmap <UP> gk
:imap <UP> <ESC>gka

:nmap <DOWN> gj
:imap <DOWN> <ESC>gja
———————– 我是分割线结束,不要复制我 ———————————

以后就可以通过键盘的上、下方向键轻松在一个超长行中移动了。
五、不要显示@@@@@

编辑.vimrc,加入以下内容:

———————– 我是分割线开始,不要复制我 ———————————
set display=lastline
———————– 我是分割线结束,不要复制我 ———————————

后记:Chrome编辑水木blog会导致文章的排版中的回车全部丢失,汗死。。。

今天写个perl的小程序的时候猛然发现自己以前设置的vim的环境还是很好用的,尽管还有点小bug,不过基本的运行和调试时没有问题了
贴出来,自己备份一下,也共享一下~~

” An example for a vimrc file.

Maintainer: Bram Moolenaar <Bram@vim.org>
” Last change: 2002 May 28

” To use it, copy it to
” for Unix and OS/2: ~/.vimrc
” for Amiga: s:.vimrc
” for MS-DOS and Win32: $VIM\_vimrc
” for OpenVMS: sys$login:.vimrc

” When started as “evim”, evim.vim will already have done these settings.
if v:progname =~? “evim”
finish
endif

” Use Vim settings, rather then Vi settings (much better!).
” This must be first, because it changes other options as a side effect.
set nocompatible

” allow backspacing over everything in insert mode
set backspace=indent,eol,start

“set autoindent ” always set autoindenting on
if has(“vms”)
set nobackup ” do not keep a backup file, use versions instead
else
set backup ” keep a backup file
endif
set history=50 ” keep 50 lines of command line history
set ruler ” show the cursor position all the time
set showcmd ” display incomplete commands
set incsearch ” do incremental searching

For Win32 GUI: remove ‘t’ flag from ‘guioptions’: no tearoff menu entries
” let &guioptions = substitute(&guioptions, “t”, “”, “g”)

” Don’t use Ex mode, use Q for formatting
map Q gq

“###################################################################
“@author - huangwei
“@created on - 2005-10-20
“@last modified - 10:16 2005-10-21
“——————————————————————-
” F2 - write file without confirmation
” F3 - call file explorer Ex
” F4 - show Taglist
” F5 - automatically insert current time to current location
” F8 - automatically complete keywords
” F12 - switch between windows
“——————————————————————-
map <S-Tab> :call NextField(’ \{2,}’,2,’ ‘,0)<CR>
map! <S-Tab> <C-O>:call NextField(’ \{2,}’,2,’ ‘,0)<CR>
” function: NextField
Args: fieldsep,minlensep,padstr,offset

” NextField checks the line above for field separators and moves the cursor on
” the current line to the next field. The default field separator is two or more
” spaces. NextField also needs the minimum length of the field separator,
” which is two in this case. If NextField is called on the first line or on a
” line that does not have any field separators above it the function echoes an
” error message and does nothing.

func! NextField(fieldsep,minlensep,padstr,offset)
let curposn = col(“.”)
let linenum = line(“.”)
let prevline = getline(linenum-1)
let curline = getline(linenum)
let nextposn = matchend(prevline,a:fieldsep,curposn-a:minlensep)+1
let padding = “”

if nextposn > strlen(prevline) || linenum == 1 || nextposn == 0
echo “last field or no fields on line above”
return
endif

echo “”

if nextposn > strlen(curline)
if &modifiable == 0
return
endif
let i = strlen(curline)
while i < nextposn - 1
let i = i + 1
let padding = padding . a:padstr
endwhile
call setline(linenum,substitute(curline,“$”,padding,“”))
endif
call cursor(linenum,nextposn+a:offset)
return
endfunc

” for quick save in normal mode
map <silent> <F2> :write<CR>
map <silent> <F3> :Explore<CR>

” switch between windows
map <silent> <F12> <C-W>w

” for quick save in edit mode
imap <F2> <ESC><F2>a

” according to SMTH’s VIM board
nnoremap <silent> <F4> :Tlist<CR>

” let F5 insert current time to current location.
map <F5> i<C-R>=strftime(”%H:%M %Y-%m-%d”)<ESC><ESC>
” map! <F5> <C-R>=strftime(”%H:%M %Y-%m-%d”)<RETURN>

“mouse function support
set mouse=a

” set auto shift width
” set shiftwidth=4

” disable auto backup
set nobackup

” set root directory of DICTIONARY, whose value by default is
” NULL to Linux
” /cygdrive/c to cygwin
C: to Win32
let g:DIC_ROOT_DIR=“C:\\dict”

” set default ‘dictionary’ path
execute “:set dictionary+=”.g:DIC_ROOT_DIR.\\words”
” more and more place including such keyword
set iskeyword+=-
” Let F8 made dictionary automatically complete keywords.
map! <F8> <C-X><C-K>

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”*
” autocmd FileType * set comments&
“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”C

autocmd FileType c call C()
fun! C()
set cindent
set comments=sr:/*,mb:*,el:*/,://
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab
set tags+=/usr/include/tags
execute “:set dictionary=C:\\dict\\C”
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
map! =for for(i = 0; i < ; i++){<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
endfun ” endfun C

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"CPP
autocmd FileType cpp call CPP()
fun! CPP()
set cindent
set comments=sr:/*,mb:*,el:*/,://
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab
set tags+=/usr/include/tags
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
execute “:set dictionary=C:\\dict\\CPP”
endfun ” endfun CPP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"PERL
autocmd FileType sed,awk,perl call PERL()
fun! PERL()
set cindent
set commentstring=\ \ #\ %s\ ” <SPACE>
set foldcolumn=3
” control-c comments block
vmap <C-C> :s/^/#/g<enter>
” control-x uncomments block
vmap <C-X> :s/^#//g<enter>
” ———-22:34 2007-01-04 update this—————————–
” —–F4 查字典 F7 单步调试 F8 语法检查 F9 运行程序——-
” —–;a 自动完成—–

” —–问题:运行程序的错误和结果如何捕捉?——

“<F11> == see perldoc for current word under cursor
map <F11> :call PerlDoc(expand(”<cword>“))<CR>

“<F7> for perl debugging
map <F7> :w<CR>:!perl.exe -wd “%”<CR>
“<F8> for perl syntax checking (autosave first)
map <F8> :w<CR>:!perl.exe -wc “%”<CR>
“<F9> to run by perl (autosave first) “”,” are both ok
map <F9> :w<CR>:!perl.exe “%”<CR>

” set dictionary for perl keywords completion
set dictionary=C:\\dict\\PERL

“set autoindent depth
set shiftwidth=4
“set tabstop
set tabstop=4
“set showmatch
set showmatch

” mapping my insert commands
” I called them “;-command” ’cause you’ve the least hesitation
” between you type the “;” and the following <Space> or <CR>

“<;a> for Auto-completion using dictionary
imap ;a <C-X><C-K>
“then use <C-N> to match the next keywords, and <C-P> the previous one
” map!=imap+cmap (i=insert mode, c=:command mode)
” a) imap <Space><Space> xx also can work, but not good
” b) i cannot map <M-x> or <M-Space>, why?
” c) Ctrl-Space <=> Ctrl-@
endfun ” endfun PERL

func PerlDoc(keyword)
if a:keyword=~“::”
“module name;
exec ‘:!perldoc ‘.a:keyword
elseif a:keyword=~“^perl”
“perl pod
exec ‘:!perldoc ‘.a:keyword
else
“perl function
exec ‘:!perldoc -f ‘.a:keyword
endif
endfunc

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"HTML
autocmd FileType html call HTML()
fun! HTML()
set dictionary=C:\\dict\\JS
set dictionary+=C:\\dict\\HTML
set tabstop=4
set shiftwidth=4
endfun ” endfun HTML
“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JAVA
autocmd FileType java call JAVA()
fun! JAVA()
set cindent
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab tags+=${JAVA_HOME}/src/tags
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
execute “:set dictionary=C:\\dict\\JAVA”
map! =for for(int i = 0; i < ; i++){<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
map! =psvm public static void main(String [] args){<RETURN>
map! =soutn System.out.println(
map! =sout System.out.print(
map! =try try{<RETURN>}catch(Exception e){<RETURN>System.out.println(e.getMessage());<RETURN>}<ESC>kkko
map! =tryb try{<ESC>:/^[ \t]*$/<RETURN>ddko}catch(Exception e){<RETURN>System.out.println(e.getMessage());<RETURN>}<ESC>k
endfun ” endfun JAVA

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JSP
autocmd FileType jsp call JSP()
fun! PHP()
execute “:set dictionary=C:\\dict\\JSP”
endfun ” endfun JSP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JS
autocmd Filetype js call JS()
fun! JS()
set dictionary=C:\\dict\\JS
set tabstop=4
set shiftwidth=4
endfun ” endfun JS

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"PHP
autocmd FileType php call PHP()
fun! PHP()
execute “:set dictionary=C:\\dict\\PHP”
endfun ” endfun PHP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"XML
autocmd FileType xml call XML()
fun! XML()
execute “:set dictionary=C:\\dict\\XML”
endfun ” endfun XML
“##################################################################

” This is an alternative that also works in block mode, but the deleted
” text is lost and it only works for putting the current register.
“vnoremap p “_dp

” Switch syntax highlighting on, when the terminal has colors
” Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has(“gui_running”)
syntax on
set hlsearch
endif

” Only do this part when compiled with support for autocommands.
if has(“autocmd”)

” Enable file type detection.
” Use the default filetype settings, so that mail gets ‘tw’ set to 72,
” ‘cindent’ is on in C files, etc.
” Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

” For all text files set ‘textwidth’ to 78 characters.
autocmd FileType text setlocal textwidth=78

” When editing a file, always jump to the last known cursor position.
” Don’t do it when the position is invalid or when inside an event handler
” (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line(“‘\”") > 0 && line(“‘\”") <= line(“$”) |
\ exe “normal g`\”" |
\ endif

endif ” has(”autocmd”)

按下v进入可视模式,然后用方向键控制选择待添加注释的文本部分,选择完毕后按下“:”键。
此时vim的命令行提示符变为:’<,’>
顺次输入

s/^/#/

输入完毕后此时的vim命令行应该是

:’<,’>s/^/#/

好了,回车吧,大功告成,所有的刚才选中的文本的行首都自动添加了#注释符
类似的,我们可以添加//,注意使用//作为注释符的时候应该输入的是:

:’<,’>s/^/\/\//

即需要转义一下/enjoy vim!

最近突然对纯文本编辑比较感兴趣,Google了一下,没有发现什么好的Win下可用的纯文本编辑器支持直接的表格编辑

于是想到了Vim

下面的就是用Vim编辑的一个示范例子

===============================================================================
Name Description Remark
AA Test OK
BB Good Great
——————————————————————————–

为了简便快速的编辑这个表格,需要编辑一下我们的_vimrc文件或其子配置文件

下面的代码摘自我的配置文件

map <S-Tab> :call NextField(’ \{2,}’,2,’ ‘,0)<CR>
map! <S-Tab> <C-O>:call NextField(’ \{2,}’,2,’ ‘,0)<CR>
” function: NextField
” Args: fieldsep,minlensep,padstr,offset

” NextField checks the line above for field separators and moves the cursor on
” the current line to the next field. The default field separator is two or more
” spaces. NextField also needs the minimum length of the field separator,
” which is two in this case. If NextField is called on the first line or on a
” line that does not have any field separators above it the function echoes an
” error message and does nothing.func! NextField(fieldsep,minlensep,padstr,offset)
let curposn = col(”.”)
let linenum = line(”.”)
let prevline = getline(linenum-1)
let curline = getline(linenum)
let nextposn = matchend(prevline,a:fieldsep,curposn-a:minlensep)+1
let padding = “”

if nextposn > strlen(prevline) || linenum == 1 || nextposn == 0
echo “last field or no fields on line above”
return
endif

echo “”

if nextposn > strlen(curline)
if &modifiable == 0
return
endif
let i = strlen(curline)
while i < nextposn - 1
let i = i + 1
let padding = padding . a:padstr
endwhile
call setline(linenum,substitute(curline,”$”,padding,”"))
endif
call cursor(linenum,nextposn+a:offset)
return
endfunc

现在这个简单的表格的编辑过程如下所列:

1. 80i=<ESC>

2. Name Description Remark

3. AA<S-Tab>Test<S-Tab>OK

4. BB<S-Tab>Good<S-Tab>Great

5. 80i-<ESC>

上面的配置文件参考这里:http://www.vim.org/tips/tip.php?tip_id=547

12月 28th, 2006我的_vimrc更新

” An example for a vimrc file.

” Maintainer: Bram Moolenaar <Bram@vim.org>
” Last change: 2002 May 28

” To use it, copy it to
” for Unix and OS/2: ~/.vimrc
” for Amiga: s:.vimrc
” for MS-DOS and Win32: $VIM\_vimrc
” for OpenVMS: sys$login:.vimrc

” When started as “evim”, evim.vim will already have done these settings.
if v:progname =~? “evim”
finish
endif

” Use Vim settings, rather then Vi settings (much better!).
” This must be first, because it changes other options as a side effect.
set nocompatible

” allow backspacing over everything in insert mode
set backspace=indent,eol,start

“set autoindent ” always set autoindenting on
if has(”vms”)
set nobackup ” do not keep a backup file, use versions instead
else
set backup ” keep a backup file
endif
set history=50 ” keep 50 lines of command line history
set ruler ” show the cursor position all the time
set showcmd ” display incomplete commands
set incsearch ” do incremental searching

” For Win32 GUI: remove ‘t’ flag from ‘guioptions’: no tearoff menu entries
” let &guioptions = substitute(&guioptions, “t”, “”, “g”)

” Don’t use Ex mode, use Q for formatting
map Q gq

“###################################################################
“@author - TrojanJason
“@created on - 2005-10-20
“@last modified - 18:16 2006-12-28
“——————————————————————-
” F2 - write file without confirmation
” F3 - call file explorer Ex
” F4 - show Taglist
” F5 - automatically insert current time to current location
” F8 - automatically complete keywords
” F12 - switch between windows
“——————————————————————-
” for quick save in normal mode
map <silent> <F2> :write<CR>
map <silent> <F3> :Explore<CR>

” switch between windows
map <silent> <F12> <C-W>w

” for quick save in edit mode
imap <F2> <ESC><F2>a

” according to SMTH’s VIM board
nnoremap <silent> <F4> :Tlist<CR>

” let F5 insert current time to current location.
map <F5> i<C-R>=strftime(”%H:%M %Y-%m-%d”)<ESC><ESC>
” map! <F5> <C-R>=strftime(”%H:%M %Y-%m-%d”)<RETURN>

“mouse function support
set mouse=a

” set auto shift width
” set shiftwidth=4

” disable auto backup
set nobackup

” set root directory of DICTIONARY, whose value by default is
” NULL to Linux
” /cygdrive/c to cygwin
” C: to Win32
let g:DIC_ROOT_DIR=”C:\\dict”

” set default ‘dictionary’ path
execute “:set dictionary+=”.g:DIC_ROOT_DIR.”\\words
” more and more place including such keyword
set iskeyword+=-
” Let F8 made dictionary automatically complete keywords.
map! <F8> <C-X><C-K>

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”*
” autocmd FileType * set comments&
“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”C

autocmd FileType c call C()
fun! C()
set cindent
set comments=sr:/*,mb:*,el:*/,://
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab
set tags+=/usr/include/tags
execute “:set dictionary+=C:\\dict\\C”
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
map! =for for(i = 0; i < ; i++){<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
endfun ” endfun C

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"CPP
autocmd FileType cpp call CPP()
fun! CPP()
set cindent
set comments=sr:/*,mb:*,el:*/,://
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab
set tags+=/usr/include/tags
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
execute “:set dictionary+=C:\\dict\\CPP”
endfun ” endfun CPP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"PERL
autocmd FileType sed,awk,perl call PERL()
fun! PERL()
set cindent
set commentstring=\ \ #\ %s\ ” <SPACE>
set foldcolumn=3
” control-c comments block
vmap <C-C> :s/^/#/g<enter>
” control-x uncomments block
vmap <C-X> :s/^#//g<enter>
” append dictionary
execute “:set dictionary+=C:\\dict\\PERL”
endfun ” endfun PERL

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"HTML
autocmd FileType html call HTML()
fun! HTML()
execute “:set dictionary+=C:\\dict\\HTML”
execute “:set dictionary+=C:\\dict\\JS”
endfun ” endfun HTML
“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JAVA
autocmd FileType java call JAVA()
fun! JAVA()
set cindent
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab tags+=${JAVA_HOME}/src/tags
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
execute “:set dictionary+=C:\\dict\\JAVA”
map! =for for(int i = 0; i < ; i++){<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
map! =psvm public static void main(String [] args){<RETURN>
map! =soutn System.out.println(
map! =sout System.out.print(
map! =try try{<RETURN>}catch(Exception e){<RETURN>System.out.println(e.getMessage());<RETURN>}<ESC>kkko
map! =tryb try{<ESC>:/^[ \t]*$/<RETURN>ddko}catch(Exception e){<RETURN>System.out.println(e.getMessage());<RETURN>}<ESC>k
endfun ” endfun JAVA

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JSP
autocmd FileType jsp call JSP()
fun! PHP()
execute “:set dictionary+=C:\\dict\\JSP”
endfun ” endfun JSP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JS
autocmd Filetype js call JS()
fun! JS()
execute “:set dictionary+=C:\\dict\\JS”
endfun ” endfun JS

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"PHP
autocmd FileType php call PHP()
fun! PHP()
execute “:set dictionary+=C:\\dict\\PHP”
endfun ” endfun PHP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"XML
autocmd FileType xml call XML()
fun! XML()
execute “:set dictionary+=C:\\dict\\XML”
endfun ” endfun XML
“##################################################################

” This is an alternative that also works in block mode, but the deleted
” text is lost and it only works for putting the current register.
“vnoremap p “_dp

” Switch syntax highlighting on, when the terminal has colors
” Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has(”gui_running”)
syntax on
set hlsearch
endif

” Only do this part when compiled with support for autocommands.
if has(”autocmd”)

” Enable file type detection.
” Use the default filetype settings, so that mail gets ‘tw’ set to 72,
” ‘cindent’ is on in C files, etc.
” Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

” For all text files set ‘textwidth’ to 78 characters.
autocmd FileType text setlocal textwidth=78

” When editing a file, always jump to the last known cursor position.
” Don’t do it when the position is invalid or when inside an event handler
” (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line(”‘\”") > 0 && line(”‘\”") <= line(”$”) |
\ exe “normal g`\”" |
\ endif

endif ” has(”autocmd”)

一个典型的Vim字典文件就是每行一个单词,如下所示:

abstract
boolean
break
byte
case
catch

编辑_vimrc,在文件中加入字典文件位置的设定:

” set root directory of DICTIONARY, whose value by default is
” NULL to Linux
” /cygdrive/c to cygwin
” C: to Win32
let g:DIC_ROOT_DIR=”C:\\dict”

” set default ‘dictionary’ path
execute “:set dictionary+=”.g:DIC_ROOT_DIR.\\words

使用vim编辑文件的时候,<C-X><C-K>将查找字典文件进行自动补全。

现在有一个问题,就是不知道如何按照文件类型进行动态添加相应的字典文件。

比如编辑.html文件,需要添加HTML和JS的关键字字典

贴一下我的配置文件代码片段

autocmd FileType html call HTML()
fun! HTML()
execute “:set dictionary+=C:\\dict\\HTML”
execute “:set dictionary+=C:\\dict\\JS”
endfun ” endfun HTML

不过发现一个bug,FileType不能正确的识别.js文件,不知道为什么。。。

还有一个问题就是在Windows下用set dictionary在函数中不支持两端用”

比如下面的写法就不能加载字典文件

execute “:set dictionary+=”.g:DIC_ROOT_DIR.”HTML”

疑惑中。。。

* 使用拼写检查功能

Vim 7 内置了一项与 Microsoft Word 类似的拼写检查功能,使用该功能可以检查出所拼写词语的错误。在默认情况下,这项功能是没有开启的。若是使用 GVim 的话,可通过“Tools -> Spelling -> Spell check on”菜单命令开启。Vim 一旦发现拼写错误的词语,则以红色的波浪线标记。而使用以下命令可以执行拼写检查功能的相关操作:
:set spell-开启拼写检查功能
:set nospell-关闭拼写检查功能
:]s-移到下一个拼写错误的单词
:[s-作用与上一命令类似,但它是从相反方向进行搜索
z=-显示一个有关拼写错误单词的列表,可从中选择
zg-告诉拼写检查器该单词是拼写正确的
zw-与上一命令相反,告诉拼写检查器该单词是拼写错误的
* 使用括弧高亮显示功能

此特性在编码时非常具有帮助。对于如“{”、“}”之类的配对括弧,Vim 7 将高亮显示它们。如果不喜欢,可以使用“:NoMatchParen”命令禁用该功能。
* 使用自动补完功能

这是一个非常酷的特性。当你在写代码的时候,可以使用该功能帮助你自动完成标记、关键字等等。此功能支持 C、(X)HTML(包含 CSS)、JavaScript、PHP、Python、Ruby、SQL、XML 等语言。在插入模式中,连续按“[Ctrl+x] [Ctrl+o]”组合键可以打开该功能。你可以从弹出的列表框中进行选择。
* 使用分页(tabs)功能

此功能可让 Vim 同时打开多个文档进行编辑。其命令如下:
:tabe /path/to/file.txt-在一个新的 tab 页中打开文件
:tabnew-新建一个 tab 页
:tabs-查看 tab 页列表,通过“>”显示当前窗口、“+”显示可修改的缓冲区
:tabc-关闭当前的 tab 页
:tab split-在当前缓冲区使用新的 tab 页打开文件
:tabn-切换到下一个 tab 页
:tabp-切换到上一个 tab 页
:tabr[ewind]-转到第一个 tab 页
:tabf[irst]-与上一命令作用相同
* 使用撤销分支功能

可以使用 :undolist 命令查看缓冲区存在的撤销分支列表。而通过 :undo < number> 命令则能够移到撤销的某个分支。

12月 28th, 2006Vim使用技巧(一)

# searching 查找
/joe/e : cursor set to End of match
把光标定位在匹配单词最后一个字母处
/joe/e+1 : cursor set to End of match plus 1
把光标定位在匹配单词最后一个字母的下一个字母处
/joe/s-2 : cursor set to Start of match minus 2
把光标定位在匹配单词第一个字母往前数两个字母的位置
/^joe.*fred.*bill/ : normal
标准的正则表达式
/^[A-J]\+/ : search for lines beginning with one or more A-J
查找以一个或多个 A-J 中的字母开头的行
/begin\_.*end : search over possible multiple lines
查找在 begin 和 end 两个单词之间尽可能多的行
/fred\_s*joe/i : any whitespace including newline
查找在 fred 和 joe 两个单词之间任意多的空格,包括新行
/fred\|joe : Search for FRED OR JOE
查找 fred 或 joe
/\([^0-9]\|^\)%.*% : Search for absence of a digit or beginning of line
查找
/.*fred\&.*joe : Search for FRED AND JOE in any ORDER!
查找同时包含 FRED 和 JOE 的行,不分前后顺序
/\<fred\>/i : search for fred but not alfred or frederick
查找 fred, 而不是 alfred 或者 frederick,也就是全字匹配
/\<\d\d\d\d\> : Search for exactly 4 digit numbers
查找4个数字的全字匹配
/\D\d\d\d\d\D : Search for exactly 4 digit numbers
查找4个数字的全字匹配
/\<\d\{4}\> : same thing
同上

# finding empty lines 查找空行
/^\n\{3} : find 3 empty lines
查找 3 行空行
# Specify what you are NOT searching for (vowels)
# 指定不要查找什么
/\c\v([^aeiou]&\a){4} : search for 4 consecutive consanants

# using rexexp memory in a search
# 在查找中使用正则表达式存储
/\(fred\).*\(joe\).*\2.*\1

# Repeating the Regexp (rather than what the Regexp finds)
# 重复正则表达式
/^\([^,]*,\)\{8}

# visual searching
# 可视模式下的查找
:vmap // y/<C-R>”<CR> : search for visually highlighted text
查找被高亮显示的文本
:vmap <silent> // y/<C-R>=escape(@”, ‘\\/.*$^~[]’)<CR><CR> : with spec chars

# searching over multiple lines \_ means including newline
# 查找多行。\_ 表示包括新行
/<!–\_p\{-}–> : search for multiple line comments
查找多行注释
/fred\_s*joe/i : any whitespace including newline
查找在 fred 和 joe 两个单词之间任意多的空
格,包括新行
/bugs\(\_.\)*bunny : bugs followed by bunny anywhere in file
bugs 后任意位置含有 bunny 单词的多个行
:h \_ : help
帮助

# search for declaration of subroutine/function under cursor
# 查找光标下子程序/函数的声明
:nmap gx yiw/^\(sub\<bar>function\)\s\+<C-R>”<CR>

# multiple file search
# 在多个文件中查找
:bufdo /searchstr
:argdo /searchstr

# How to search for a URL without backslashing
# 如何不使用反斜线查找 URL
?http://www.vim.org/ : search BACKWARDS!!! clever huh!
—————————————-
# substitution
# 替换
:%s/fred/joe/igc : general substitute command
普通替换命令
:%s/\r//g : Delete DOS returns ^M
删除 DOS 回车符 ^M

# Is your Text File jumbled onto one line? use following
# 你的文本文件是否乱七八糟的排成一行?使用如下命令
:%s/\r/\r/g : Turn DOS returns ^M into real returns
转换 DOS 回车符 ^M 为真正的回车符
:%s= *$== : delete end of line blanks
删除行尾空格
:%s= \+$== : Same thing
同上
:%s#\s*\r\?$## : Clean both trailing spaces AND DOS returns
删除行尾空格和 DOS 回车符
:%s#\s*\r*$## : same thing
删除行尾空格和 DOS 回车符

# deleting empty lines
# 删除空行
:%s/^\n\{3}// : delete blocks of 3 empty lines
删除三行空行
:%s/^\n\+/\r/ : compressing empty lines
压缩多行空行为一行

# IF YOU ONLY WANT TO KNOW ONE THING
# 如果你只想明白一件事情
:’a,’bg/fred/s/dick/joe/igc : VERY USEFUL
非常有用

# duplicating columns
# 复制列
:%s= [^ ]\+$=&&= : duplicate end column
复制最后一列
:%s= \f\+$=&&= : same thing
同上
:%s= \S\+$=&& : usually the same
同上
# memory
# 记忆,或叫引用
:s/\(.*\):\(.*\)/\2 : \1/ : reverse fields separated by :
反转以 : 分隔的字段
:%s/^\(.*\)\n\1/\1$/ : delete duplicate lines
删除重复的行

# non-greedy matching \{-}
# 非贪婪匹配 \{-}
:%s/^.\{-}pdf/new.pdf/ : delete to 1st pdf only
只删除到第一个 pdf

# use of optional atom \?
:%s#\<[zy]\?tbl_[a-z_]\+\>#\L&#gc : lowercase with optional leading characters
不懂

# over possibly many lines
# 匹配尽可能多的行
:%s/<!–\_.\{-}–>// : delete possibly multi-line comments
删除尽可能多的注释
:help /\{-} : help non-greedy
非贪婪匹配的帮助

# substitute using a register
# 使用寄存器替换
:s/fred/<c-r>a/g : sub “fred” with contents of register “a”
用”a”寄存器里的内容替换”fred”
:s/fred/\=@a/g : better alternative as register not displayed
更好的方法,不用显示寄存器内容

# multiple commands on one line
# 写在一行里的复杂命令
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/

# ORing
:%s/suck\|buck/loopy/gc : ORing (must break pipe)
不懂
# Calling a VIM function
# 调用 Vim 函数
:s/__date__/\=strftime(”%c”)/ : insert datestring
插入日期

# Working with Columns sub any str1 in col3
# 处理列,替换所有在第三列中的 str1
:%s:\(\(\w\+\s\+\)\{2}\)str1:\1str2:

# Swapping first & last column (4 columns)
# 交换第一列和最后一列 (共4列)
:%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1:

# filter all form elements into paste register
# 把所有的form元素(就是html里面的form啦)放到register里
:redir @*|sil exec ‘g#<\(input\|select\|textarea\|/\=form\)\>#p’|redir END
:nmap ,z :redir @*<Bar>sil exec
‘g@<\(input\<Bar>select\<Bar>textarea\<Bar>/\=form\)\>@p’<Bar>redir END<CR>

# increment numbers by 6 on certain lines only
# 不懂
:g/loc\|function/s/\d/\=submatch(0)+6/

# better
# 更好的方法
:%s#txtdev\zs\d#\=submatch(0)+1#g
:h /\zs

# increment only numbers gg\d\d by 6 (another way)
# 不懂
:%s/\(gg\)\@<=\d\+/\=submatch(0)+6/
:h zero-width

# find replacement text, put in memory, then use \zs to simplify substitute
# 查找需替换的文本,保存,然后使用 \zs 命令简单替换
:%s/”\([^.]\+\).*\zsxx/\1/

# Pull word under cursor into LHS of a substitute
# 不懂
:nmap <leader>z :%s#\<<c-r>=expand(”<cword>”)<cr>\>#

# Pull Visually Highlighted text into LHS of a substitute
# 不懂
:vmap <leader>z :<C-U>%s/\<<c-r>*\>/

—————————————-

# all following performing similar task, substitute within substitution
# Multiple single character substitution in a portion of line only

:%s,\(all/.*\)\@<=/,_,g : replace all / with _ AFTER “all/”

# Same thing
:s#all/\zs.*#\=substitute(submatch(0), ‘/’, ‘_’, ‘g’)#

# Substitute by splitting line, then re-joining
:s#all/#&^M#|s#/#_#g|-j!

# Substitute inside substitute
:%s/.*/\=’cp ‘.submatch(0).’ all/’.substitute(submatch(0),’/',’_',’g')/
—————————————-
# global command display (see tip 227)
# 全局命令显示(参见 tip 227)
:g/fred.*joe.*dick/ : display all lines fred,joe & dick
显示所有包含fred,joe 和 dick 的行
:g/\<fred\>/ : display all lines fred but not freddy
显示所有全字匹配 fred 的行
:g/<pattern>/z#.5 : display with context
显示上下文
:g/<pattern>/z#.5|echo “==========” : display beautifully
显示得很漂亮
:g/^\s*$/d : delete all blank lines
删除所有的空行
:g!/^dd/d : delete lines not containing string
删除所有行首不是 dd 的行
:v/^dd/d : delete lines not containing string
同上
:g/fred/,/joe/d : not line based (very powerfull)
并不基于行(非常强大)
:g/{/ ,/}/- s/\n\+/\r/g : Delete empty lines but only between {…}
删除在 {…} 只见的空行
:v/./.,/./-1join : compress empty lines
压缩空行
:g/^$/,/./-j : compress empty lines
压缩空行
:g/<input\|<form/p : ORing
不懂
:g/^/pu _ : double space file (pu = put)
把文件中空行增加一倍
:g/^/m0 : Reverse file (m = move)
翻转文件
:g/fred/t$ : copy lines matching fred to EOF
把匹配 fred 的行拷贝到文件最后
:g/stage/t’a : copy lines matching stage to marker a
把匹配 stage 的行做标记a
:%norm jdd : delete every other line
隔一行删除一行

# incrementing numbers (type <c-a> as 5 characters)
:.,$g/^\d/exe “norm! \<c-a>”: increment numbers
增加每行行首的数字
:’a,’bg/\d\+/norm! ^A : increment numbers
增加标记 a 到标记 b 只见每行行首的数字

# storing glob results (note must use APPEND)
# 保存全局命令的结果 (注意必须使用添加模式)
:g/fred/y A : append all lines fred to register a
添加所有为fred所匹配的行到register a
:’a,’b g/^Error/ . w >> errors.txt

# duplicate every line in a file wrap a print ” around each duplicate
# 复制每一行,然后在复制出来的每一行两侧加上一个 print ‘复制出来的内容’
:g/./yank|put|-1s/’/”/g|s/.*/Print ‘&’/

# replace string with contents of a file, -d deletes the “mark”
# 用文件中的内容替换字符串,-d 表示删除“标记”
:g/^MARK$/r tmp.ex | -d

—————————————-

# Global combined with substitute (power editing)
# 全局命令和替换命令联姻 (强大的编辑能力)
:’a,’bg/fred/s/joe/susan/gic : can use memory to extend matching
可以使用反向引用来匹配
:g/fred/,/joe/s/fred/joe/gic : non-line based (ultra)

—————————————-

# Find fred before beginning search for joe
# 先找fred,然后找joe
:/fred/;/joe/-2,/sid/+3s/sally/alley/gIC

—————————————-

# Absolutely essential
# 基础

—————————————-
* # g* g# : find word under cursor (<cword>) (forwards/backwards)
寻找光标处的狭义单词(<cword>) (前向/后向)
% : match brackets {}[]()
括号配对寻找 {}[]()
. : repeat last modification

matchit.vim : % now matches tags <tr><td><script> <?php etc
使得 % 能够配对标记 <tr><td><script> <?php 等等
<C-N><C-P> : word completion in insert mode
插入模式下的单词自动完成
<C-X><C-L> : Line complete SUPER USEFUL
行自动完成(超级有用)
/<C-R><C-W> : Pull <cword> onto search/command line
把狭义单词 <cword> 写到 搜索命令行
/<C-R><C-A> : Pull <CWORD> onto search/command line
把广义单词 <cWORD> 写到 搜索命令行
:set ignorecase : you nearly always want this
搜索时忽略大小写
:syntax on : colour syntax in Perl,HTML,PHP etc
在 Perl,HTML,PHP 等中进行语法着色
:h regexp<C-D> : type control-D and get a list all help topics containing
按下 control-D 键即可得到包含有 regexp 的帮助主题的列表
regexp (plus use TAB to Step thru list)
(使用TAB可以实现帮助的自动补齐)
—————————————-
# MAKE IT EASY TO UPDATE/RELOAD _vimrc
# 使更新 _vimrc 更容易
:nmap ,s :source $VIM/_vimrc
# 译释:nmap 是绑定一个在normal模式下的快捷键
:nmap ,v :e $VIM/_vimrc
# 译释:在normal模式下,先后按下 ,s 两个键执行_vimrc,而 ,v 则是编辑_vimrc

—————————————-

#VISUAL MODE (easy to add other HTML Tags)
# visual 模式 (例子是:轻松添加其他的 HTML Tags)
:vmap sb “zdi<b><C-R>z</b><ESC> : wrap <b></b> around VISUALLY selected Text
在visual模式下选中的文字前后分别
加上<b>和</b>
:vmap st “zdi<?= <C-R>z ?><ESC> : wrap <?= ?> around VISUALLY selected Text
在visual模式下选中的文字前后分别加
上<?= 和 ?>

—————————————-

# Exploring
# 文件浏览
:Exp(lore) : file explorer note capital Ex
开启目录浏览器,注意首字母E是大写的
:Sex(plore) : file explorer in split window
在一个分割的窗口中开启目录浏览器
:ls : list of buffers
显示当前buffer的情况
:cd .. : move to parent directory
进入父目录
:args : list of files
显示目前打开的文件
:lcd %:p:h : change to directory of current file
更改到当前文件所在的目录
:autocmd BufEnter * lcd %:p:h : change to directory of current file
automatically (put in _vimrc)
自动更改到当前文件所在的目录 (放到 _vimrc)

—————————————-

# Buffer Explorer (Top Ten Vim Script)
# 缓冲区(buffer)浏览器 (第三方的一个最流行的脚本)
# needs bufexplorer.vim http://www.vim.org/script.php?script_id=42
# 需要下载 bufexplorer.vim
\be : buffer explorer list of buffers
在缓冲区浏览器中打开缓冲区列表
\bs : buffer explorer (split window)
以分割窗口的形式打开缓冲区浏览器

—————————————-

# Changing Case
guu : lowercase line
行小写
gUU : uppercase line
行大写
Vu : lowercase line
行小写
VU : uppercase line
行大写
g~~ : flip case line
行翻转
vEU : Upper Case Word
字大写(狭义字)
vE~ : Flip Case Word
字翻转(狭义字)
ggguG : lowercase entire file
把整个文章全部小写

# Titlise Visually Selected Text (map for .vimrc)
vmap ,c :s/\<\(.\)\(\k*\)\>/\u\1\L\2/g<CR>
# Uppercase first letter of sentences
# 大写所有句子的第一个字母
:%s/[.!?]\_s\+\a/\U&\E/g

—————————————-

gf : open file name under cursor (SUPER)
取当前光标处的广义字作为文件名,然后试图打开它!
ga : display hex,ascii value of char under cursor
显示光标处字符的ascii,hex,oct,…
ggVGg? : rot13 whole file
用rot13编码整个文件
ggg?G : rot13 whole file (quicker for large file)
用rot13编码整个文件(对大文件更快一些)
:8 | normal VGg? : rot13 from line 8
从第8行开始,用rot13编码后面的文本
:normal 10GVGg? : rot13 from line 8
从第8行开始,用rot13编码后面的文本

# 【关于rot13――谁让英文是偶数个字母啊】
# ROT13 是一种简单的编码,它把字母分成前后两组,每组13个,编码和解码
# 的算法相同,仅仅交换字母的这两个部分,即:[a..m] –> [n..z] 和 [n..z]
# –> [a..m] 。 ROT13 用简易的手段使得信件不能直接被识别和阅
# 读,也不会被搜索匹配程序用通常的方法直接找到。经常用于 USENET 中发表一
# 些攻击性或令人不快的言论或有简单保密需要的文章。
# 由于 ROT13 是自逆算法,所以,解码和编码是同一个过程。

<C-A>,<C-X> : increment,decrement number under cursor
增加,减少光标处的狭义字所表示的数字
win32 users must remap CNTRL-A
Win32的用户可能需要重新定义一下Ctrl-A
<C-R>=5*5 : insert 25 into text (mini-calculator)
插入25 (一个迷你计算器)

—————————————-

# Makes all other tips superfluous
:h 42 : also http://www.google.com/search?q=42
:h holy-grail
:h!

—————————————-

# Markers & moving about
# 标记和移动
‘. : jump to last modification line (SUPER)
跳到最后修改的那一行 (超级有用)
`. : jump to exact spot in last modification line
不仅跳到最后修改的那一行,还要定位到修改点
g; : cycle thru recent changes (oldest first) (new in vim6.3)
循环跳转修改点(从最老的修改点开始) (vim6.3中新增)
g, : reverse direction (new in vim6.3)
反向循环跳转修改点 (vim6.3中新增)

:changes
:h changelist : help for above
<C-O> : retrace your movements in file (starting from most recent)
依次沿着你的跳转记录向回跳 (从最近的一次开始)
<C-I> : retrace your movements in file (reverse direction)
依次沿着你的跳转记录向前跳
:ju(mps) : list of your movements
列出你跳转的足迹
:help jump-motions
:history : list of all your commands
列出历史命令记录
:his c : commandline history
命令行命令历史
:his s : search history
搜索命令历史
q/ : Search history Window
搜索命令历史的窗口
q: : commandline history Window
命令行命令历史的窗口
:<C-F> : history Window
历史命令记录的窗口
—————————————-
# Abbreviations & maps
# # 缩写和键盘映射
:map <f7> :’a,’bw! c:/aaa/x

10月 24th, 2005我的.vimrc备份

” An example for a vimrc file.

” Maintainer: Bram Moolenaar <
Bram@vim.org>
” Last change: 2002 May 28

” To use it, copy it to
” for Unix and OS/2: ~/.vimrc
” for Amiga: s:.vimrc
” for MS-DOS and Win32: $VIM\_vimrc
” for OpenVMS: sys$login:.vimrc

” When started as “evim”, evim.vim will already have done these settings.
if v:progname =~? “evim”
finish
endif

” Use Vim settings, rather then Vi settings (much better!).
” This must be first, because it changes other options as a side effect.
set nocompatible

” allow backspacing over everything in insert mode
set backspace=indent,eol,start

“set autoindent ” always set autoindenting on
if has(”vms”)
set nobackup ” do not keep a backup file, use versions instead
else
set backup ” keep a backup file
endif
set history=50 ” keep 50 lines of command line history
set ruler ” show the cursor position all the time
set showcmd ” display incomplete commands
set incsearch ” do incremental searching

” For Win32 GUI: remove ‘t’ flag from ‘guioptions’: no tearoff menu entries
” let &guioptions = substitute(&guioptions, “t”, “”, “g”)

” Don’t use Ex mode, use Q for formatting
map Q gq

“###################################################################
“@author - huangwei
“@created on - 2005-10-20
“@last modified - 10:16 2005-10-21
“——————————————————————-
” F2 - write file without confirmation
” F3 - call file explorer Ex
” F4 - show Taglist
” F5 - automatically insert current time to current location
” F8 - automatically complete keywords
” F12 - switch between windows
“——————————————————————-
” for quick save in normal mode
map <silent> <F2> :write<CR>
map <silent> <F3> :Explore<CR>

” switch between windows
map <silent> <F12> <C-W>w

” for quick save in edit mode
imap <F2> <ESC><F2>a

” according to SMTH’s VIM board
nnoremap <silent> <F4> :Tlist<CR>

” let F5 insert current time to current location.
map <F5> i<C-R>=strftime(”%H:%M %Y-%m-%d”)<ESC><ESC>
” map! <F5> <C-R>=strftime(”%H:%M %Y-%m-%d”)<RETURN>

“mouse function support
set mouse=a

” set auto shift width
” set shiftwidth=4

” disable auto backup
set nobackup

” set root directory of DICTIONARY, whose value by default is
” NULL to Linux
” /cygdrive/c to cygwin
” C: to Win32
let g:DIC_ROOT_DIR=”"

” set default ‘dictionary’ path
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/words”
” more and more place including such keyword
set iskeyword+=-
” Let F8 made dictionary automatically complete keywords.
map! <F8> <C-X><C-K>

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”*
” autocmd FileType * set comments&
“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”C

autocmd FileType c call C()
fun! C()
set cindent
set comments=sr:/*,mb:*,el:*/,://
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab
set tags+=/usr/include/tags
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/C,” . tmpvar
unlet tmpvar
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
map! =for for(i = 0; i < ; i++){<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
endfun ” endfun C

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"CPP
autocmd FileType cpp call CPP()
fun! CPP()
set cindent
set comments=sr:/*,mb:*,el:*/,://
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab
set tags+=/usr/include/tags
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/CPP,” . tmpvar
unlet tmpvar
endfun ” endfun CPP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"PERL
autocmd FileType sed,awk,perl call PERL()
fun! PERL()
set cindent
set commentstring=\ \ #\ %s\ ” <SPACE>
set foldcolumn=3
” control-c comments block
vmap <C-C> :s/^/#/g<enter>
” control-x uncomments block
vmap <C-X> :s/^#//g<enter>
” append dictionary
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/PERL,” . tmpvar
unlet tmpvar
endfun ” endfun PERL

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"HTML
autocmd FileType html call HTML()
fun! HTML()
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/HTML,” . tmpvar
unlet tmpvar
endfun ” endfun HTML
“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JAVA
autocmd FileType java call JAVA()
fun! JAVA()
set cindent
set commentstring=\ \ //\ %s\ ” <SPACE>
set foldcolumn=3
set expandtab tags+=${JAVA_HOME}/src/tags
” control-c comments block
vmap <C-C> :s/^/\/\//g<enter>
” control-x uncomments block
vmap <C-X> :s/^\/\///g<enter>
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/JAVA,” . tmpvar
unlet tmpvar
map! =for for(int i = 0; i < ; i++){<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
map! =psvm public static void main(String [] args){<RETURN>
map! =soutn System.out.println(
map! =sout System.out.print(
map! =try try{<RETURN>}catch(Exception e){<RETURN>System.out.println(e.getMessage());<RETURN>}<ESC>kkko
map! =tryb try{<ESC>:/^[ \t]*$/<RETURN>ddko}catch(Exception e){<RETURN>System.out.println(e.getMessage());<RETURN>}<ESC>k
endfun ” endfun JAVA

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JSP
autocmd FileType jsp call JSP()
fun! PHP()
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/JSP,” . tmpvar
unlet tmpvar
endfun ” endfun JSP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"JS
autocmd FileType js call JS()
fun! JS()
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/JS,” . tmpvar
unlet tmpvar
endfun ” endfun JS

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"PHP
autocmd FileType php call PHP()
fun! PHP()
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/PHP,” . tmpvar
unlet tmpvar
endfun ” endfun PHP

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"XML
autocmd FileType xml call XML()
fun! XML()
let tmpvar=&dictionary
execute “:set dictionary=”.g:DIC_ROOT_DIR.”/usr/share/dict/XML,” . tmpvar
unlet tmpvar
endfun ” endfun XML
“##################################################################

” This is an alternative that also works in block mode, but the deleted
” text is lost and it only works for putting the current register.
“vnoremap p “_dp

” Switch syntax highlighting on, when the terminal has colors
” Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has(”gui_running”)
syntax on
set hlsearch
endif

” Only do this part when compiled with support for autocommands.
if has(”autocmd”)

” Enable file type detection.
” Use the default filetype settings, so that mail gets ‘tw’ set to 72,
” ‘cindent’ is on in C files, etc.
” Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

” For all text files set ‘textwidth’ to 78 characters.
autocmd FileType text setlocal textwidth=78

” When editing a file, always jump to the last known cursor position.
” Don’t do it when the position is invalid or when inside an event handler
” (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line(”‘\”") > 0 && line(”‘\”") <= line(”$”) |
\ exe “normal g`\”" |
\ endif

endif ” has(”autocmd”)


© 2007 猪在笑 | iKon Wordpress Theme by TextNData | Powered by Wordpress | rakCha web directory
登录 | 访问数171995 | 水木BLOG | 水木社区 | 关于我们 | Blog论坛 | 法律声明 | 隐私权保护 | 京ICP证050249号
水木社区Blog系统是基于KBS系统WordPress MU架构的