分享一下我的vim配置
这是我长时间使用vim总结的一些配置,分享给有需要的人。可以支持编译一键编译并执行C、C++和Java(需要安装编译器并配置环境变量),具体的使用方法,在下面的配置文件中讲的很详细。另外,在Linux上默认使用的clang的编译器,这种编译器可以兼容gcc的大部分选项,并且编译速度更快,提示更加友好,您也可以根据自己的需要改成自己喜欢的编译器。
我是在Windows7下测试的,所以Windows7系统直接可用。其中的插件与配置文件在 Linux 下同样适用。如果您是XP的用户,可能会出现Consolas字体找不到的情况,可以从Windows7系统拷贝,或者到去下载。对于其他系统(UNIX,MAC)的用户直接将下载到的文件解压,把插件目录和配置文件覆盖掉原来的文件即可。在Linux下,需要把插件目录重新命名为 .vim,配置文件重新命名为 .vimrc。建议您全新安装vim,仅仅拷贝配置文件和插件目录。
使用vim已经有快4年的时间了,从最初的排斥到现在的爱不释手,这段心路历程非常奇特。vim是一个非常奇特、精致的编辑器,是一个可以最大限度发挥人的智慧的编辑器。通过使用恰当的插件,完全可以秒杀其他昂贵而又笨重的IDE。然而最重要的是,它是免费的。这种免费充满了理想主义色彩,更难能可贵的是它有非常实用,这或许就是理想与现实的结合吧。
分享一下我使用vim的心得:对于一个初学者,不要过于深入的去钻研的vim配置,而最重要的就是要把vim用起来。所以,一开始,尽可以去网上找一些别人的配置文件为己所用,不要去深究这些配置具体的原理。我最一开始就是这样做的。作为一个软件,最大的价值就是可以提高人的效率,而如果在使用的同时还充满了快乐,那不是更好了吗?
下载连接:http://pan.baidu.com/s/1kT9WTvT
"-----------------Author:Light"-----------------Email:Black_Art@outlook.com"-----------------Date:2015-05-0400:02:05"********************************encoding**************************************"默认为UTF-8编码setencoding=utf-8setfileencoding=utf-8setfileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1setfileencoding=utf-8let&termencoding=&encoding"********************************ui**************************************"字体/配色"以下为解决中文显示问题,以及相应带来的提示及菜单乱码问题setencoding=utf-8"设置vim内部使用的字符编码,原来是cp936langmessageszh_CN.UTF-8"解决consle输出乱码"解决菜单乱码source$VIMRUNTIME/delmenu.vimsource$VIMRUNTIME/menu.vimcolorschememolokaisetguifont=Source\Code\Pro:h21.5,Consolas:h26"去掉工具条、菜单栏、滚动条"setgo=aAce"setguioptions-=msetshm+=Isetguioptions-=T"高亮光标所在的行setcursorline"自动最大化窗口ifhas('gui_running')auGUIEnter*simalt~x"给Win32下的gVim窗口设置透明度auGUIEnter*calllibcallnr("vimtweak.dll","SetAlpha",237)endif"********************************language**************************************"语言中文languagechineselanguagemessageszh_CN.utf-8"********************************system**************************************"保留Ctrl+A/c/v操作"source$VIMRUNTIME/mswin.vim"与windows共享剪贴板setclipboard+=unnamed"保留历史记录sethistory=500"导入删除菜单脚本,删除乱码的菜单source$VIMRUNTIME/delmenu.vim"导入正常的菜单脚本source$VIMRUNTIME/menu.vimsetnocompatible"Diff模式的时候鼠标同步滚动forVim7.3ifhas('cursorbind')setcursorbindend"********************************setting**************************************"行控制setlinebreaksettextwidth=80setwrap"带如下字符不换行setiskeyword+=_,$,@,%,#,-"标签页settabpagemax=9setshowtabline=2"控制台响铃setnoerrorbellssetnovisualbellsett_vb="closevisualbell"行号和标尺setnumbersetrulersetrulerformat=%15(%c%V\%p%%%)"命令行于状态行setch=1setls=2"始终显示状态行setwildmenu"命令行补全以增强模式运行"高亮、实时搜索sethlsearchsetmagicsetshowmatchsetmat=2setincsearchsetignorecase"制表符settabstop=4setexpandtabsetsmarttabsetshiftwidth=4setsofttabstop=4"状态栏显示目前所执行的指令setshowcmd"缩进setautoindentsetsmartindent"自动重新读入setautoread"插入模式下使用<BS>、<Del><C-W><C-U>setbackspace=indent,eol,start"设定在任何模式下鼠标都可用setmouse=a"自动改变当前目录setautochdir"备份和缓存setnobackupsetnoswapfile"自动完成setcomplete=.,w,b,k,t,isetcompleteopt=longest,menu"定义<Leader>为逗号letmapleader=","letmaplocalleader=",""保证语法高亮syntaxenablesyntaxonfiletypepluginindenton"********************************mapping**************************************"标签页操作nmapnt:tabnew<cr>:NERDTreeToggle<cr><c-w>wnmaptg:tabprevious<cr>nmapnc:tabclose<cr>"去掉查找后的高亮nmapnh:noh<cr>"转换文件类型nmap'h:setfiletype=html<cr>nmap'j:setfiletype=javascript<cr>nmap'c:setfiletype=css<cr>"在行尾添加;nmap;$A;<ESC>"在行尾添加,nmap<leader><leader>$A,<ESC>"另存为nmapss:browseconfirmsaveas<cr>"切换窗口nmaptt<c-w>w"新窗口打开配置文件nmap<leader>e:tabnew$VIM/_vimrc<cr>"按下Q不进入Ex模式,而是退出nmapQ:x<cr>"Tabularize插件对齐快捷键nmap<Leader>te:Tabularize/=<CR>nmap<Leader>tm:Tabularize/:<CR>"排序注释nmap<Leader>tc:Tabularize/\/\/<CR>"搜索nmap<Leader>n:cnext<cr>nmap<Leader>p:cprev<cr>nmap<Leader>l:clist<cr>nmap<Leader>w:cw<cr>"********************************plugin**************************************"插件快捷键nmapne:NERDTreeToggle<cr>"NERDTree配置letNERDTreeDirArrows=1"目录箭头1显示箭头0传统+-|号"neocomplcache配置letg:neocomplcache_enable_at_startup=1letg:neocomplcache_enable_camel_case_completion=1"doxygen配置letg:DoxygenToolkit_authorName="qinjia"letg:DoxygenToolkit_briefTag_funcName="yes"letg:doxygen_enhanced_color=1letg:DoxygenToolkit_paramTag_pre="@Param"letg:DoxygenToolkit_returnTag="@Returns"nmap<Leader>d:Dox<cr>nmap<Leader>b:DoxAuthor<cr>"********************************syntax**************************************"JavaScript语法高亮auFileTypehtml,javascriptletg:javascript_enable_domhtmlcss=1auBufRead,BufNewFile*.jssetsyntax=jquery"给各语言文件添加Dictlets:dict_dir=$VIM.'\vimfiles\dict\'lets:dict_dir="setlocaldict+=".s:dict_dirauFileTypehtmlexecs:dict_dir."html.dict"auFileTypecss,htmlexecs:dict_dir."css.dict"auFileTypejavascript,htmlexecs:dict_dir."javascript.dict"auFileTypejavascriptsetdictionary+=$VIM.'\vimfiles\dict\node.dict'"将指定文件的换行符转换成dos格式auFileTypephp,javascript,html,xml,json,css,txt,vim,vimwikisetff=dos"********************************function**************************************"获取当前目录"func!GetPWD()"returnsubstitute(getcwd(),"","","g")"endf"------------------------------------------------------------------------------"<判断操作系统是否是Windows还是Linux>"------------------------------------------------------------------------------if(has("win32")||has("win64")||has("win95")||has("win16"))letg:iswindows=1elseletg:iswindows=0endif"------------------------------------------------------------------------------"<判断是终端还是Gvim>"------------------------------------------------------------------------------ifhas("gui_running")letg:isGUI=1elseletg:isGUI=0endif"-----------------------------------------------------------------------------"<编译、连接、运行配置(目前只配置了C、C++、Java语言)>"-----------------------------------------------------------------------------"F9一键保存、编译、连接存并运行nmap<F9>:callRun()<CR>imap<F9><ESC>:callRun()<CR>"Ctrl+F9一键保存并编译nmap<c-F9>:callCompile()<CR>imap<c-F9><ESC>:callCompile()<CR>"Ctrl+F10一键保存并连接nmap<c-F10>:callLink()<CR>imap<c-F10><ESC>:callLink()<CR>lets:LastShellReturn_C=0lets:LastShellReturn_L=0lets:ShowWarning=1lets:Obj_Extension='.o'lets:Exe_Extension='.exe'lets:Class_Extension='.class'lets:Sou_Error=0lets:windows_CFlags='gcc\-fexec-charset=gbk\-Wall\-g\-std=c11\-O0\-c\%\-o\%<.o'lets:linux_CFlags='clang\-Wall\-g\-O0\-std=c11\-c\%\-o\%<.o'lets:windows_CPPFlags='g++\-fexec-charset=gbk\-Wall\-g\-O0\-c\%\-o\%<.o'lets:linux_CPPFlags='clang++\-Wall\-g\-O0\-c\%\-o\%<.o'lets:JavaFlags='javac\%'func!Compile()exe":ccl"exe":update"lets:Sou_Error=0lets:LastShellReturn_C=0letSou=expand("%:p")letv:statusmsg=''ifexpand("%:e")=="c"||expand("%:e")=="cpp"||expand("%:e")=="cxx"letObj=expand("%:p:r").s:Obj_ExtensionletObj_Name=expand("%:p:t:r").s:Obj_Extensionif!filereadable(Obj)||(filereadable(Obj)&&(getftime(Obj)<getftime(Sou)))redraw!ifexpand("%:e")=="c"ifg:iswindowsexe":setlocalmakeprg=".s:windows_CFlagselseexe":setlocalmakeprg=".s:linux_CFlagsendifechohlWarningMsg|echo"compiling..."silentmakeelseifexpand("%:e")=="cpp"||expand("%:e")=="cxx"ifg:iswindowsexe":setlocalmakeprg=".s:windows_CPPFlagselseexe":setlocalmakeprg=".s:linux_CPPFlagsendifechohlWarningMsg|echo"compiling..."silentmakeendifredraw!ifv:shell_error!=0lets:LastShellReturn_C=v:shell_errorendififg:iswindowsifs:LastShellReturn_C!=0exe":bocope"echohlWarningMsg|echo"compilationfailed"elseifs:ShowWarningexe":bocw"endifechohlWarningMsg|echo"compilationsuccessful"endifelseifempty(v:statusmsg)echohlWarningMsg|echo"compilationsuccessful"elseexe":bocope"endifendifelseechohlWarningMsg|echo""Obj_Name"isuptodate"endifelseifexpand("%:e")=="java"letclass=expand("%:p:r").s:Class_Extensionletclass_Name=expand("%:p:t:r").s:Class_Extensionif!filereadable(class)||(filereadable(class)&&(getftime(class)<getftime(Sou)))redraw!exe":setlocalmakeprg=".s:JavaFlagsechohlWarningMsg|echo"compiling..."silentmakeredraw!ifv:shell_error!=0lets:LastShellReturn_C=v:shell_errorendififg:iswindowsifs:LastShellReturn_C!=0exe":bocope"echohlWarningMsg|echo"compilationfailed"elseifs:ShowWarningexe":bocw"endifechohlWarningMsg|echo"compilationsuccessful"endifelseifempty(v:statusmsg)echohlWarningMsg|echo"compilationsuccessful"elseexe":bocope"endifendifelseechohlWarningMsg|echo""class_Name"isuptodate"endifelselets:Sou_Error=1echohlWarningMsg|echo"pleasechoosethecorrectsourcefile"endifexe":setlocalmakeprg=make"endfuncfunc!Link()callCompile()ifs:Sou_Error||s:LastShellReturn_C!=0returnendififexpand("%:e")=="c"||expand("%:e")=="cpp"||expand("%:e")=="cxx"lets:LastShellReturn_L=0letSou=expand("%:p")letObj=expand("%:p:r").s:Obj_Extensionifg:iswindowsletExe=expand("%:p:r").s:Exe_ExtensionletExe_Name=expand("%:p:t:r").s:Exe_ExtensionelseletExe=expand("%:p:r")letExe_Name=expand("%:p:t:r")endifletv:statusmsg=''iffilereadable(Obj)&&(getftime(Obj)>=getftime(Sou))redraw!if!executable(Exe)||(executable(Exe)&&getftime(Exe)<getftime(Obj))ifexpand("%:e")=="c"setlocalmakeprg=gcc\-o\%<\%<.oechohlWarningMsg|echo"linking..."silentmakeelseifexpand("%:e")=="cpp"||expand("%:e")=="cxx"setlocalmakeprg=g++\-o\%<\%<.oechohlWarningMsg|echo"linking..."silentmakeendifredraw!ifv:shell_error!=0lets:LastShellReturn_L=v:shell_errorendififg:iswindowsifs:LastShellReturn_L!=0exe":bocope"echohlWarningMsg|echo"linkingfailed"elseifs:ShowWarningexe":bocw"endifechohlWarningMsg|echo"linkingsuccessful"endifelseifempty(v:statusmsg)echohlWarningMsg|echo"linkingsuccessful"elseexe":bocope"endifendifelseechohlWarningMsg|echo""Exe_Name"isuptodate"endifendifsetlocalmakeprg=makeelseifexpand("%:e")=="java"returnendifendfuncfunc!Run()lets:ShowWarning=0callLink()lets:ShowWarning=1ifs:Sou_Error||s:LastShellReturn_C!=0||s:LastShellReturn_L!=0returnendifletSou=expand("%:p")ifexpand("%:e")=="c"||expand("%:e")=="cpp"||expand("%:e")=="cxx"letObj=expand("%:p:r").s:Obj_Extensionifg:iswindowsletExe=expand("%:p:r").s:Exe_ExtensionelseletExe=expand("%:p:r")endififexecutable(Exe)&&getftime(Exe)>=getftime(Obj)&&getftime(Obj)>=getftime(Sou)redraw!echohlWarningMsg|echo"running..."ifg:iswindowsexe":!%<.exe"elseifg:isGUIexe":!gnome-terminal-xbash-c'./%<;echo;echo请按Enter键继续;read'"elseexe":!clear;./%<"endifendifredraw!echohlWarningMsg|echo"runningfinish"endifelseifexpand("%:e")=="java"letclass=expand("%:p:r").s:Class_Extensionifgetftime(class)>=getftime(Sou)redraw!echohlWarningMsg|echo"running..."ifg:iswindowsexe":!java%<"elseifg:isGUIexe":!gnome-terminal-xbash-c'java%<;echo;echo请按Enter键继续;read'"elseexe":!clear;java%<"endifendifredraw!echohlWarningMsg|echo"runningfinish"endifendifendfunc
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。