vim入门使用与配置

vim相关知识积累,持续更新中。

常用操作一般模式切换到命令行:!command 暂时离开执行command的显示结果set nu显示行号块选择

按下v或者V或者[Ctrl]-v时,这个时候光标经过的地方会开始反白,y键可复制,d键可删除

替换文本中指定字符

在命令模式下

:%s/需要被替换的字符/新的字符/g

% 为正则表达式,表示文本结束,s 为 substitute 首字符,g 表示全局

环境设置与记录

vim的环境设置参数有很多,如果你想要知道目前的设置值,可以再一般模式时输入set all来查阅,不过设置选项实在太多了,在这里列出一些平时比较常用的一些简单的设置值

也可以通过配置文件来直观规定我们习惯的vim操作环境。整个vim的设置值一般是放置在/etc/vimrc这个文件中,不过,不建议直接修改它。建议修改文件~/.vimrc这个文件(默认不存在,,请自行手动创建),将希望的设置值列入。

set hlsearch”高亮度反白set backspace=2″课随时用退格键删除set autoindent”自动缩排set ruler”课显示最后一行的状态set showmode”左下角那一行的状态set nu”行号set bg=dark”显示不同的底色色调syntax on”语法高亮

一份不错的 vim 环境配置文件

“basicimap yy <Esc>set nusyntax onset tabstop=4set softtabstop=4set shiftwidth=4set autoindentset cindentset cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1smap <C-a> “+yGmap <C-x> “+p”tab shortcutmap <A-1> 1gtmap <A-1> 2gtmap <A-1> 3gtmap <A-1> 4gtmap <A-1> 5gtmap <A-1> 6gtmap <A-1> 7gtmap <A-1> 8gtmap <A-1> 9gt”window shortcutmap <C-h> <C-w>hmap <C-j> <C-w>jmap <C-k> <C-w>kmap <C-l> <C-w>l”color schemeset t_Co=256colorscheme desertEx”encodingset encoding=utf-8set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,gbk,euc-jp,euc-kr,latin1if has(“win32″)set fileencoding=chinese” fix menu gibberishsource $VIMRUNTIME/delmenu.vimsource $VIMRUNTIME/menu.vim” fix console gibberishlanguage messages zh_CN.utf-8elseset termencoding=utf-8set fileencoding=utf-8endif”tagsmap <F5> :!ctags -R –c++-kinds=+p –fields=+iaS –extra=+q .<CR>”/usr/include/tagsif has(“win32″)set tags+=E:\workspace\linux\tags ” tags for /usr/include/elseset tags+=/usr/include/tags ” tags for /usr/include/endifset tags+=tags” tags for current project”omnioppcopleteset nocpfiletype plugin onset completeopt=longest,menu” I really HATE the preview window!!!let OmniCpp_NameSpaceSearch=1″ 0: namespaces disabled” 1: search namespaces in the current buffer [default]” 2: search namespaces in the current buffer and in included fileslet OmniCpp_GlobalScopeSearch=1 ” 0: disabled 1:enabledlet OmniCpp_ShowAccess=1″ 1: show accesslet OmniCpp_ShowPrototypeInAbbr=1 ” 1: display prototype in abbreviationlet OmniCpp_MayCompleteArrow=1 ” autocomplete after ->let OmniCpp_MayCompleteDot=1″ autocomplete after .let OmniCpp_MayCompleteScope=1 ” autocomplete after ::autocmd FileType python set omnifunc=pythoncomplete#Completeautocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJSautocmd FileType html set omnifunc=htmlcomplete#CompleteTagsautocmd FileType css set omnifunc=csscomplete#CompleteCSSautocmd FileType xml set omnifunc=xmlcomplete#CompleteTagsautocmd FileType php set omnifunc=phpcomplete#CompletePHPautocmd FileType c set omnifunc=ccomplete#Complete”compileif(has(“win32”) || has(“win95”) || has(“win64”) || has(“win16”))g:iswindows=0endif”单个文件编译map <F9> :call Do_OneFileMake()<CR>function Do_OneFileMake()if expand(“%:p:h”)!=getcwd()echohl WarningMsg | echo “Fail to make! This file is not in the current dir! Press <F7> to redirect to the dir of this file.” | echohl Nonereturnendiflet sourcefileename=expand(“%:t”)if (sourcefileename==”” || (&filetype!=”cpp” && &filetype!=”c”))echohl WarningMsg | echo “Fail to make! Please select the right file!” | echohl Nonereturnendiflet deletedspacefilename=substitute(sourcefileename,’ ‘,”,’g’)if strlen(deletedspacefilename)!=strlen(sourcefileename)echohl WarningMsg | echo “Fail to make! Please delete the spaces in the filename!” | echohl Nonereturnendifif &filetype==”c”if g:iswindows==1set makeprg=gcc\ -o\ %<.exe\ %elseset makeprg=gcc\ -o\ %<\ %endifelseif &filetype==”cpp”if g:iswindows==1set makeprg=g++\ -o\ %<.exe\ %elseset makeprg=g++\ -o\ %<\ %endif”elseif &filetype==”cs””set makeprg=csc\ \/nologo\ \/out:%<.exe\ %endifif(g:iswindows==1)let outfilename=substitute(sourcefileename,’\(\.[^.]*\)’ ,’.exe’,’g’)let toexename=outfilenameelselet outfilename=substitute(sourcefileename,’\(\.[^.]*\)’ ,”,’g’)let toexename=outfilenameendifif filereadable(outfilename)if(g:iswindows==1)let outdeletedsuccess=delete(getcwd().”\\”.outfilename)elselet outdeletedsuccess=delete(“./”.outfilename)endifif(outdeletedsuccess!=0)set makeprg=makeechohl WarningMsg | echo “Fail to make! I cannot delete the “.outfilename | echohl Nonereturnendifendifexecute “silent make”set makeprg=makeexecute “normal :”if filereadable(outfilename)if(g:iswindows==1)execute “!”.toexenameelseexecute “!./”.toexenameendifendifexecute “copen”endfunction”进行make的设置map <F6> :call Do_make()<CR>map <c-F6> :silent make clean<CR>function Do_make()set makeprg=makeexecute “silent make”execute “copen”endfunction”debugmap <F8> :call Do_OneFileDebug()<CR>function Do_OneFileDebug()if expand(“%:p:h”)!=getcwd()echohl WarningMsg | echo “Fail to make! This file is not in the current dir! Press <F7> to redirect to the dir of this file.” | echohl Nonereturnendiflet sourcefileename=expand(“%:t”)if (sourcefileename==”” || (&filetype!=”cpp” && &filetype!=”c”))echohl WarningMsg | echo “Fail to make! Please select the right file!” | echohl Nonereturnendiflet deletedspacefilename=substitute(sourcefileename,’ ‘,”,’g’)if strlen(deletedspacefilename)!=strlen(sourcefileename)echohl WarningMsg | echo “Fail to make! Please delete the spaces in the filename!” | echohl Nonereturnendifif &filetype==”c”if g:iswindows==1set makeprg=gcc\ -g\ -o\ %<.exe\ %elseset makeprg=gcc\ -g\ -o\ %<\ %endifelseif &filetype==”cpp”if g:iswindows==1set makeprg=g++\ -g\ -o\ %<.exe\ %elseset makeprg=g++\ -g\ -o\ %<\ %endif”elseif &filetype==”cs””set makeprg=csc\ \/nologo\ \/out:%<.exe\ %endifif(g:iswindows==1)let outfilename=substitute(sourcefileename,’\(\.[^.]*\)’ ,’.exe’,’g’)let toexename=outfilenameelselet outfilename=substitute(sourcefileename,’\(\.[^.]*\)’ ,”,’g’)let toexename=outfilenameendifif filereadable(outfilename)if(g:iswindows==1)let outdeletedsuccess=delete(getcwd().”\\”.outfilename)elselet outdeletedsuccess=delete(“./”.outfilename)endifif(outdeletedsuccess!=0)set makeprg=makeechohl WarningMsg | echo “Fail to make! I cannot delete the “.outfilename | echohl Nonereturnendifendifexecute “silent make”set makeprg=makeexecute “normal :”if filereadable(outfilename)if(g:iswindows==1)execute “!gdb\ “.toexenameelseexecute “!gdb\ ./”.toexenameendifendifexecute “copen”endfunction

你的脸是为了呈现上帝赐给人类最贵重的礼物–微笑,一定要成为你工作最大的资产。

vim入门使用与配置

相关文章:

你感兴趣的文章:

标签云: