amix vim vimrc 3.6 (部分修改)

本文介绍了一套全面的Vim配置,包括界面设置、颜色字体、文件管理、文本操作、插件使用等,旨在提高编程效率。通过安装特定插件和调整配置选项,用户可以实现更快速、更便捷的代码编辑体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Maintainer:amix the lucky stiff
" http://amix.dk - amix@amix.dk
"
"Version:3.6 - 25/08/10 14:40:30
"
"Blog_post:
" http://amix.dk/blog/post/19486#The-ultimate-vim-configuration-vimrc
"Syntax_highlighted:
" http://amix.dk/vim/vimrc.html
"Raw_version:
" http://amix.dk/vim/vimrc.txt
"
"How_to_Install_on_Unix:
"$ mkdir ~/.vim_runtime
"$ svn co svn://orangoo.com/vim ~/.vim_runtime
"$ cat ~/.vim_runtime/install.sh
"$ sh ~/.vim_runtime/install.sh <system>
"<sytem> can be `mac`, `linux` or `windows`
"
"How_to_Upgrade:
"$ svn update ~/.vim_runtime
"
"Sections:
"-> General
"-> VIM user interface
"-> Colors and Fonts
"-> Files and backups
"-> Text, tab and indent related
"-> Visual mode related
"-> Command mode related
"-> Moving around, tabs and buffers
"-> Statusline
"-> Parenthesis/bracket expanding
"-> General Abbrevs
"-> Editing mappings
"
"-> Cope
"-> Minibuffer plugin
"-> Omni complete functions
"-> Python section
"-> JavaScript section
"
"
"Plugins_Included:
" > minibufexpl.vim - http://www.vim.org/scripts/script.php?script_id=159
" Makes it easy to get an overview of buffers:
" info -> :e ~/.vim_runtime/plugin/minibufexpl.vim
"
" > bufexplorer - http://www.vim.org/scripts/script.php?script_id=42
" Makes it easy to switch between buffers:
" info -> :help bufExplorer
"
" > yankring.vim - http://www.vim.org/scripts/script.php?script_id=1234
" Emacs's killring, useful when using the clipboard:
" info -> :help yankring
"
" > surround.vim - http://www.vim.org/scripts/script.php?script_id=1697
" Makes it easy to work with surrounding text:
" info -> :help surround
"
" > snipMate.vim - http://www.vim.org/scripts/script.php?script_id=2540
" Snippets for many languages (similar to TextMate's):
" info -> :help snipMate
"
" > mru.vim - http://www.vim.org/scripts/script.php?script_id=521
" Plugin to manage Most Recently Used (MRU) files:
" info -> :e ~/.vim_runtime/plugin/mru.vim
"
" > Command-T - http://www.vim.org/scripts/script.php?script_id=3025
" Command-T plug-in provides an extremely fast, intuitive mechanism for opening filesa:
" info -> :help CommandT
" screencast and web-help -> http://amix.dk/blog/post/19501
"
"
"Revisions:
" > 3.6: Added lots of stuff (colors, Command-T, Vim 7.3 persistent undo etc.)
" > 3.5: Paste mode is now shown in status lineif you are in paste mode
" > 3.4: Added mru.vim
" > 3.3: Added syntax highlighting for Mako mako.vim
" > 3.2: Turned on python_highlight_all for better syntax
"highlighting for Python
" > 3.1: Added revisions ;) and bufexplorer.vim
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
sethistory=700

" Enable filetype plugin
filetypepluginon
filetypeindenton

" Set to auto read when a file is changed from the outside
setautoread

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
letmapleader=","
letg:mapleader=","

" Fast saving
nmap<leader>w:w!<cr>

" Fast editing of the .vimrc
map<leader>e:e! ~/.vim_runtime/vimrc<cr>

" When vimrc is edited, reload it
autocmd!bufwritepostvimrcsource~/.vim_runtime/vimrc


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
setso=7

setwildmenu"Turn on WiLd menu

setruler"Always show current position

setcmdheight=2"The commandbar height

sethid"Change buffer - without saving

" Set backspace config
setbackspace=eol,start,indent
setwhichwrap+=<,>,h,l

setignorecase"Ignore case when searching
setsmartcase

sethlsearch"Highlight search things

setincsearch"Make search act like search in modern browsers
setnolazyredraw"Don't redraw while executing macros

setmagic"Set magic on, for regular expressions

setshowmatch"Show matching bracets when text indicator is over them
setmat=2"How many tenths of a second to blink

" No sound on errors
setnoerrorbells
setnovisualbell
sett_vb=
settm=500


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntaxenable"Enable syntax hl

function! MySys()
ifhas("win32")
return"win32"
elseifhas("unix")
return"unix"
else
return"mac"
endif
endfunction

" Set font according to system
ifMySys()=="mac"
setgfn=Menlo:h14
setshell=/bin/bash
elseifMySys()=="windows"
"set gfn=Bitstream\ Vera\ Sans\ Mono:h10
setgfn=YaHeiz:h13
elseifMySys()=="linux"
setgfn=Monospace\ 10
setshell=/bin/bash
endif

ifhas("gui_running")
"set guioptions-=m
setguioptions-=T
"set guioptions-=l
"set guioptions-=L
"set guioptions-=r
"set guioptions-=R
sett_Co=256
setbackground=dark
colorschemeelflord
setnonu
else
colorschemezellner
setbackground=dark

setnonu
endif

"set encoding=prc
setencoding=utf8
try
langen_US
catch
endtry

setffs=unix,dos,mac"Default file types


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
setnobackup
setnowb
setnoswapfile

"Persistent undo
try
ifMySys()=="windows"
setundodir=C:\Windows\Temp
else
setundodir=~/.vim_runtime/undodir
endif

setundofile
catch
endtry


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
setexpandtab
setshiftwidth=4
settabstop=4
setsmarttab

setlbr
settw=500

setai"Auto indent
setsi"Smart indet
setwrap"Wrap lines


""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Really useful!
"In visual mode when you press * or # to search for the current selection
vnoremap<silent>*:call VisualSearch('f')<CR>
vnoremap<silent>#:call VisualSearch('b')<CR>

" When you press gv you vimgrep after the selected text
vnoremap<silent>gv:call VisualSearch('gv')<CR>
map<leader>g:vimgrep // **/*.<left><left><left><left><left><left><left>


function! CmdLine(str)
exe"menu Foo.Bar :".a:str
emenuFoo.Bar
unmenuFoo
endfunction

" From an idea by Michael Naumann
function! VisualSearch(direction)range
letl:saved_reg=@"
execute"normal! vgvy"

letl:pattern=escape(@",'\\/.*$^~[]')
letl:pattern=substitute(l:pattern,"\n$","","")

ifa:direction=='b'
execute"normal ?".l:pattern."^M"
elseifa:direction=='gv'
callCmdLine("vimgrep ".'/'.l:pattern.'/'.' **/*.')
elseifa:direction=='f'
execute"normal /".l:pattern."^M"
endif

let@/=l:pattern
let@"=l:saved_reg
endfunction



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Command mode related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart mappings on the command line
cno$he ~/
cno$de ~/Desktop/
cno$je ./
cno$ce<C-\>eCurrentFileDir("e")<cr>

" $q is super useful when browsing on the command line
cno$q<C-\>eDeleteTillSlash()<cr>

" Bash like keys for the command line
cnoremap<C-A><Home>
cnoremap<C-E><End>
cnoremap<C-K><C-U>

cnoremap<C-P><Up>
cnoremap<C-N><Down>

" Useful on some European keyboards
map½$
imap½$
vmap½$
cmap½$


func! Cwd()
letcwd=getcwd()
return"e" . cwd
endfunc

func! DeleteTillSlash()
letg:cmd=getcmdline()
ifMySys()=="linux"||MySys()=="mac"
letg:cmd_edited=substitute(g:cmd,"\\(.*\[/\]\\).*","\\1","")
else
letg:cmd_edited=substitute(g:cmd,"\\(.*\[\\\\]\\).*","\\1","")
endif
ifg:cmd==g:cmd_edited
ifMySys()=="linux"||MySys()=="mac"
letg:cmd_edited=substitute(g:cmd,"\\(.*\[/\]\\).*/","\\1","")
else
letg:cmd_edited=substitute(g:cmd,"\\(.*\[\\\\\]\\).*\[\\\\\]","\\1","")
endif
endif
returng:cmd_edited
endfunc

func! CurrentFileDir(cmd)
returna:cmd." ".expand("%:p:h")."/"
endfunc


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map space to / (search) and c-space to ? (backgwards search)
map<space>/
map<c-space>?
map<silent><leader><cr>:noh<cr>

" 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

" Close the current buffer
map<leader>bd:Bclose<cr>

" Close all the buffers
map<leader>ba:1,300 bd!<cr>

" Use the arrows to something usefull
map<right>:bn<cr>
map<left>:bp<cr>

" Tab configuration
map<leader>tn:tabnew<cr>
map<leader>te:tabedit
map<leader>tc:tabclose<cr>
map<leader>tm:tabmove

" When pressing <leader>cd switch to the directory of the open buffer
map<leader>cd:cd %:p:h<cr>


command!Bclosecall<SID>BufcloseCloseIt()
function!<SID>BufcloseCloseIt()
letl:currentBufNum=bufnr("%")
letl:alternateBufNum=bufnr("#")

ifbuflisted(l:alternateBufNum)
buffer#
else
bnext
endif

ifbufnr("%")==l:currentBufNum
new
endif

ifbuflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction

" Specify the behavior when switching between buffers
try
setswitchbuf=usetab
setstal=2
catch
endtry


""""""""""""""""""""""""""""""
" => Statusline
""""""""""""""""""""""""""""""
" Always hide the statusline
setlaststatus=2

" Format the statusline
setstatusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c


function! CurDir()
letcurdir=substitute(getcwd(),'/Users/amir/',"~/","g")
returncurdir
endfunction

function! HasPaste()
if&paste
return'PASTE MODE'
else
return''
endif
endfunction


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket expanding
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap$1<esc>`>a)<esc>`<i(<esc>
vnoremap$2<esc>`>a]<esc>`<i[<esc>
vnoremap$3<esc>`>a}<esc>`<i{<esc>
vnoremap$$<esc>`>a"<esc>`<i"<esc>
vnoremap$q<esc>`>a'<esc>`<i'<esc>
vnoremap$e<esc>`>a"<esc>`<i"<esc>

" Map auto complete of (, ", ', [
inoremap$1()<esc>i
inoremap$2[]<esc>i
inoremap$3{}<esc>i
inoremap$4{<esc>o}<esc>O
inoremap$q''<esc>i
inoremap$e""<esc>i
inoremap$t<><esc>i


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Abbrevs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iabxdate<c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remap VIM 0
map0^

"Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap<M-j>mz:m+<cr>`z
nmap<M-k>mz:m-2<cr>`z
vmap<M-j>:m'>+<cr>`<my`>mzgv`yo`z
vmap<M-k>:m'<-2<cr>`>my`<mzgv`yo`z

ifMySys()=="mac"
nmap<D-j><M-j>
nmap<D-k><M-k>
vmap<D-j><M-j>
vmap<D-k><M-k>
endif

"Delete trailing white space, useful for Python ;)
func! DeleteTrailingWS()
exe"normal mz"
%s/\s\+$//ge
exe"normal `z"
endfunc
autocmdBufWrite*.py:callDeleteTrailingWS()

setguitablabel=%t


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Cope
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Do :help cope if you are unsure what cope is. It's super useful!
map<leader>cc:botright cope<cr>
map<leader>n:cn<cr>
map<leader>p:cp<cr>


""""""""""""""""""""""""""""""
" => bufExplorer plugin
""""""""""""""""""""""""""""""
letg:bufExplorerDefaultHelp=0
letg:bufExplorerShowRelativePath=1
map<leader>o:BufExplorer<cr>


""""""""""""""""""""""""""""""
" => Minibuffer plugin
""""""""""""""""""""""""""""""
letg:miniBufExplModSelTarget=1
letg:miniBufExplorerMoreThanOne=2
letg:miniBufExplModSelTarget=0
letg:miniBufExplUseSingleClick=1
letg:miniBufExplMapWindowNavVim=1
letg:miniBufExplVSplit=25
letg:miniBufExplSplitBelow=1

letg:bufExplorerSortBy="name"

autocmdBufRead,BufNew:callUMiniBufExplorer

map<leader>u:TMiniBufExplorer<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Omni complete functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmdFileTypecsssetomnifunc=csscomplete#CompleteCSS


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Pressing ,ss will toggle and untoggle spell checking
map<leader>ss:setlocal spell!<cr>

"Shortcuts using <leader>
map<leader>sn]s
map<leader>sp[s
map<leader>sazg
map<leader>s?z=


""""""""""""""""""""""""""""""
" => Python section
""""""""""""""""""""""""""""""
letpython_highlight_all=1
auFileTypepythonsynkeywordpythonDecoratorTrue None False self

auBufNewFile,BufRead*.jinjasetsyntax=htmljinja
auBufNewFile,BufRead*.makosetft=mako

auFileTypepythoninoremap<buffer>$rreturn
auFileTypepythoninoremap<buffer>$iimport
auFileTypepythoninoremap<buffer>$pprint
auFileTypepythoninoremap<buffer>$f#--- PH ----------------------------------------------<esc>FP2xi
auFileTypepythonmap<buffer><leader>1/class
auFileTypepythonmap<buffer><leader>2/def
auFileTypepythonmap<buffer><leader>C?class
auFileTypepythonmap<buffer><leader>D?def


""""""""""""""""""""""""""""""
" => JavaScript section
"""""""""""""""""""""""""""""""
auFileTypejavascriptcallJavaScriptFold()
auFileTypejavascriptsetlfen
auFileTypejavascriptsetlnocindent

auFileTypejavascriptimap<c-t>AJS.log();<esc>hi
auFileTypejavascriptimap<c-a>alert();<esc>hi

auFileTypejavascriptinoremap<buffer>$rreturn
auFileTypejavascriptinoremap<buffer>$f//--- PH ----------------------------------------------<esc>FP2xi

function! JavaScriptFold()
setlfoldmethod=syntax
setlfoldlevelstart=1
synregionfoldBracesstart=/{/ end=/}/transparentfoldkeependextend

function! FoldText()
returnsubstitute(getline(v:foldstart),'{.*','{...}','')
endfunction
setlfoldtext=FoldText()
endfunction


""""""""""""""""""""""""""""""
" => MRU plugin
""""""""""""""""""""""""""""""
letMRU_Max_Entries=400
map<leader>f:MRU<CR>


""""""""""""""""""""""""""""""
" => Command-T
""""""""""""""""""""""""""""""
letg:CommandTMaxHeight=15
setwildignore+=*.o,*.obj,.git,*.pyc
noremap<leader>j:CommandT<cr>
noremap<leader>y:CommandTFlush<cr>


""""""""""""""""""""""""""""""
" => Vim grep
""""""""""""""""""""""""""""""
letGrep_Skip_Dirs='RCS CVS SCCS .svn generated'
setgrepprg=/bin/grep\ -nH



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap<Leader>mmmHmt:%s/<C-V><cr>//ge<cr>'tzt'm

"Quickly open a buffer for scripbble
map<leader>q:e ~/buffer<cr>
auBufRead,BufNewFile~/bufferiab<buffer>xh1===========================================

map<leader>pp:setlocal paste!<cr>

map<leader>bb:cd ..<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Z@is2120.csdn
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
letg:calendar_focus_today=1
letg:calendar_diary="D:\\mydoc\\doc\\Ediary"

letTlist_Show_One_File=1
letTlist_Exit_OnlyWindow=1
"let Tlist_Ctags_Cmd ="/sw/bin/ctags-exuberant"
"let Tlist_Sort_Type ="name"
"let Tlist_Show_Menu = 1
"map <leader>t :Tlist<cr>
map<F3>:Tlist<cr>

settags=tags;
setautochdir

" turn off nice effect on status bar title
letperformance_mode=1

"Get out of VI's compatible mode..
setnocompatible

"Have the mouse enabled all the time:
ifexists("&mouse")
setmouse=a
endif

setfileencodings=ucs-bom,utf-8,cp936,gb2312,gbk,gb18030,chinese,big5,euc-jp,euc-kr,latin1

highlightmenufont=YaHeiz
languagemessagesen_US
setlangmenu=en_US
let$LANG='en_US'
source$VIMRUNTIME/delmenu.vim
source$VIMRUNTIME/menu.vim

"if you use vim in tty,
"'uxterm -cjk' or putty with option 'Treat CJK ambiguous characters as wide' on
ifexists("&ambiwidth")
setambiwidth=double
endif

"Highlight current
ifhas("gui_running")
ifexists("&cursorline")
setcursorline
endif
endif

"Switch to current dir
map<leader>cd:cd %:p:h<cr>

"Comment for C like language
ifhas("autocmd")
auBufNewFile,BufRead*.js,*.htc,*.c,*.tmpl,*.cssino$c/**<cr>**/<esc>O
endif

"My information
iaxdate<c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
"iab xname Amir Salihefendic

"Enable folding, I find it very useful
ifexists("&foldenable")
setfen
endif

ifexists("&foldlevel")
setfdl=0
endif

setnofen
setfdl=0
"set lbr
"set si
"set wrap

autocmdFileTypec,cpp,cssetshiftwidth=4| settabstop=4|setexpandtab

"au BufNewFile,BufRead *.todo so ~/vim_local/syntax/amido.vim

ifhas("autocmd")&&v:version>600
auBufRead,BufNew*.vimmap<buffer><leader><space>:w!<cr>:source %<cr>
endif

" HTML entities - used by xml edit plugin
letxml_use_xhtml=1
"let xml_no_auto_nesting = 1

"To HTML
lethtml_use_css=0
lethtml_number_lines=0
letuse_xhtml=1
setautoindent

"set fileencodings=utf-8,gb2312,gbk,cp936
"set termencoding=utf-8
"set fileformats=dos,unix
"set language=chinese_china
"set encoding=prc
setfenc=utf-8
setfencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936

"charset=utf-8
letg:html_use_css=0
letg:html_use_encoding="utf-8"
"let g:html_use_encoding ="gb2312"
letg:html_use_xhtml=0

letg:fencview_autodetect=1
setguifont=YaHeiz:h13
setguifontwide=YaHeiz:h13

"c# compiler
"auto save the file before compile
setautowrite
setmakeprg=csc\ /nologo\%
setefm+=%A%f(%l\\,%c):%m
nnoremap<silent><F5>:!start cmd /c "%:p:r:s,$,.exe," & pause<CR>

"最大化窗口
ifhas("gui_running")
ifMySys()=="win32"
"start gvim maximized
ifhas("autocmd")
auGUIEnter*simalt~x
endif
endif
endif

sethls
syntaxon
setshowcmd
setnomagic

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值