vim的一些使用备忘

1.用vim,gvim替换换行符 

用vim,gvim替换换行符
:%s/,/,^M/g

注意那个^M在Gvim中是先按ctrl+q在按回车打出来的,
在Vim中是按ctrl+v再按回车才能打出来
以下是我的vimrc,放这里只是备份
"安装GVIM后默认的配置
"-------------------------------------------------------------------------------{{{
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if
&diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if
&diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if
&sh =~ '\<cmd'
let cmd
= '""' . $VIMRUNTIME . '\diff"'
let eq
= '"'
else
let cmd
= substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd
= $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . '
> ' . arg3 . eq
endfunction
"-------------------------------------------------------------------------------}}}


"
"基本配置
"-------------------------------------------------------------------------------{{{
set helplang=cn,en "设置帮助语言
"set fencs=utf8,gbk "保证vimrc的编码是gbk格式
set fenc=gbk

"set guioptions-=m "去掉菜单栏
set guioptions-=T "去掉工具栏
set guioptions-=L "去掉左滑动条
"set guioptions-=r "去掉右滑动条


"set guifont=Lucida_Console:h9:cANSI "设置字体Lucida_Console字体
"set guifont=Bitstream_Vera_Sans_Mono:h9:cANSI "设置英文字体
"set gfw=Yahei_Mono:h9:cGB2312 "设置中文微软雅黑字体
"set guifont=Bitstream_Vera_Sans_Mono:h9:cANSI
"set gfw=Yahei_Mono:h10:cGB2312
set guifont=Arial_monospaced_for_SAP:h9:cANSI
"set gfw=幼圆:h10:cGB2312


set hidden
set wildmenu "增强的命令行自动补全
set showmode "显示模式
set number "设置显示行号
set background=dark "设置背景颜色 dark
set autoindent "设置自动将当前行对齐格式应用到下一行
set smartindent "设置智能选择对齐格式
set showmatch "设置匹配括号模式
set cursorline "当前光标所在行会有阴影
set so=7 "光标在下边界7行即开始滚屏
set backspace=indent,eol,start "设置后退键有效性
set whichwrap=b,s,
<,>,[,] "设置自动这行

"GNU编码风格设置
"set cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1

set sw=4 "设置缩进为4个空格
set ts=4 "设置Tab为4个空格
set et "设置编辑时Tab替换为空格,使用:retab格式化
set shiftwidth=4 "设置行之间交错使用4空格

set incsearch "设置搜索选项 /string
set nobackup "设置不备份文件
set foldenable "设置使用空格开关折叠
set ignorecase smartcase "设置不区分大小写
syntax enable "语法高亮可用
syntax on "打开语法高亮
colorscheme desert "设置颜色方案
"au GUIEnter * simalt ~x "GVIM打开后最大化

"Insert模式时,按下F2插入时间戳记
imap
<F2> <C-R>=strftime("%c")<CR>

autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType java set omnifunc=javacomplete#Complete
autocmd FileType php set omnifunc=phpcomplete#Complete
autocmd FileType sql set omnifunc=sqlcomplete#Complete
autocmd FileType c set omnifunc=ccomplete#Complete
"-------------------------------------------------------------------------------}}}

"以下配置是从范飞龙给我传的VIM中的_vimrc_version1中拷贝的2010/1/21 21:12:09
"但是我去掉了关于ctags路径和taglist的设置主要是要他的C-F12
"ctags+taglist插件设置
"---------------------------------------------------------------{{{
set tags=tags;
set tags+=gcc.tags;
set tags+=fltk2.tags;
set autochdir

set nocp
filetype plugin on
"map
<C-F12> :!ctags -R –c++-kinds=+p –fields=+iaS –extra=+q .<CR>
set completeopt=longest,menu "关掉智能补全时代预览窗口,这样可以防止闪屏现象

"2010/1/22 1:08:43很困了,可能很多错
"以下还是拷贝至vimer的博客
"---------------------------------------------------------------{{{
if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型
let g:iswindows=1
else
let g:iswindows=0
endif

map
<F12> :call Do_CsTag()<CR>
nmap
<C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap
<C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap
<C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap
<C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap
<C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap
<C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap
<C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap
<C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function Do_CsTag()
let dir = getcwd()
if filereadable("tags")
if(g:iswindows==1)
let tagsdeleted=delete(dir."\\"."tags")
else
let tagsdeleted=delete("./"."tags")
endif
if(tagsdeleted!=0)
echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
return
endif
endif
if has("cscope")
silent! execute "cs kill -1"
endif
if filereadable("cscope.files")
if(g:iswindows==1)
let csfilesdeleted=delete(dir."\\"."cscope.files")
else
let csfilesdeleted=delete("./"."cscope.files")
endif
if(csfilesdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
return
endif
endif
if filereadable("cscope.out")
if(g:iswindows==1)
let csoutdeleted=delete(dir."\\"."cscope.out")
else
let csoutdeleted=delete("./"."cscope.out")
endif
if(csoutdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
return
endif
endif
if(executable('ctags'))
"silent! execute "!ctags -R –c-types=+p –fields=+S *"
silent! execute "!ctags -R –c++-kinds=+p –fields=+iaS –extra=+q ."
endif
if(executable('cscope') && has("cscope") )
if(g:iswindows!=1)
silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
else
silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
endif
silent! execute "!cscope -b"
execute "normal :"
if filereadable("cscope.out")
execute "cs add cscope.out"
endif
endif
endfunction
"---------------------------------------------------------------}}}
"---------------------------------------------------------------}}}



"以下设置是从《把VIM打造成一个真正的IDE(2)》
"拷贝来的2010/1/21 21:27:18
"http://www.vimer.cn/2009/10/page/3
"---------------------------------------------------------------{{{
"进行Tlist的设置
"TlistUpdate可以更新tags
map
<F3> :silent! Tlist<CR>
"按下F3就可以呼出了
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表,如果想只有1个,设置为1
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=0 "不是一直实时更新tags,因为没有必要
let Tlist_Inc_Winwidth=0
"---------------------------------------------------------------}}}
"
"GCC配置
"----------------------------------------
"F5编译当前C++程序
"map
<F5> :w<Enter> :!g++ -o %< %<Enter>
"nmap
<F5> :w<cr> :!start g++ -o %< %<Enter>

"以下设置是从《VIM-一键编译单个源文件》拷贝来的2010/1/25 0:09:17
"http://www.vimer.cn/2009/10/11.html
"---------------------------------------------------------------{{{
"单个文件编译
map
<F5> :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 None
return
endif
let sourcefileename=expand("%:t")
if (sourcefileename=="" || (
&filetype!="cpp" && &filetype!="c"))
echohl WarningMsg | echo "Fail to make! Please select the right file!" | echohl None
return
endif
let deletedspacefilename=substitute(sourcefileename,' ','','g')
if strlen(deletedspacefilename)!=strlen(sourcefileename)
echohl WarningMsg | echo "Fail to make! Please delete the spaces in the filename!" | echohl None
return
endif
if
&filetype=="c"
if g:iswindows==1
set makeprg=gcc\ -o\ %
<.exe\ %
else
set makeprg
=gcc\ -o\ %<\ %
endif
elseif &filetype
=="cpp"
if g:iswindows==1
set makeprg=g++\ -o\ %<.exe\ %
else
set makeprg
=g++\ -o\ %<\ %
endif
"elseif &filetype
=="cs"
"set makeprg=csc\ \/nologo\ \/out:%<.exe\ %
endif
if(g:iswindows
==1)
let outfilename=substitute(sourcefileename,'\(\.[^.]*\)$','.exe','g')
let toexename=outfilename
else
let outfilename
=substitute(sourcefileename,'\(\.[^.]*\)$','','g')
let toexename=outfilename
endif

if filereadable(outfilename)
if(g:iswindows
==1)
let outdeletedsuccess=delete(getcwd()."\\".outfilename)
else
let outdeletedsuccess
=delete("./".outfilename)
endif
if(outdeletedsuccess!
=0)
set makeprg=make
echohl WarningMsg | echo "Fail to make! I cannot delete the ".outfilename | echohl None
return
endif
endif
execute "silent make"
set makeprg
=make

execute "normal :"
if filereadable(outfilename)
if(g:iswindows
==1)
execute "!".toexename
else
execute "!./".toexename
endif
endif
execute "copen"

endfunction

"进行make的设置
map <F6
> :call Do_make()<CR>
map
<c-F6> :silent make clean<CR>
function Do_make()
set makeprg=make
execute "silent make"
execute "copen"
endfunction
"---------------------------------------------------------------}}}

"执行编译后的程序
map
<F9> :!start cmd /k %<&pause&exit<Enter>

"Ctrl+F5编译并执行
map
<C-F5> :make<cr> :!start cmd /k %<&pause&exit<Enter>

"---------------------------------------------------------------{{{
"以下设置是从《把VIM打造成一个真正的IDE(3)》拷贝来的,
"安装了NERD_commenter和DoxygenToolkit插件2010/1/22 0:27:25
"对NERD_commenter的设置
let NERDShutUp=1
"支持单行和多行的选择,//格式
":map
<Ctrl-h> ,c<space>
map
<F4> ,c<space>
"对DoxygenToolkit的设置
map fg :Dox
<cr>
let g:DoxygenToolkit_authorName="ZhangxiangYe"
let g:DoxygenToolkit_licenseTag="My own license\
<enter>"
let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"
let g:DoxygenToolkit_briefTag_pre = "@brief\t"
let g:DoxygenToolkit_paramTag_pre = "@param\t"
let g:DoxygenToolkit_returnTag = "@return\t"
let g:DoxygenToolkit_briefTag_funcName = "no"
let g:DoxygenToolkit_maxFunctionProtoLines = 30
"---------------------------------------------------------------}}}

"---------------------------------------------------------------{{{
"以下是从范飞龙的配置中拷贝的,2010/1/22 10:26:25
"目的是通过 WinManager 插件来将 TagList 窗口和 netrw 窗口整合起来,
"
"WinManager配置
"---------------------------------------------------------------{
let g:winManagerWindowLayout='FileExplorer|TagList'
let g:winManagerWidth=30
let g:defaultExplorer=0
"nmap wm :WMToggle
<cr>
nmap
<M-w> :WMToggle<cr>
nmap
<F11> :wa<cr>:TlistUpdate<cr>:FirstExplorerWindow<cr><F5><c-w>b
"---------------------------------------------------------------}
"
"a配置
"---------------------------------------------------------------{
let g:alternateExtensions_cpp="h"
let g:alternateExtensions_h="cpp"
"nnoremap
<silent><F12> :A<CR>"这个快捷键会不会和前面的ctags重复了
"---------------------------------------------------------------}

"
"MiniBufferExplorer配置
"---------------------------------------------------------------{
let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplMapWindowNavVim=1
let g:miniBufExplMapWindowNavArrows=1
let g:miniBufExplorerMoreThanOne=0
"---------------------------------------------------------------}

"
"Grep配置
"---------------------------------------------------------------{
"nnoremap
<silent><F3> :Grep<CR>
"---------------------------------------------------------------}
"


"
"omnicppcomplete配置
"-------------------------------------------------------------------------------{{{
let OmniCpp_GlobalScopeSearch = 1 " 0 or 1
let OmniCpp_NamespaceSearch = 1 " 0 , 1 or 2
let OmniCpp_DisplayMode = 1

let OmniCpp_ShowPrototypeInAbbr = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_DefaultNamespaces=[ "std "]
"-------------------------------------------------------------------------------}}}


"
"Latex插件部分
"---------------------------------------------------------------{
" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on

" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash

" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*

" OPTIONAL: This enables automatic indentation as you type.
filetype indent on

" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
"---------------------------------------------------------------}
"---------------------------------------------------------------}}}
"
"
highlight MarkWordN ctermbg=Cyan ctermfg=Black guibg=#8CCBEA guifg=Black
highlight link SearchSpecialSearchType MoreMsg

  

posted @ 2011-04-30 15:31  羊习习  阅读(668)  评论(0编辑  收藏  举报