- 论坛徽章:
- 0
|
对于UNIX/linux初学者来说,在用VI来写程序的时候,总是发现不如WINDOWS下面的那些专业的文本编辑器那样高亮关键字,自动对齐等等...其实我们只要对VI进行一些简单的配置,即可实现很多美妙的功能,通过下面的配置,你就会发现,VI的灵活性几乎超乎于你的想象...
一般来说,我们可以在当前用户的根目录下创建一个.vimrc的隐藏文件(当然,也可以不隐藏,看个人的习惯),方法如下:
$ touch ~/.vimrc
符号~(可能很多人知道这个符号什么意思,却不会读,这个符号叫鄂化符号)在这里指当前用户的根目录,在创建新用户的时候会在/etc/passwd文件中的第六个字段说明主目录(如果你创建用户的时候没有指定根目录,默认为:/home/usrname),下面我们具体来看看.vimrc的配置...
$ vi ~/.vimrc
你可以依自己的爱好选择如下内容copy到.vimrc中:
[只是为了方便写C程序,提供自动格式化,使用C风格的自动缩进,tab设置为4个space...]
set fenc=utf-8 "设定默认解码
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
set nocp "或者 set nocompatible 用于关闭VI的兼容模式
set number "显示行号
set ai "或者 set autoindent vim使用自动对齐,也就是把当前行的对齐格式应用到下一行
set si "或者 set smartindent 依据上面的对齐格式,智能的选择对齐方式
set tabstop=4 "设置tab键为4个空格
set sw=4 "或者 set shiftwidth 设置当行之间交错时使用4个空格
set ruler "设置在编辑过程中,于右下角显示光标位置的状态行
set incsearch "设置增量搜索,这样的查询比较smart
set showmatch "高亮显示匹配的括号
set matchtime=5 "匹配括号高亮时间(单位为 1/10 s) set ignorecase "在搜索的时候忽略大小写
syntax on "高亮语法
[下面是网上比较流行的一些.vimrc]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 设定默认解码
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" history文件中需要记录的行数
set history=100
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 与windows共享剪贴板
set clipboard+=unnamed
" 侦测文件类型
filetype on
" 载入文件类型插件
filetype plugin on
" 为特定文件类型载入相关缩进文件
filetype indent on
" 保存全局变量
set viminfo+=!
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 语法高亮
syntax on
" 高亮字符,让其不受100列限制
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%101v.*'
" 状态行颜色
highlight StatusLine guifg=SlateBlue guibg=Yellow
highlight StatusLineNC guifg=Gray guibg=White
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 不要备份文件(根据自己需要取舍)
set nobackup
" 不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide
" 字符间插入的像素行数目
set linespace=0
" 增强模式中的命令行自动完成操作
set wildmenu
" 在状态行上显示光标所在位置的行号和列号
set ruler
set rulerformat=%20(%2*%,h,l
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
" 不让vim发出讨厌的滴滴声
set noerrorbells
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=5
" 在搜索的时候忽略大小写
set ignorecase
" 不要高亮被搜索的句子(phrases)
set nohlsearch
" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch
" 输入:set list命令是应该显示些啥?
set listchars=tab:\|\ ,trail:.,extends:>,precedes: 'o'>o-->
autocmd FileType java,c,cpp,cs vmap ''>o*/
autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") :call CompileRunGcc()
func! CompileRunGcc()
exec "w"
exec "!gcc % -o % :call CompileRunGpp()
func! CompileRunGpp()
exec "w"
exec "!g++ % -o % @=((foldclosed(line('.'))
" minibufexpl插件的一般设置
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
[下面这个被称为史上最强]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" _
" __ | \
" / | /
" \__ | \
" by Amix -
http://amix.dk/
"
" Maintainer: Amir Salihefendic
" Version: 2.7
" Last Change: 12/10/06 00:09:21
"
" Sections:
" ----------------------
"
General
"
Colors and Fonts
"
Fileformats
"
VIM userinterface
"
Statusline
"
Visual
"
Moving around and tabs
"
General Autocommands
"
Parenthesis/bracket expanding
"
General Abbrevs
"
Editing mappings etc.
"
Command-line config
"
Buffer realted
"
Files and backups
"
Folding
"
Text options
"
Indent
"
Spell checking
"
Plugin configuration
"
Yank ring
"
File explorer
"
Minibuffer
"
Tag list (ctags) - not used
"
LaTeX Suite things
"
Filetype generic
"
Todo
"
VIM
"
HTML related
"
Ruby & PHP section
"
Python section
"
Cheetah section
"
Vim section
"
Java section
"
JavaScript section
"
C mappings
"
SML
"
Scheme bindings
"
Snippets
"
Python
"
javaScript
"
Cope
"
MISC
"
" Tip:
" If you find anything that you can't understand than do this:
" help keyword OR helpgrep keywords
" Example:
" Go into command-line mode and type helpgrep nocompatible, ie.
" :helpgrep nocompatible
" then press c to see the results, or :botright cw
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Get out of VI's compatible mode..
set nocompatible
"Sets how many lines of history VIM har to remember
set history=400
"Enable filetype plugin
filetype plugin on
filetype indent on
"Set to auto read when a file is changed from the outside
set autoread
"Have the mouse enabled all the time:
set mouse=a
"Set mapleader
let mapleader = ","
let g:mapleader = ","
"Fast saving
nmap leader>w :w!cr>
nmap leader>f :findcr>
"Fast reloading of the .vimrc
map leader>s :source ~/vim_local/vimrccr>
"Fast editing of .vimrc
map leader>e :e! ~/vim_local/vimrccr>
"When .vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/vim_local/vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable syntax hl
syntax enable
"Set font to Monaco 10pt
if MySys() == "mac"
set gfn=Bitstream\ Vera\ Sans\ Mono:h14
set nomacatsui
set termencoding=macroman
elseif MySys() == "linux"
set gfn=Monospace\ 11
endif
if has("gui_running")
set guioptions-=T
let psc_style='cool'
colorscheme ps_color
else
set background=dark
colorscheme zellner
endif
"Some nice mapping to switch syntax (useful if one mixes different languages in one file)
map leader>1 :set syntax=cheetahcr>
map leader>2 :set syntax=xhtmlcr>
map leader>3 :set syntax=pythoncr>
map leader>4 :set ft=javascriptcr>
map leader>$ :syntax sync fromstartcr>
autocmd BufEnter * :syntax sync fromstart
"Highlight current
if has("gui_running")
set cursorline
hi cursorline guibg=#333333
hi CursorColumn guibg=#333333
endif
"Omni menu colors
hi Pmenu guibg=#333333
hi PmenuSel guibg=#555555 guifg=#ffffff
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fileformats
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Favorite filetypes
set ffs=unix,dos,mac
nmap leader>fd :se ff=doscr>
nmap leader>fu :se ff=unixcr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" VIM userinterface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Set 7 lines to the curors - when moving vertical..
set so=7
"Turn on WiLd menu
set wildmenu
"Always show current position
set ruler
"The commandbar is 2 high
set cmdheight=2
"Show line number
set nu
"Do not redraw, when running macros.. lazyredraw
set lz
"Change buffer - without saving
set hid
"Set backspace
set backspace=eol,start,indent
"Bbackspace and cursor keys wrap to
set whichwrap+=,>,h,l
"Ignore case when searching
set ignorecase
set incsearch
"Set magic on
set magic
"No sound on errors.
set noerrorbells
set novisualbell
set t_vb=
"show matching bracets
set showmatch
"How many tenths of a second to blink
set mat=2
"Highlight search things
set hlsearch
""""""""""""""""""""""""""""""
" Statusline
""""""""""""""""""""""""""""""
"Always hide the statusline
set laststatus=2
function! CurDir()
let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
return curdir
endfunction
"Format the statusline
set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
""""""""""""""""""""""""""""""
" Visual
""""""""""""""""""""""""""""""
" From an idea by Michael Naumann
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
else
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
"Basically you press * or # to search for the current selection !! Really useful
vnoremap silent> * :call VisualSearch('f')CR>
vnoremap silent> # :call VisualSearch('b')CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Moving around and tabs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Map space to / and c-space to ?
map space> /
map c-space> ?
"Smart way to move btw. windows
map C-j> C-W>j
map C-k> C-W>k
map C-h> C-W>h
map C-l> C-W>l
"Actually, the tab does not switch buffers, but my arrows
"Bclose function ca be found in "Buffer related" section
map leader>bd :Bclosecr>
map down> bd
"Use the arrows to something usefull
map right> :bncr>
map left> :bpcr>
"Tab configuration
map leader>tn :tabnew %cr>
map leader>te :tabedit
map leader>tc :tabclosecr>
map leader>tm :tabmove
try
set switchbuf=usetab
set stal=2
catch
endtry
"Moving fast to front, back and 2 sides ;)
imap m-$> esc>$a
imap m-0> esc>0i
imap esc>$a
imap esc>0i
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Switch to current dir
map leader>cd :cd %:p:hcr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Parenthesis/bracket expanding
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 esc>`>a)esc>`esc>
")
vnoremap $2 esc>`>a]esc>`esc>
vnoremap $3 esc>`>a}esc>`esc>
vnoremap $$ esc>`>a"esc>`esc>
vnoremap $q esc>`>a'esc>`esc>
vnoremap $w esc>`>a"esc>`esc>
"Map auto complete of (, ", ', [
inoremap $1 ()esc>:let leavechar=")"cr>i
inoremap $2 []esc>:let leavechar="]"cr>i
inoremap $4 {esc>o}esc>:let leavechar="}"cr>O
inoremap $3 {}esc>:let leavechar="}"cr>i
inoremap $q ''esc>:let leavechar="'"cr>i
inoremap $w ""esc>:let leavechar='"'cr>i
au BufNewFile,BufRead *.\(vim\)\@! inoremap " ""esc>:let leavechar='"'cr>i
au BufNewFile,BufRead *.\(txt\)\@! inoremap ' ''esc>:let leavechar="'"cr>i
imap m-l> esc>:exec "normal f" . leavecharcr>a
imap esc>:exec "normal f" . leavecharcr>a
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Abbrevs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"My information
iab xdate c-r>=strftime("%d/%m/%y %H:%M:%S")cr>
iab xname Amir Salihefendic
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Editing mappings etc.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remap VIM 0
map 0 ^
"Move a line of text using control
nmap M-j> mz:m+cr>`z
nmap M-k> mz:m-2cr>`z
vmap M-j> :m'>+cr>`mzgv`yo`z
vmap M-k> :m'cr>`>my`if MySys() == "mac"
nmap M-j>
nmap M-k>
vmap M-j>
vmap M-k>
endif
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
set completeopt=menu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Command-line config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
func! Cwd()
let cwd = getcwd()
return "e " . cwd
endfunc
func! DeleteTillSlash()
let g:cmd = getcmdline()
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
endif
if g:cmd == g:cmd_edited
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
endif
endif
return g:cmd_edited
endfunc
func! CurrentFileDir(cmd)
return a:cmd . " " . expand("%:p:h") . "/"
endfunc
"Smart mappings on the command line
cno $h e ~/
cno $d e ~/Desktop/
cno $j e ./
cno $q C-\>eDeleteTillSlash()cr>
cno $c e C-\>eCurrentFileDir("e")cr>
cno $tc C-\>eCurrentFileDir("tabnew")cr>
cno $th tabnew ~/
cno $td tabnew ~/Desktop/
"Bash like
cnoremap C-A> Home>
cnoremap C-E> End>
cnoremap C-K> C-U>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Fast open a buffer by search for a name
map c-q> :sb
"Open a dummy buffer for paste
map leader>q :e ~/buffercr>
"Restore cursor to file position in previous editing session
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
" Buffer - reverse everything ... :)
map F9> ggVGg?
" Don't close window, when deleting a buffer
command! Bclose call SID>BufcloseCloseIt()
function! BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Files and backups
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Turn backup off
set nobackup
set nowb
set noswapfile
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable folding, I find it very useful
set nofen
set fdl=0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text options
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=2
map leader>t2 :set shiftwidth=2cr>
map leader>t4 :set shiftwidth=4cr>
au FileType html,python,vim,javascript setl shiftwidth=2
au FileType html,python,vim,javascript setl tabstop=2
au FileType java setl shiftwidth=4
au FileType java setl tabstop=4
set smarttab
set lbr
set tw=500
""""""""""""""""""""""""""""""
" Indent
""""""""""""""""""""""""""""""
"Auto indent
set ai
"Smart indet
set si
"C-style indeting
set cindent
"Wrap lines
set wrap
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map leader>sn ]s
map leader>sp [s
map leader>sa zg
map leader>s? z=
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" Vim Grep
""""""""""""""""""""""""""""""
let Grep_Skip_Dirs = 'RCS CVS SCCS .svn'
let Grep_Cygwin_Find = 1
""""""""""""""""""""""""""""""
" Yank Ring
""""""""""""""""""""""""""""""
map leader>y :YRShowcr>
""""""""""""""""""""""""""""""
" File explorer
""""""""""""""""""""""""""""""
"Split vertically
let g:explVertical=1
"Window size
let g:explWinSize=35
let g:explSplitLeft=1
let g:explSplitBelow=1
"Hide some files
let g:explHideFiles='^\.,.*\.class$,.*\.swp$,.*\.pyc$,.*\.swo$,\.DS_Store$'
"Hide the help thing..
let g:explDetailedHelp=0
""""""""""""""""""""""""""""""
" Minibuffer
""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 2
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1
let g:bufExplorerSortBy = "name"
autocmd BufRead,BufNew :call UMiniBufExplorer
""""""""""""""""""""""""""""""
" Tag list (ctags) - not used
""""""""""""""""""""""""""""""
"let Tlist_Ctags_Cmd = "/sw/bin/ctags-exuberant"
"let Tlist_Sort_Type = "name"
"let Tlist_Show_Menu = 1
"map t :Tlist
""""""""""""""""""""""""""""""
" LaTeX Suite things
""""""""""""""""""""""""""""""
set grepprg=grep\ -nH\ $*
let g:Tex_DefaultTargetFormat="pdf"
let g:Tex_ViewRule_pdf='xpdf'
"Bindings
autocmd FileType tex map silent>leader>space> :w!cr> :silent! call Tex_RunLaTeX()cr>
"Auto complete some things ;)
autocmd FileType tex inoremap $i \indent
autocmd FileType tex inoremap $* \cdot
autocmd FileType tex inoremap $i \item
autocmd FileType tex inoremap $m \[cr>\]esc>O
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Filetype generic
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Todo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
au BufNewFile,BufRead *.todo so ~/vim_local/syntax/amido.vim
""""""""""""""""""""""""""""""
" VIM
""""""""""""""""""""""""""""""
autocmd FileType vim map buffer> leader>space> :w!cr>:source %cr>
""""""""""""""""""""""""""""""
" HTML related
""""""""""""""""""""""""""""""
" HTML entities - used by xml edit plugin
let xml_use_xhtml = 1
"let xml_no_auto_nesting = 1
"To HTML
let html_use_css = 1
let html_number_lines = 0
let use_xhtml = 1
""""""""""""""""""""""""""""""
" Ruby & PHP section
""""""""""""""""""""""""""""""
autocmd FileType ruby map buffer> leader>space> :w!cr>:!ruby %cr>
autocmd FileType php compiler php
autocmd FileType php map buffer> leader>space> cd:wcr>:make %cr>
""""""""""""""""""""""""""""""
" Python section
""""""""""""""""""""""""""""""
"Run the current buffer in python - ie. on leader+space
au FileType python so ~/vim_local/syntax/python.vim
autocmd FileType python map buffer> leader>space> :w!cr>:!python %cr>
autocmd FileType python so ~/vim_local/plugin/python_fold.vim
"Set some bindings up for 'compile' of python
autocmd FileType python set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd FileType python set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
"Python iMaps
au FileType python set cindent
au FileType python inoremap buffer> $r return
au FileType python inoremap buffer> $s self
au FileType python inoremap buffer> $c ##cr>#space>cr>#esc>kla
au FileType python inoremap buffer> $i import
au FileType python inoremap buffer> $p print
au FileType python inoremap buffer> $d """cr>"""esc>O
"Run in the Python interpreter
function! Python_Eval_VSplit() range
let src = tempname()
let dst = tempname()
execute ": " . a:firstline . "," . a:lastline . "w " . src
execute ":!python " . src . " > " . dst
execute ":pedit! " . dst
endfunction
au FileType python vmap F7> :call Python_Eval_VSplit()cr>
""""""""""""""""""""""""""""""
" Cheetah section
"""""""""""""""""""""""""""""""
autocmd FileType cheetah set ft=xml
autocmd FileType cheetah set syntax=cheetah
"""""""""""""""""""""""""""""""
" Vim section
"""""""""""""""""""""""""""""""
autocmd FileType vim set nofen
"""""""""""""""""""""""""""""""
" Java section
"""""""""""""""""""""""""""""""
au FileType java inoremap buffer> C-t> System.out.println();esc>hi
"Java comments
autocmd FileType java source ~/vim_local/macros/jcommenter.vim
autocmd FileType java let b:jcommenter_class_author='Amir Salihefendic (amix@amix.dk)'
autocmd FileType java let b:jcommenter_file_author='Amir Salihefendic (amix@amix.dk)'
autocmd FileType java map buffer> F2> :call JCommentWriter()cr>
"Abbr'z
autocmd FileType java inoremap buffer> $pr private
autocmd FileType java inoremap buffer> $r return
autocmd FileType java inoremap buffer> $pu public
autocmd FileType java inoremap buffer> $i import
autocmd FileType java inoremap buffer> $b boolean
autocmd FileType java inoremap buffer> $v void
autocmd FileType java inoremap buffer> $s String
"Folding
function! JavaFold()
setl foldmethod=syntax
setl foldlevelstart=1
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
syn match foldImports /\(\n\?import.\+;\n\)\+/ transparent fold
function! FoldText()
return substitute(getline(v:foldstart), '{.*', '{...}', '')
endfunction
setl foldtext=FoldText()
endfunction
au FileType java call JavaFold()
au FileType java setl fen
au BufEnter *.sablecc,*.scc set ft=sablecc
""""""""""""""""""""""""""""""
" JavaScript section
"""""""""""""""""""""""""""""""
au FileType javascript so ~/vim_local/syntax/javascript.vim
function! JavaScriptFold()
setl foldmethod=syntax
setl foldlevelstart=1
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
function! FoldText()
return substitute(getline(v:foldstart), '{.*', '{...}', '')
endfunction
setl foldtext=FoldText()
endfunction
au FileType javascript call JavaScriptFold()
au FileType javascript setl fen
au FileType javascript imap c-t> console.log();esc>hi
au FileType javascript imap c-a> alert();esc>hi
au FileType javascript setl nocindent
au FileType javascript inoremap buffer> $r return
au FileType javascript inoremap buffer> $d //cr>//cr>//esc>kaspace>
au FileType javascript inoremap buffer> $c /**cr>space>cr>**/esc>ka
""""""""""""""""""""""""""""""
" HTML
"""""""""""""""""""""""""""""""
au FileType html,cheetah set ft=xml
au FileType html,cheetah set syntax=html
""""""""""""""""""""""""""""""
" C mappings
"""""""""""""""""""""""""""""""
autocmd FileType c map buffer> leader>space> :wcr>:!gcc %cr>
"""""""""""""""""""""""""""""""
" SML
"""""""""""""""""""""""""""""""
autocmd FileType sml map silent> buffer> leader>space> cd:wcr>:!sml %cr>
""""""""""""""""""""""""""""""
" Scheme bidings
""""""""""""""""""""""""""""""
autocmd BufNewFile,BufRead *.scm map buffer> leader>space> cd:wcr>:!petite %cr>
autocmd BufNewFile,BufRead *.scm inoremap buffer> C-t> (pretty-print )esc>i
autocmd BufNewFile,BufRead *.scm vnoremap C-t> esc>`>a)esc>`esc>
""""""""""""""""""""""""""""""
" SVN section
"""""""""""""""""""""""""""""""
map F8> :newCR>:read !svn diffCR>:set syntax=diff buftype=nofileCR>gg
""""""""""""""""""""""""""""""
" Snippets
"""""""""""""""""""""""""""""""
"You can use to goto the next - it is pretty smart ;)
"""""""""""""""""""""""""""""""
" Python
"""""""""""""""""""""""""""""""
autocmd FileType python inorea buffer> cfun c-r>=IMAP_PutTextWithMovement("def ():\n\nreturn ")cr>
autocmd FileType python inorea buffer> cclass c-r>=IMAP_PutTextWithMovement("class :\n")cr>
autocmd FileType python inorea buffer> cfor c-r>=IMAP_PutTextWithMovement("for in :\n")cr>
autocmd FileType python inorea buffer> cif c-r>=IMAP_PutTextWithMovement("if :\n")cr>
autocmd FileType python inorea buffer> cifelse c-r>=IMAP_PutTextWithMovement("if :\n\nelse:\n")cr>
"""""""""""""""""""""""""""""""
" JavaScript
"""""""""""""""""""""""""""""""
autocmd FileType cheetah,html,javascript inorea buffer> cfun c-r>=IMAP_PutTextWithMovement("function () {\n;\nreturn ;\n}")cr>
autocmd filetype cheetah,html,javascript inorea buffer> cfor c-r>=IMAP_PutTextWithMovement("for(; ; ) {\n;\n}")cr>
autocmd FileType cheetah,html,javascript inorea buffer> cif c-r>=IMAP_PutTextWithMovement("if() {\n;\n}")cr>
autocmd FileType cheetah,html,javascript inorea buffer> cifelse c-r>=IMAP_PutTextWithMovement("if() {\n;\n}\nelse {\n;\n}")cr>
"""""""""""""""""""""""""""""""
" HTML
"""""""""""""""""""""""""""""""
autocmd FileType cheetah,html inorea buffer> cahref c-r>=IMAP_PutTextWithMovement('">')cr>
autocmd FileType cheetah,html inorea buffer> cbold c-r>=IMAP_PutTextWithMovement('')cr>
autocmd FileType cheetah,html inorea buffer> cimg c-r>=IMAP_PutTextWithMovement('" alt="" />')cr>
autocmd FileType cheetah,html inorea buffer> cpara c-r>=IMAP_PutTextWithMovement('')cr>
autocmd FileType cheetah,html inorea buffer> ctag c-r>=IMAP_PutTextWithMovement('>>')cr>
autocmd FileType cheetah,html inorea buffer> ctag1 c-r>=IMAP_PutTextWithMovement(">>")cr>
"""""""""""""""""""""""""""""""
" Java
"""""""""""""""""""""""""""""""
autocmd FileType java inorea buffer> cfun c-r>=IMAP_PutTextWithMovement("public () {\n;\nreturn ;\n}")cr>
autocmd FileType java inorea buffer> cfunpr c-r>=IMAP_PutTextWithMovement("private () {\n;\nreturn ;\n}")cr>
autocmd FileType java inorea buffer> cfor c-r>=IMAP_PutTextWithMovement("for(; ; ) {\n;\n}")cr>
autocmd FileType java inorea buffer> cif c-r>=IMAP_PutTextWithMovement("if() {\n;\n}")cr>
autocmd FileType java inorea buffer> cifelse c-r>=IMAP_PutTextWithMovement("if() {\n;\n}\nelse {\n;\n}")cr>
autocmd FileType java inorea buffer> cclass c-r>=IMAP_PutTextWithMovement("class {\n\n}")cr>
autocmd FileType java inorea buffer> cmain c-r>=IMAP_PutTextWithMovement("public static void main(String[] argv) {\n\n}")cr>
"Presse c-q insted of space (or other key) to complete the snippet
imap C-q> C-]>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cope
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"For Cope
map silent> leader>cr> :nohcr>
"Orginal for all
map leader>n :cncr>
map leader>p :cpcr>
map leader>c :botright cw 10cr>
map c-u> c-l>c-j>:qcr>:botright cw 10cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remove the Windows ^M
noremap Leader>m mmHmt:%s/C-V>cr>//gecr>'tzt'm
"Paste toggle - when pasting something in, don't indent.
set pastetoggle=F3>
"Remove indenting on empty lines
map F2> :%s/\s*$//gcr>:nohcr>''
"Super paste
inoremap C-v> esc>:set pastecr>muiC-R>+esc>mv'uV'v=:set nopastecr>
"A function that inserts links & anchors on a TOhtml export.
" Notice:
" Syntax used is:
"
Link
" Anchor
function! SmartTOHtml()
TOhtml
try
%s/"\s\+\*> \(.\+\)/" \1" style="color: cyan">\1/g
%s/"\(-\|\s\)\+\*> \(.\+\)/" \ \ \2" style="color: cyan;">\2/g
%s/"\s\+=> \(.\+\)/" \1" style="color: #fff">\1/g
catch
endtry
exe ":write!"
exe ":bd"
endfunction
[vim组织提供的一个配置例子]
"=====================================================================================
" 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
"
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
" |-- backup to put backup files
" |-- diary to save calendar.vim's diaries
" |-- GetLatest to save GetLatestVimScripts.vim's
" | |
" | `-- 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 () 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 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: .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
"-------------------------------------------------------------------------------------
" has been mapped to SuperTab() func in that plugin
"-------------------------------------------------------------------------------------
" plugin - timestamp.vim
"-------------------------------------------------------------------------------------
let g:timestamp_regexp = '\v\C%()@='
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%(^ *)@ ->
" 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 = "iFkA"
endif
endf
" include colon(5Cool for namespaces in xsl for instance
"setlocal iskeyword=@,48-57,_,192-255,58
inoremap ,,, >db:call MakeElement()@w
"-------------------------------------------------------------------------------------
" mappings
"-------------------------------------------------------------------------------------
map :MBEbn
" -> switches buffers
map :MBEbp
" :Sex
" up arrow to bring up a file explorer
map :Tlist
" down arrow to bring up the taglist
map i r
" Alt-i inserts a single char, and back to normal
map ggVG:call SuperRetab()
map ggVGg?
" Rot13 encode the current file
"noremap :cal VimCommanderToggle()
" plugin - php_console.vim
"map :call ParsePhpFile() " call function in normal mode
"imap :call ParsePhpFile() " 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 %>
iab xdate =strftime("%m/%d/%y %H:%M:%S")
"-------------------------------------------------------------------------------------
" 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 :FirstExplorerWindow
map :BottomExplorerWindow
map :WMToggle
let g:winManagerWidth = 35
let g:winManagerWindowLayout = 'TodoList'
let g:tskelDir = $VIMFILES."/skeletons"
"-------------------------------------------------------------------------------------
" vim: set et ft=vim tw=98 path+=$VIMFILES/*:
参考:
http://www.vi-improved.org/vimrc.php
http://vimdoc.sourceforge.net/
http://www.yuanma.org/data/2006/0906/article_1473.htm
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/63573/showart_509129.html |
|