[分享] Vim 配置文件(_vimrc)

Vim、Emacs配置和使用
回复
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

[分享] Vim 配置文件(_vimrc)

#1

帖子 leal » 2006-05-14 21:09

Windows 和 Linux 下适用,无需更改,除了要重新设置用到的程序路径;
GUI 和 Console 或终端下适用,无需更改。

可在我的站点上下载/查看: _vimrc, _vimrc.txt, _vimrc.html
http://linxiao.li.googlepages.com/vim
http://www.leal.cn

使用前需要先下载一些 scripts, 见 _vimrc 或 plugin_list.txt, plugin_list.html
同上网址。

使用前先查看 vimrc 的使用说明。

Good Luck!


附 _vimrc

"=====================================================================================
" Description: My daily vimrc with dozens of plugins.
" Originally derived from MetaCosm's http://vi-improved.org/vimrc.php
" Last Change: 0 14/05/2006 20:54:07 Leal@RAINT:_vimrc
"
" Author: Leal <linxiao.li AT gmail DOT com>
" http://www.leal.cn
" Version: 1.0065
"
" Usage: 1. Prepare necessary dirs and files
" $VIMDATA X:\Vim\vimdata on Win, ~/vimdata on Linux
" |
" |-- temp to put swap files <DIR>
" |-- backup to put backup files <DIR>
" |-- diary to save calendar.vim's diaries <DIR>
" |-- GetLatest to save GetLatestVimScripts.vim's <DIR>
" | |
" | `-- GetLatestVimScripts.dat to store GLVS's items
" |
" |-- _vim_fav_files to store favmenu.vim's items
" `-- _vim_mru_files to store mru.vim's items
"
" 2. Get all scripts you favor on www.vim.org better with GLVS
"
" 3. Get all needed utilities, especially on Windows, e.g.
" wget -- WGET for Windows (win32) http://users.ugent.be/~bpuype/wget/
" ctags -- Exuberant Ctags http://ctags.sf.net/
"
" 4. If you have no idea of some option, just press K (<S-k>) on it.
"
" 5. HTML file is produced with :TOhtml, with colo default.
"
"=====================================================================================

"-------------------------------------------------------------------------------------
" TODO List
"-------------------------------------------------------------------------------------
" 1. Install Chinese Vim help helplang -> cn

"-------------------------------------------------------------------------------------
" general
"-------------------------------------------------------------------------------------
set nocompatible " use vim as vim, should be put at the very start
set history=1000 " lines of Ex-mode commands, search history
set browsedir=buffer " use directory of the related buffer for file browser
set clipboard+=unnamed " use clipboard register '*' for all y, d, c, p ops
set viminfo+=! " make sure it can save viminfo
set isk+=$,%,#,- " none of these should be word dividers
set confirm " raise a dialog confirm whether to save changed buffer
set ffs=unix,dos,mac " favor unix ff, which behaves good under bot Winz & Linux
set fenc=utf-8 " default fileencoding
set fencs=utf-8,ucs-bom,euc-jp,gb18030,gbk,gb2312,cp936
map Q gq
" don't use Ex-mode, use Q for formatting
filetype on " enable file type detection
filetype plugin on " enable loading the plugin for appropriate file type

"-------------------------------------------------------------------------------------
" platform dependent
"-------------------------------------------------------------------------------------
if has("win32")
let $VIMDATA = $VIM.'/vimdata'
let $VIMFILES = $VIM.'/vimfiles'
let PYTHON_BIN_PATH = 'd:/foo/python/python.exe' " ensure the path right
else
let $VIMDATA = $HOME.'/vimdata'
let $VIMFILES = $HOME.'/.vim'
let PYTHON_BIN_PATH = '/usr/bin/python'
set guifont=courier\ 10
endif

"-------------------------------------------------------------------------------------
" path/backup
"-------------------------------------------------------------------------------------
set backup " make backup file and leave it around
set backupdir=$VIMDATA/backup " where to put backup file
set directory=$VIMDATA/temp " where to put swap file
set runtimepath+=$VIMDATA " add this path to rtp, support GetLatestVimScripts.vim
set path=.,/usr/include/*,, " where gf, ^Wf, :find will search
set tags=./tags,tags,$VIMRUNTIME/doc/tags,$VIMFILES/doc/tags " tags files CTRL-] uses
set makeef=error.err " the errorfile for :make and :grep

"-------------------------------------------------------------------------------------
" colors
"-------------------------------------------------------------------------------------
set background=dark " use a dark background
syntax on " syntax highlighting

"-------------------------------------------------------------------------------------
" gui-only settings
"-------------------------------------------------------------------------------------
if has("gui_running")
colo inkpot " colorscheme, inkpot.vim
set lines=40 " window tall and wide, only if gui_running,
set columns=120 " or vim under console behaves badly
endif

"-------------------------------------------------------------------------------------
" Vim UI
"-------------------------------------------------------------------------------------
set linespace=1 " space it out a little more (easier to read)
set wildmenu " type :h and press <Tab> to look what happens
set ruler " always show current position along the bottom
set cmdheight=2 " use 2 screen lines for command-line
set lazyredraw " do not redraw while executing macros (much faster)
set nonumber " don't print line number
set hid " allow to change buffer without saving
set backspace=2 " make backspace work normal
set whichwrap+=<,>,h,l " allow backspace and cursor keys to wrap
set mouse=a " use mouse in all modes
set shortmess=atI " shorten messages to avoid 'press a key' prompt
set report=0 " tell us when anything is changed via :...
set fillchars=vert:\ ,stl:\ ,stlnc:\
" make the splitters between windows be blank

"-------------------------------------------------------------------------------------
" visual cues
"-------------------------------------------------------------------------------------
set showmatch " show matching paren
set matchtime=5 " 1/10 second to show the matching paren
set nohlsearch " do not highlight searched for phrases
set incsearch " BUT do highlight where the so far typed pattern matches
set scrolloff=10 " minimal number of screen lines to keep above/below the cursor
set novisualbell " use visual bell instead of beeping
set noerrorbells " do not make noise
set laststatus=2 " always show the status line
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ " what to show while :set list
set statusline=%{VimBuddy()}\ %F%m%r%h%w\ [%{&ff}]\ [%Y]\ [\%03.3b\ \%02.2B]\ [%02v\ %03l\ %L\ %p%%]

"-------------------------------------------------------------------------------------
" text formatting/layout
"-------------------------------------------------------------------------------------
set ai " autoindent
set si " smartindent
set cindent " do C-style indenting
set fo=tcrqn " see help (complex)
set tabstop=4 " tab spacing (settings below are just to unify it)
set softtabstop=4 " unify
set shiftwidth=4 " unify
set noexpandtab " real tabs please!
set smarttab " use tabs at the start of a line, spaces elsewhere
set nowrap " do not wrap lines
set formatoptions+=mM " so that vim can reformat multibyte text (e.g. Chinese)

"-------------------------------------------------------------------------------------
" folding
"-------------------------------------------------------------------------------------
set foldenable " turn on folding
set foldmethod=indent " make folding indent sensitive
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

"-------------------------------------------------------------------------------------
" plugin - a.vim
"-------------------------------------------------------------------------------------
" alternate files quickly (.c --> .h etc)

"-------------------------------------------------------------------------------------
" plugin - c.vim
"-------------------------------------------------------------------------------------
"set makeprg=g++\ %
let g:C_AuthorName = 'Leal'
let g:C_Email = 'linxiao.li NOSPAM gmail DOT com'

"-------------------------------------------------------------------------------------
" plugin - runscript.vim (for Python)
"-------------------------------------------------------------------------------------
"let PYTHON_BIN_PATH = ...

"-------------------------------------------------------------------------------------
" plugin - calendar.vim
"-------------------------------------------------------------------------------------
let g:calendar_diary = $VIMDATA.'/diary' " where to store your diary

"-------------------------------------------------------------------------------------
" plugin - mru.vim (most recently used files)
"-------------------------------------------------------------------------------------
let MRU_File = $VIMDATA.'/_vim_mru_files' " which file to save mru entries
let MRU_Max_Entries = 20 " max mru entries in _vim_mru_files

"-------------------------------------------------------------------------------------
" plugin - favmenu.vim
"-------------------------------------------------------------------------------------
let FAV_File = $VIMDATA.'/_vim_fav_files' " which file to save favorite entries

"-------------------------------------------------------------------------------------
" plugin - minibufexpl.vim
"-------------------------------------------------------------------------------------
let g:miniBufExplTabWrap = 1 " make tabs show complete (no broken on two lines)
let g:miniBufExplModSelTarget = 1

"-------------------------------------------------------------------------------------
" plugin - taglist.vim
"-------------------------------------------------------------------------------------
if has("win32")
let Tlist_Ctags_Cmd = $VIMFILES.'/ctags.exe' " location of ctags tool
else
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
endif

let Tlist_Sort_Type = "name" " order by
let Tlist_Use_Right_Window = 1 " split to the right side of the screen
let Tlist_Compart_Format = 1 " show small meny
let Tlist_Exist_OnlyWindow = 1 " if you are the last, kill yourself
let Tlist_File_Fold_Auto_Close = 0 " do not close tags for other files
let Tlist_Enable_Fold_Column = 0 " do not show folding tree

"-------------------------------------------------------------------------------------
" plugin - matchit.vim
"-------------------------------------------------------------------------------------
let b:match_ignorecase = 1

"-------------------------------------------------------------------------------------
" plugin - supertab.vim
"-------------------------------------------------------------------------------------
" <Tab> has been mapped to SuperTab() func in that plugin

"-------------------------------------------------------------------------------------
" plugin - timestamp.vim
"-------------------------------------------------------------------------------------
let g:timestamp_regexp = '\v\C%(<Last %([cC]hanged?|[Mm]odified):\s+)@<=.*$'
let g:timestamp_rep = '%w %d/%m/%Y %H:%M:%S #u@#h:#f'
augroup TimeStampHtml
au filetype html let b:timestamp_regexp = '\v\C%(\<!-- Timestamp:\s{-1,})@<=.{-}%(\s*--\>)@='
au filetype html let b:timestamp_rep = '%a %d/%m/%Y %r #u@#h:#f'
augroup END

"-------------------------------------------------------------------------------------
" plugin - perl-support.vim
"-------------------------------------------------------------------------------------
let g:Perl_AuthorName = 'Leal'
let g:Perl_Email = 'linxiao.li NOSPAM gmail DOT com'
let tlist_perl_settings = 'perl;c:constants;l:labels;s:subroutines;d:POD'

"-------------------------------------------------------------------------------------
" utilities
"-------------------------------------------------------------------------------------
" select range, then hit :SuperRetab($width) - by p0g and FallingCow
fu! SuperRetab(width) range
sil! exe a:firstline . ',' . a:lastline . 's/\v%(^ *)@<= {'. a:width .'}/\t/g'
endf

" bind :CD to :cd %:h, then change cwd to the dir that includes current file
sil! com -nargs=0 CD exe 'cd %:h'

"TODO just do it
fu! AddLineNo(isVM)
if(a:isVM == 1)
sil! exe 's/^/\=' . strpart((line('.')-line("'<")+1)." ", 0, 4)
else
sil! exe '%s/^/\=' . strpart(line('.')." ", 0, 4)
endif
endf
" add line number befor each line of the text
" :g/^/exec "s/^/".strpart(line(".")." ", 0, 4)
" :%s/^/\=strpart(line('.')." ", 0, 4)
" visual mode
" :s/^/\=strpart((line('.')-line("'<")+1)." ", 0, 4)

" XML support, e.g. element,,,<CR> -> <element> </element>
" Bart van Deenen , www.vandeenensupport.com
fu! MakeElement()
if match(getline('.'),'^\s*>\s*$') == -1
"the deleted word was not alone on the line
let @w = "i<pla</pa>F<i"
else
"the deleted word was on it's own on the line
let @w = "i<po</pa>kA"
endif
endf

" include colon(58) for namespaces in xsl for instance
"setlocal iskeyword=@,48-57,_,192-255,58
inoremap <buffer> ,,, ><Esc>db:call MakeElement()<enter>@w

"-------------------------------------------------------------------------------------
" mappings
"-------------------------------------------------------------------------------------
map <right> <ESC>:MBEbn<RETURN>
" -> switches buffers
map <left> <ESC>:MBEbp<RETURN>
" <- switches buffers
map <up> <ESC>:Sex<RETURN><ESC><C-W><C-W>
" up arrow to bring up a file explorer
map <down> <ESC>:Tlist<RETURN>
" down arrow to bring up the taglist
map <A-i> i <ESC>r
" Alt-i inserts a single char, and back to normal
map <F3> <ESC>ggVG:call SuperRetab()<left>
map <F4> ggVGg?
" Rot13 encode the current file

"noremap <silent> <C-F11> :cal VimCommanderToggle()<CR>

" plugin - php_console.vim
"map <F5> :call ParsePhpFile()<cr> " call function in normal mode
"imap <F5> <ESC>:call ParsePhpFile()<cr> " call function in insert mode

"-------------------------------------------------------------------------------------
" autocommands
"-------------------------------------------------------------------------------------
au BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full)
au BufNewFile,BufRead *.asp :set ft=jscript " all my .asp files ARE jscript
au BufNewFile,BufRead *.tpl :set ft=html " all my .tpl files ARE html

" ftplugin - python_fold - $VIMFILES/ftplugin/python_fold.vim
" add names in pydiction to autocomplete class or object's class, attribute or method
au FileType python set complete+=k$VIMFILES/dict/pydiction isk+=.,(
"au FileType python pyfile $VIMFILES/plugin/pyCallTips.py
au FileType python source $VIMFILES/plugin/python.vim
"au FileType java source $VIMFILES/ftplugin/JavaRun.vim
"au FileType php set complete+=k$VIMFILES/dict/php.dict isk+=.,(
au FileType text setlocal textwidth=78

"-------------------------------------------------------------------------------------
" highlight active line in normal mode, Vim7 don't need this
"-------------------------------------------------------------------------------------
"highlight CurrentLine guibg=darkgrey guifg=white ctermbg=darkgrey ctermfg=white
"au! Cursorhold * exe 'match CurrentLine /\%' . line('.') . 'l.*/'
"set ut=19

"-------------------------------------------------------------------------------------
" stuffs I don't like
"-------------------------------------------------------------------------------------
"set ignorecase -- turns out, I like case sensitivity
"set list -- turns out, do not display unprintable characters such as Tab
"autocmd GUIEnter * :simalt ~x -- having it auto maximize the screen is annoying
"autocmd BufEnter * :lcd %:p:h -- switch to current dir (breaks some scripts)

"-------------------------------------------------------------------------------------
" useful abbrevs
"-------------------------------------------------------------------------------------
iab xasp <%@language=jscript%><CR><%<CR><TAB><CR><BS>%><ESC><<O<TAB>
iab xdate <c-r>=strftime("%m/%d/%y %H:%M:%S")<cr>

"-------------------------------------------------------------------------------------
" customize cursor color to indicate IM is on
"-------------------------------------------------------------------------------------
if has('multi_byte_ime')
hi Cursor guifg=NONE guibg=Green
hi CursorIM guifg=NONE guibg=Blue
endif

"-------------------------------------------------------------------------------------
" TVO defaults - otl.vim
"-------------------------------------------------------------------------------------
let otl_install_menu =1
let no_otl_maps =0
let no_otl_insert_maps =0

let otl_bold_headers =0
let otl_use_thlnk =0

let g:otl_use_viki =0
let maplocalleader =","

map <c-w><c-f> :FirstExplorerWindow<cr>
map <c-w><c-b> :BottomExplorerWindow<cr>
map <c-w><c-t> :WMToggle<cr>

let g:winManagerWidth = 35
let g:winManagerWindowLayout = 'TodoList'

let g:tskelDir = $VIMFILES."/skeletons"

"-------------------------------------------------------------------------------------
" vim: set et ft=vim tw=98 path+=$VIMFILES/*:
用心×恒 | 豆瓣 | 门户 | Blog
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#2

帖子 eexpress » 2006-05-14 21:57

复杂的。定义这么多。 :lol:
● 鸣学
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#3

帖子 leal » 2006-05-14 23:33

哈哈 许多 是插件是设置 , Vim本身的估计8 9十行吧
用心×恒 | 豆瓣 | 门户 | Blog
terry6394
帖子: 48
注册时间: 2006-01-02 12:40

#4

帖子 terry6394 » 2006-05-14 23:53

主要的功能说一说吧。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#5

帖子 eexpress » 2006-05-15 11:22

我只用了这一点。

代码: 全选

$ cat .vimrc
set fencs=utf-8,ucs-bom,euc-jp,gb18030,gbk,gb2312,cp936
syntax on

set guifont=courier\ 10 这个字体名是不是少了? 系统显示是Courier 10 Pitch。怎么确定应该用你说的这个的。
● 鸣学
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#6

帖子 leal » 2006-05-15 12:49

可以到 Vim 的 编辑 -> 选择字体 里看看

set guifont = courier\ 10
字体名是 courier 字体大小为 10

set guifont = Courier\ 10\ Pitch\ 10
才是选择 后面的字体啊
用心×恒 | 豆瓣 | 门户 | Blog
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#7

帖子 leal » 2006-05-15 19:53

terry6394 写了:主要的功能说一说吧。
查看
http://linxiao.li.googlepages.com/vim  上的plugin_list.txt一文『提供Html」

另外看看 _vimrc 里的函数 都有说明

如果不涉及编程,许多配置都可以去掉。

日常用主要的增强 
自动加时间戳
<Tab>和Shift-<Tab> 键代替 Ctr-P Ctr-N补全,方便快捷
/ 搜索时 使用 <Tab> 键可自动补全关键字
YankRing 粘贴拷贝历史
:CD 命令 将工作路径切换到 当前缓冲文件 所在的目录等同于 :cd %:h
还有其它一堆
用心×恒 | 豆瓣 | 门户 | Blog
muyufan
帖子: 95
注册时间: 2006-02-14 1:50
联系:

#8

帖子 muyufan » 2006-05-23 14:30

英文的说明 偶看不懂
firefly
帖子: 22
注册时间: 2006-05-23 1:52

#9

帖子 firefly » 2006-06-26 13:00

不用这么麻烦,只需在/usr/share/vim下的 vimrc中添加如下一行
source $VIMRUNTIME/vimrc_example.vim

如果想用windows的快捷键,如(ctrl+c,ctrl+v,ctrl+z,shift+上 等),可加上如下两行:

source $VIMRUNTIME/mswin.vim

behave mswin

这样配置一下,就已经很好用了,不用把太多时间花在它的配置上,毕竟只是一个编辑器而已 :roll:
头像
putao
帖子: 14
注册时间: 2006-05-24 13:58
来自: ICCAS

#10

帖子 putao » 2006-06-29 17:02

firefly 写了:不用这么麻烦,只需在/usr/share/vim下的 vimrc中添加如下一行
source $VIMRUNTIME/vimrc_example.vim

:roll:
或者mv vimrc_example.vim ~/.vimrc
就已经基本够用了,以后需要什么慢慢往里加吧
Lanczos 迭代中...
头像
zhoufcumt
帖子: 14
注册时间: 2010-04-15 20:01

Re:

#11

帖子 zhoufcumt » 2010-10-23 11:16

firefly 写了:不用这么麻烦,只需在/usr/share/vim下的 vimrc中添加如下一行
source $VIMRUNTIME/vimrc_example.vim

如果想用windows的快捷键,如(ctrl+c,ctrl+v,ctrl+z,shift+上 等),可加上如下两行:

source $VIMRUNTIME/mswin.vim

behave mswin

这样配置一下,就已经很好用了,不用把太多时间花在它的配置上,毕竟只是一个编辑器而已 :roll:
我试了下,快捷键不能用啊,ctrl+c,ctrl+v没反应啊,麻烦解决下
Gamit/Globk ing
头像
zhoufcumt
帖子: 14
注册时间: 2010-04-15 20:01

Re:

#12

帖子 zhoufcumt » 2010-10-23 11:29

firefly 写了:不用这么麻烦,只需在/usr/share/vim下的 vimrc中添加如下一行
source $VIMRUNTIME/vimrc_example.vim

如果想用windows的快捷键,如(ctrl+c,ctrl+v,ctrl+z,shift+上 等),可加上如下两行:

source $VIMRUNTIME/mswin.vim

behave mswin

这样配置一下,就已经很好用了,不用把太多时间花在它的配置上,毕竟只是一个编辑器而已 :roll:
我刚试了下,ctrl+a全选命令可以用,但是ctrl+c,ctrl+v,ctrl+x都不能用啊
下面的是mswin.vim里面的代码
" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G

" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y

" CTRL-V and SHIFT-Insert are Paste
map <C-V> "+gP
map <S-Insert> "+gP

cmap <C-V> <C-R>+
cmap <S-Insert> <C-R>+
xnoremap <C-A> <C-C>ggVG
是不是ctrl+c,ctrl+v的代码有问题,需要改下啊
Gamit/Globk ing
回复