Vimrc – 15.0

"F1~F12快捷键映射

""{{{

map :NERDTreeToggle .

map :BufExplorer

map :TlistToggle

noremap :make

nnoremap :A

map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .

"noremap :make clean;make

"noremap :!cvs up

""}}}

"F1~F12快捷键映射

 

 

"非F1~F12快捷键

""{{{

let mapleader=","

let g:mapleader=","

map svi : source ~/.vimrc " fast reloading of the .vimrc

map evi : e! ~/.vimrc " fast editing of .vimrc

map sb : set scrollbind

map nsb : set noscrollbind

map ls : set laststatus=2

map nls : set laststatus=1

map sy : set syntax=on

map nsy : set syntax=off

nnoremap c : set cursorline! cursorcolumn!

""}}}

"非F1~F12快捷键

 

 

 

"简单配置

"{{{

 

"打开语法色彩

syntax enable

"打开语法色彩

 

"打开关键字色

syntax on

"打开关键字色

 

"侦测文件类型

filetype on

"侦测文件类型

 

"载入文件类型插件

filetype plugin on

"载入文件类型插件

 

"为特定文件类型载入相关缩进文件

filetype indent on

"为特定文件类型载入相关缩进文件

 

"设置VIM颜色主题

"term 黑白终端的属性

"cterm 彩色终端的属性

"ctermfg 彩色终端的前景色

"ctermbg 彩色终端的背景色

"gui GUI 版本属性

"guifg GUI 版本的前景色

"guibg GUI 版本的背景色

colorscheme elflord

"colorscheme morning

"colorscheme evening

"colorscheme desert

"设置VIM颜色主题

 

"改变注释代码的颜色

hi Comment ctermfg=6

"改.c文件的c风格/* ... */注释为会灰白色

hi cComment ctermfg=LightBlue guifg=Grey

"改.c文件的c++风格// ... 注释为彩色终端下为暗蓝灰色、GUI下为浅蓝色

hi cCommentL ctermfg=DarkGray guifg=LightBlue

"以上可参看/usr/share/vim/vim72/syntax/c.vim中对cComment和cCommentL的定义

"改变注释代码的颜色

 

"预览窗口,eg. ctr+w { 时的窗口大小

set previewheight=10

"预览窗口,eg. ctr+w { 时的窗口大小

 

"设置弹出菜单的高度

set pumheight=15

"设置弹出菜单的高度

 

"使用鼠标

set mouse=a

"使用鼠标

 

"autocmd

if has("autocmd")

autocmd BufEnter * :lchdir %:p:h

endif

"autocmd

 

"映射快捷键开始命令,缺省为'/'(已经移到上面)

"let mapleader=","

"let g:mapleader=","

"映射快捷键开始命令,缺省为'/'(已经移到上面)

 

"解决consle输出乱码

language messages zh_CN.utf-8

"解决consle输出乱码

 

"在Linux下设置字体的命令是:

:set guifont=Monospace:12

"在Linux下设置字体的命令是:

 

"可用来改动补全时采用的方式

:set wildmode=list:full

"可用来改动补全时采用的方式

 

"可用来取得菜单式的匹配列表

:set wildmenu

"可用来取得菜单式的匹配列表

 

"修改一个文件后,自动进行备份,备份的文件名为原文件名加"~"后缀

"if has("vms")

" set nobackup

"else

" set backup "vim main.c 多出 main.c~文件用来保存打开前的原文件, 最后可用vimdiff main.c main.c~比较

"endif

"修改一个文件后,自动进行备份,备份的文件名为原文件名加"~"后缀

 

"写备份但关闭vim后自动删除

set writebackup

"set nowritebackup

"写备份但关闭vim后自动删除

 

"vi兼容开关

set nocp

"vi兼容开关

"

 

"不使用swap文件

"set noswapfile

set swapfile

"不使用swap文件

 

"显示匹配的括号([{和}])

set showmatch

"显示匹配的括号([{和}])

 

"显示日期的缩写

iab xdate =strftime("%Y-%m-%d %H:%M:%S")

"显示日期的缩写

 

"关闭遇到错误时的声音提示

set noerrorbells

"关闭遇到错误时的声音提示

 

"不要闪烁

set novisualbell

"不要闪烁

 

"使用空格来替换tab

set expandtab

"set et

"使用空格来替换tab

 

"在vim编辑器下方显示命令

set showcmd

set cmdheight=1

"在vim编辑器下方显示命令

 

"当光标达到上端或下端时 翻滚的行数

set scrolljump =5

"当光标达到上端或下端时 翻滚的行数

 

"当光标达到水平极端时 移动的列数

set sidescroll =5

"当光标达到水平极端时 移动的列数

 

"当光标距离极端(上,下,左,右)多少时发生窗口滚动

set scrolloff =0

"当光标距离极端(上,下,左,右)多少时发生窗口滚动

 

"当使用vimdiff比较文件,相比较的比较文件同步滚动,但是分割窗口也同步

"set scrollbind

"set noscrollbind "个人觉得很有用, 赐予一个快捷键

"当使用vimdiff比较文件,相比较的比较文件同步滚动,但是分割窗口也同步

 

"将当前编辑文件的路径设置为当前路径

set autochdir

"将当前编辑文件的路径设置为当前路径

 

"自动读写相关

set autoread " read open files again when changed outside Vim ( 同步 )

set autowrite " write a modified buffer on each :next , ... ( 跳到另一个文件时,自动保存上个文件 )

"自动读写相关

 

"设置VIM行号

set nu

"set nonu

"设置VIM行号

 

"Tab 宽度

set ts=4

"Tab 宽度

 

"自动缩进的时候, 缩进尺寸

set sw=4

"自动缩进的时候, 缩进尺寸

 

"打开 VIM 的状态栏标尺

set ru

"打开 VIM 的状态栏标尺

 

"显示括号配对情况

set sm "smartmatch

"显示括号配对情况

 

"自能缩进 smart cindent

set si

"自能缩进 smart cindent

 

"打开 C/C++ 风格的自动缩进 ( =a{ , gg=G 代码美化 )

set cin

"打开 C/C++ 风格的自动缩进 ( =a{ , gg=G 代码美化 )

 

"允许backspace和光标键跨越行边界 ( 不习惯 )

"set whichwrap+=<,>,h,l

"允许backspace和光标键跨越行边界 ( 不习惯 )

 

"内容多时,换行显示

"set wrap

set nowrap

"内容多时,换行显示

"

 

"启动的时候不显示那个援助乌干达儿童的提示

set shortmess=atI

"启动的时候不显示那个援助乌干达儿童的提示

 

"通过使用: commands命令,告诉我们文件的哪一行被改变过 ( 不习惯 )

"set report=0

"通过使用: commands命令,告诉我们文件的哪一行被改变过 ( 不习惯 )

 

"在被分割的窗口间显示空白,便于阅读 (没看到效果)

set fillchars=vert:/ ,stl:/ ,stlnc:/

"在被分割的窗口间显示空白,便于阅读 (没看到效果)

 

"带有如下符号的单词不要被换行分割

set iskeyword+=_,$,@,%,#,-

"带有如下符号的单词不要被换行分割

"}}}

"简单配置

 

 

 

"字符编码(多字节)

"{{{

if has("multi_byte")

    set encoding=utf-8

    "set fileencoding=cp936

    "set fileencoding=utf-8

    "set fileencodings=ucs-bom,utf-8,chinese

set fileencodings=ucs-bom,utf-8,chinese,big5,latin1,cp936

endif

 

"if has("multi_byte")

" " Set fileencoding priority

" if getfsize(expand("%")) > 0

" set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1

" else

" set fileencodings=cp936,big5,euc-jp,euc-kr,latin1

" endif

" " CJK environment detection and corresponding setting

" if v:lang =~ "^zh_CN"

" " Use cp936 to support GBK, euc-cn == gb2312

" set encoding=cp936

" set termencoding=cp936

" set fileencoding=cp936

" elseif v:lang =~ "^zh_TW"

" " cp950, big5 or euc-tw

" " Are they equal to each other?

" set encoding=big5

" set termencoding=big5

" set fileencoding=big5

" elseif v:lang =~ "^ko"

" " Copied from someone's dotfile, untested

" set encoding=euc-kr

" set termencoding=euc-kr

" set fileencoding=euc-kr

" elseif v:lang =~ "^ja_JP"

" " Copied from someone's dotfile, unteste

" set encoding=euc-jp

" set termencoding=euc-jp

" set fileencoding=euc-jp

" endif

" " Detect UTF-8 locale, and replace CJK setting if needed

" if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"

" set encoding=utf-8

" set termencoding=utf-8

" set fileencoding=utf-8

" endif

"else

" echoerr "Sorry, this version of (g)vim was not compiled with multi_byte"

"endif

"}}}

"字符编码(多字节)

 

 

 

"设置C/C++语言的具体缩进方式 eg. switch case 缩进

""{{{

set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s

"set cino=:4g2t0(sus

"set cino=:0g0t0(sus

" :0 -- switch 语句之下的 case 语句缩进 0 个空格

" g0 -- class,struct,等权限控制语句(public,protected,private)相对class,struct等所在的块缩进 0 个空格

" t0 -- 如果函数返回值与函数名不在同一行,则返回值缩进 0 个空格

" (sus - 当一对括号跨越多行时,其后的行缩进前面 sw 指定的距离

""}}}

"设置C/C++语言的具体缩进方式 eg. switch case 缩进

 

 

 

"C的编译和运行 " 不好用,推荐用c.vim插件, /rr(运行), /ra(带参数运行), /ro(输出乱码输出到(buff, xterm, vim))

"{{{

"map :call CompileRunGcc()

"func! CompileRunGcc()

" exec "w"

" exec "!gcc % -o %<"

" exec "! ./%<"

"endfunc

"}}}

"C的编译和运行 " 不好用,推荐用c.vim插件, /rr(运行), /ra(带参数运行), /ro(输出乱码输出到(buff, xterm, vim))

 

 

 

"目前看不到作用nicer foldtext

"{{{

"set foldtext=MyFoldtext()

"function! MyFoldtext()

" let line = getline(v:foldstart)

" let level = v:foldlevel

" let i = 1

" while i < level

" let line = ' ' . line

" let i = i + 1

" endwhile

" let num = v:foldend - v:foldstart

" let line = line . '------' . num . ' lines'

" return line

"endfunction

"}}}

"目前看不到作用nicer foldtext

 

 

 

"search 搜索 (不用这个也能实现)

""{{{

"set hls " hlsearch :highlight search

"set is " incsearch :increase search

"set ic " ignorecase :ignore case when searching

"set scs " smartcase :if has upper case, ignore 'ignorecase' option

""map h *N " h to highlight all word the same to which under cursor (可以使用vim自带shift + *)

""

""basically you press * or # to search for the current selection !! Really useful

"vnoremap * :call VisualSearch('f')

"vnoremap # :call VisualSearch('b')

"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

"map :nohl " :press to clear hightlight search highlight

""}}}

"search 搜索 (不用这个也能实现)

 

 

 

"显示当前文件

"{{{

"显示状态栏

set ruler

set laststatus=2

highlight statusline cterm=bold ctermfg=black ctermbg=white

"显示状态栏

"

function! CurDir()

let curdir = substitute(getcwd(), $HOME, "~", "g")

return curdir

endfunction

 

 

function! CurTime()

let curtime = strftime("%m-%d %H:%M:%S")

return curtime

endfunction

"set statusline=[%n]/ %f%m%r%h/ /|/ / pwd:/ %{CurDir()}/ / /|%=/|/ %l,%c/ %p%%/ /|/ ascii=%b,hex=%b%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|/ %{$USER}/ @/ %{hostname()}/

"set statusline=[%n]/ %F%m%r%h/ /|/ / pwd:/ %{CurDir()}/ / /|%=/|/ %l,%c/ %p%%/ /|/ ascii=%b,hex=%B%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|

"使用%F就不需要使用自定义函数CurDir()

"set statusline=[%n]/ /|/ %F%m%r%h/ /|%=/|/ %l,%c/ %p%%/ /|/ ascii=%b,hex=%B%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|/ / %{CurTime()}/ /|

set statusline=[%n]/ /|/ %F%m%r%h/ /|%=/|/ %c/ /|/ ascii=%b,hex=%B%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|/ %{CurTime()}/ /|

"状态行显示内容

" %F 当前文件名

" %m 当前文件修改状态

" %r 当前文件是否只读

" %Y 当前文件类型

" %{&fileformat} 当前文件编码

" %b 当前光标处字符的 ASCII 码值

" %B 当前光标处字符的十六进制值

" %l 当前光标行号

" %c 当前光标列号

" %V 当前光标虚拟列号 (根据字符所占字节数计算)

" %p 当前行占总行数的百分比

" %% 百分号

" %L 当前文件总行数

"}}}

"显示当前文件

 

 

 

"当前行(列)高亮显示

"{{{

set cursorline

set cursorcolumn

"hi CursorLine term=bold cterm=bold ctermbg=darkgrey ctermfg=yellow guibg=#333333 guifg=red

"hi CursorLine term=bold cterm=bold ctermbg=darkyellow ctermfg=darkblue guibg=lightblue guifg=black

"hi CursorLine term=bold cterm=bold ctermbg=black ctermfg=yellow guibg=darkgrey guifg=darkyellow

"hi CursorLine term=reverse cterm=reverse ctermbg=darkred ctermfg=black guibg=blue guifg=white

"hi CursorLine term=none cterm=reverse ctermbg=Magenta ctermfg=DarkGray "guibg=blue guifg=white

hi CursorLine term=none cterm=reverse ctermbg=Yellow ctermfg=DarkGray "guibg=blue guifg=white

hi CursorColumn term=bold cterm=bold ctermbg=black ctermfg=Cyan "guibg=darkgrey guifg=white

"nnoremap c : set cursorline! cursorcolumn!

"set cursorline

"au! Cursorhold * exe 'match CurrentLine //%' . line('.') . 'l.*/'

"set ut=100

"}}}

"当前行(列)高亮显示

 

 

"单行或多行注释

"{{{

nmap :Setcomment

"normal 模式下ctrl + C 快捷键

imap :Setcomment

"insert 模式下ctrl + C 快捷键

vmap :SetcommentV

"visual 模式下ctrl + C 快捷键

command! -nargs=0 Setcomment call s:SET_COMMENT()

command! -nargs=0 SetcommentV call s:SET_COMMENTV()

 

"非视图模式下所调用的函数

function! s:SET_COMMENT()

let lindex=line(".")

let str=getline(lindex)

"查看当前是否为注释行

let CommentMsg=s:IsComment(str)

call s:SET_COMMENTV_LINE(lindex,CommentMsg[1],CommentMsg[0])

endfunction

 

"视图模式下所调用的函数

function! s:SET_COMMENTV()

let lbeginindex=line("'<") "得到视图中的第一行的行数

let lendindex=line("'>") "得到视图中的最后一行的行数

let str=getline(lbeginindex)

"查看当前是否为注释行

let CommentMsg=s:IsComment(str)

"为各行设置

let i=lbeginindex

while i<=lendindex

call s:SET_COMMENTV_LINE(i,CommentMsg[1],CommentMsg[0])

let i=i+1

endwhile

endfunction

 

"设置注释

"index:在第几行

"pos:在第几列

"comment_flag: 0:添加注释符 1:删除注释符

function! s:SET_COMMENTV_LINE( index,pos, comment_flag )

let poscur = [0, 0,0, 0]

let poscur[1]=a:index

let poscur[2]=a:pos+1

call setpos(".",poscur) "设置光标的位置

 

if a:comment_flag==0

"插入//

exec "normal! i//"

else

"删除//

exec "normal! xx"

endif

endfunction

 

"查看当前是否为注释行并返回相关信息

"str:一行代码

function! s:IsComment(str)

let ret= [0, 0] "第一项为是否为注释行(0,1),第二项为要处理的列,

let i=0

let strlen=len(a:str)

while i

"空格和tab允许为"//"的前缀

if !(a:str[i]==' ' || a:str[i] == ' ' )

let ret[1]=i

if a:str[i]=='/' && a:str[i+1]=='/'

let ret[0]=1

else

let ret[0]=0

endif

return ret

endif

let i=i+1

endwhile

return [0,0] "空串处理

endfunction

"}}}

"单行或多行注释

 

 

 

"自己定义函数或函数头文件

"{{{

"ctrl+F12 或 ctrl+F11:生成tags

"vim -t sys_open : 就可以到sys_open 的定义出

"--c++-kinds=+p : 为C++文件增加函数原型的标签

"--fields=+iaS : 在标签文件中加入继承信息(i)、类成员的访问控制信息(a)、以及函数的指纹(S)

"--extra=+q : 为标签增加类修饰符。注意,如果没有此选项,将不能对类成员补全

"map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .

"map :!ctags -R --c-kinds=+p --fields=+iaS --extra=+q .

"map :!ctags -R .

set tags+=./tags

"}}}

"自己定义函数或函数头文件

 

 

 

"vim折叠功能

""{{{

"折叠方式,可用选项 'foldmethod' 来设定折叠方式:set fdm=***

"有 6 种方法来选定折叠:

"manual 手工定义折叠

"indent 更多的缩进表示更高级别的折叠

"expr 用表达式来定义折叠

"syntax 用语法高亮来定义折叠

"diff 对没有更改的文本进行折叠

"marker 对文中的标志折叠

"常用的折叠快捷键

"zf 创建折叠 (marker 有效)

"zo 打开折叠

"zO 对所在范围内所有嵌套的折叠点展开

"zc 关闭当前折叠

"zC 对所在范围内所有嵌套的折叠点进行折叠

"[z 到当前打开的折叠的开始处。

"]z 到当前打开的折叠的末尾处。

"zM 关闭所有折叠 (我喜欢)

"zr 打开所有折叠

"zR 循环地打开所有折叠 (我喜欢)

"zE 删除所有折叠

"zd 删除当前折叠

"zD 循环删除 (Delete) 光标下的折叠,即嵌套删除折叠

"za 若当前打开则关闭,若当前关闭则打开 ( 这个就足够了)

"zA 循环地打开/关闭当前折叠

"zj 到下一折叠的开始处 ( 我喜欢 )

"zk 到上一折叠的末尾 ( 我喜欢 )

"set fdm=marker

"set foldmethod=indent

"要想在{ } 代码块中折叠,按空格键

"syntax 与 c.vim 中的 /cc 注释功能冲突

set fdm=marker

"nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo') "使用空格打开或关闭折叠

"}}}

"vim折叠功能

 

 

 

"文件比较

""{{{

":vertical diffsplit FILE_RIGHT "与已打开的文件进行比较

"设置不同之处显示上下三行

set diffopt=context:3

"命令模式(ESC键进入):

"dp 左边文件差异复制到右边文件(直接在键盘上行按下dp)

"do 右边文件差异复制到左边文件(直接在键盘上行按下do)

"zo 隐藏相同行

"zc 展开向同行

"u 撤销

"Ctrl+w 文件切换

"

":qa! 退出不保存

":wa 保存

":wqa 保存退出

":diffupdate 重新比较

""}}}

"文件比较

 

"C库函数参数Scratch显示

""{{{

"1.先下载glibc库

"2.解压到/usr/src中

"3.执行:ctags -R --c-kinds=f

"4.ctrl+x ctrl+o

"one 添加c库函数定义数据库

"set tags+=/usr/src/glibc/tags

"two 添加linux 源码 函数定义数据库

"set tags+=/usr/src/linux/tags

"}}}

"C库函数参数Scratch显示

 

 

 

"C库类型定义,函数声明,宏定义等

"{{{

"1.cd /usr/include/

"2.执行:ctags -R --c-kinds=+pxd

"3.使用:ctrl+x ctrl+]

"set tags+=/usr/include/tags

"}}}

"C库类型定义,函数声明,宏定义等

 

 

"单词列表匹配

"{{{

"ctrl+x ctrl+k

"apt-get install wordlist

"set dictionary-=/usr/share/dict/wordlist dictionary+=/usr/share/dict/wordlist

set dictionary+=~/.vim/c-support/wordlists/wordlist.list

set cpt=.,b,t

 

" .    scan the current buffer ('wrapscan' is ignored)

" w    scan buffers from other windows

" b    scan other loaded buffers that are in the buffer list

" u    scan the unloaded buffers that are in the buffer list

" U    scan the buffers that are not in the buffer list

" k    scan the files given with the 'dictionary' option

" kspell use the currently active spell checking |spell|

" k{dict}    scan the file {dict}. Several "k" flags can be given,

" patterns are valid too. For example: >

" :set cpt=k/usr/dict/*,k~/spanish

" s    scan the files given with the 'thesaurus' option

" s{tsr}    scan the file {tsr}. Several "s" flags can be given, patterns

" are valid too.

" i    scan current and included files

" d    scan current and included files for defined name or macro

" |i_CTRL-X_CTRL-D|

" ]    tag completion

" t    same as "]"

"}}}

"单词列表匹配

 

"括号智能匹配

"{{{

:inoremap ( () i

:inoremap ) =ClosePair(')')

:inoremap { {} i

:inoremap } =ClosePair('}')

:inoremap [ [] i

:inoremap ] =ClosePair(']')

:inoremap " "" i

:inoremap " =ClosePair('"')

":inoremap < <> i

":inoremap > =ClosePair('>')

function! ClosePair(char)

if getline('.')[col('.') - 1] == a:char

return "/ "

else

return a:char

endif

endf

"}}}

"括号智能匹配

 

 

 

"tab智能完成 使用实际的tab 需要shift+tab

"{{{

"ctrl + c 可以中断正在查找

"function! Smart_TabComplete()

" let line = getline('.') " curline

" let substr = strpart(line, -1, col('.')+1) " from start to cursor

" let substr = matchstr(substr, "[^ /t]*$") " word till cursor

" if (strlen(substr)==0) " nothing to match on empty string

" return "/ "

" endif

" let has_period = match(substr, '/.') != -1 " position of period, if any

" let has_slash = match(substr, '//') != -1 " position of slash, if any

" if (!has_period && !has_slash)

" return "/ / " " existing text matching

" elseif ( has_slash )

" return "/ / " " file matching

" else

" return "/ / " " plugin matching

" endif

"endfunction

"inoremap =Smart_TabComplete()

"}}}

"tab智能完成 使用实际的tab 需要shift+tab

 

 

 

"gf 命令 go file 到该文件去

"{{{

"set path+=/home/linux/u-boot-1.3.1/include/

"set path+=/usr/src/linux-headers-2.6.27-7/include/

"set path+=/usr/src/linux/include/

"}}}

"gf 命令 go file 到该文件去

 

 

 

 

"----------------------

"利用 插件 丰富 功能

"----------------------

 

"WinManager 插件 ( 不好用 )

""{{{

"let g:defaultExplorer=1

"let g:winManagerWindowLayout='FileExplorer|BufExplorer|TagList'

"let g:persistentBehaviour=0 "只剩一个窗口时, 退出vim.

"let g:winManagerWidth=80 "设置winmanager的宽度,默认为25

"nmap fir :FirstExplorerWindow

"nmap bot :BottomExplorerWindow

"nmap wm :WMToggle

"nmap :WMToggle "定义打开关闭winmanager按键

""}}}

"WinManager 插件 ( 不好用 )

 

 

 

"NERD_commenter.vim : 1218

""{{{

let NERDSpaceDelims=1

let NERD_c_alt_style=1

"Default mapping:

"[count],cc " 以行为单位进行注释.

" ,c " comment , <--> , uncomment. ( 常用 )

" ,cm " 一段为单位进行注释. ( 常用 )

" ,cs " 简洁美观式注释. ( 常用 , 可以嵌套注释,用,cu取消注释 )

" ,cy " Same as ,cc except that the commented line(s) are yanked first.

" ,c$ " 注释当前光标到行末的内容.

" ,cA " 在行末进行手动输入注释内容.

" ,ca " 切换注释方式(/**/ <--> //). ( 常用 )

" ,cl " Same cc, 左对齐.

" ,cb " Same cc, 两端对其.

" ,cu " Uncomments the selected line(s). ( 常用 )

"}}}

"NERD_commenter.vim : 1218

 

 

 

"F2单独切换打开NERD_tree(nerd_tree插件)

"{{{

let g:NERDChristmasTree = 1 "色彩显示

let g:NERDTreNERDShowHidden = 1 "显示隐藏文件

let g:NERDTreeWinPos = 'left' "窗口显示位置

let g:NERDTreeHighlightCursorline = 0 "高亮当前行

let g:NERDTreeWinSize = 40 "设置显示宽度

"nmap :NERDTreeToggle .

"

" o.......打开所选文件或目录 ( 常用 )

" enter..............相当于o

" go......类似o, 但光标仍然停留在NERD_tree ( 常用 )

" t.......在新标签中打开所选文件

" T.......类似t, 但光标仍然停留在NERD_tree

" i.......在一个水平分割窗口中打开文件

" gi......类似i, 但光标仍然停留在NERD_tree

" s.......在一个垂直分割窗口中打开文件.......................|NERDTree-s|

" gs......类似s, 但光标仍然停留在NERD_tree

" O.......递归打开所选目录

" 鼠标双击.......相当于o, 没错支持鼠标的~!

""}}}

"F2单独切换打开NERD_tree(nerd_tree插件)

 

 

 

"bufexplorer插件 (使用 NERD_tree)

"{{{

"map :BufExplorer

",be 打开选择窗口 ','是前面mapleader设置的 ( F3 )

"r可以进行反向排序.

"d/D可以用来关闭文件.

"p可以用来显示/关闭绝对路径模式

"}}}

"bufexplorer插件 (使用 NERD_tree)

 

 

 

"echofunc.vim 在命令行中显示函数信息 ( 不错 )

""{{{

"直接下载解压即可

""}}}

"echofunc.vim 在命令行中显示函数信息 ( 不错 )

 

 

 

"fencview.vim 对你打开的文件的编码自动识别

""{{{

"直接下载解压即可

""}}}

"fencview.vim 对你打开的文件的编码自动识别

 

 

 

"lookupfile插件默认会使用ctags产生的tag来查找,效率很低,使用下面脚本生成filenametags

""{{{

"当使用了acp.vim ( autocomplpop.vim)时, 该插件好像有点问题. 不过还是可以使用

"echo "!_TAG_FILE_SORTED    2    /2=foldcase/"; find . -not -iregex '.*/./(jar/|gif/|jpg/|class/|exe/|dll/|pdd/|sw[op]/|xls/|doc/|pdf/|zip/|tar/|ico/|ear/|war/|dat/).*' -type f -printf "%f/t%p/t1/n" | sort -f > ./filenametags

let g:LookupFile_MinPatLength = 2 "最少输入3个字符才开始查找

let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串

let g:LookupFile_PreservePatternHistory = 1 "保存查找历史

let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目

let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件

let g:LookupFile_SortMethod = "" "关闭对搜索结果的字母排序

let g:LookupFile_UpdateTime = 200

let g:LookupFile_AlwaysAcceptFirst = 1

let g:LookupFile_DefaultCmd = ':LUTags'

" Don't display binary files

let g:LookupFile_FileFilter = '/.class$/|/.o$/|/.obj$/|/.exe$/|/.jar$/|/.zip$/|/.war$/|/.ear$'

let g:LookupFile_TagExpr = string('/home/tags/filenametags')

 

"if filereadable("/home/tags/filenametags") "设置tag文件的名字

" let g:LookupFile_TagExpr ='"/home/tags/filenametags"'

"endif

 

"映射LookupFile为,lk

nmap lk :LUTags

"映射LUBufs为,ll

nmap ll :LUBufs

"映射LUWalk为,lw

nmap lw :LUWalk

 

" lookup file with ignore case

function! LookupFile_IgnoreCaseFunc(pattern)

let _tags = &tags

try

let &tags = eval(g:LookupFile_TagExpr)

let newpattern = '/c' . a:pattern

let tags = taglist(newpattern)

catch

echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE

return ""

finally

let &tags = _tags

endtry

 

" Show the matches for what is typed so far.

let files = map(tags, 'v:val["filename"]')

return files

endfunction

let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'

""}}}

"lookupfile插件默认会使用ctags产生的tag来查找,效率很低,使用下面脚本生成filenametags

 

 

 

"使用 autocomplpop.vim 插件 先已经被acp.vim替换

""{{{

" 1. 下载 autocomplpop.vim 后,放到Vim文件目录下的plugin目录中

" 2. 增加智能提示触发命令

" 3. 加入PHP的全能提示触发命令

"if !exists('g:AutoComplPop_Behavior')

" let g:AutoComplPop_Behavior = {}

" let g:AutoComplPop_Behavior['php'] = []

" call add(g:AutoComplPop_Behavior['php'], {'command': "//",'pattern': printf('/(->/|::/|/$/)/k/{%d,}$', 0),'repeat': 0,})

"endif

" 兼容 plugin/snipMate.vim 在snipMate.vim添加

" fun! GetSnipsInCurrentScope()

" let snips = {}

" for scope in [bufnr('%')] + split(&ft, '/.') + ['_']

" call extend(snips, get(s:snippets, scope, {}), 'keep')

" call extend(snips, get(s:multi_snips, scope, {}), 'keep')

" endfor

" return snips

" endf

let g:acp_behaviorSnipmateLength = 1 "兼容snipMate.vim

let g:acp_behaviorPerlOmniLength = 1 "配合perl-completion.vim

let g:acp_enableAtStartup = 1

"" * c = classes

"" * d = macro definitions

"" * e = enumerators (values inside an enumeration)

"" * f = function definitions

"" * g = enumeration names

"" * m = class, struct, and union members

"" * n = namespaces

"" * p = function prototypes

"" * s = structure names

"" * t = typedefs

"" * u = union names

"" * v = variable definitions

let g:acp_completeOption = '.,b,f,s,t,d'

let g:acp_behaviorFileLength = 2

""}}}

"使用 autocomplpop.vim 插件 先已经被acp.vim替换

 

 

 

"completeopt 弹出菜单 输入字母实现即时的过滤和匹配

""{{{

"关掉智能补全时的预览窗口 (Scratch)

" menu 使用弹出菜单来显示可能的补全

" longest 只插入匹配的最长公共文本

"set completeopt=menuone,menu,longest,preview

set completeopt=menu,longest

"filetype plugin on

"set ofu=syntaxcomplete#Complete

"

"filetype plugin indent on

autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete

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

if has("autocmd") && exists("+omnifunc")

autocmd Filetype *

/ if &omnifunc == "" |

/ setlocal omnifunc=syntaxcomplete#Complete |

/ endif

endif

let g:rubycomplete_buffer_loading = 1

let g:rubycomplete_classes_in_global = 1

"let g:rubycomplete_rails = 1

"

""}}}

"completeopt 弹出菜单 输入字母实现即时的过滤和匹配

 

 

 

 

"OmniCppComplete : C/C++ omni-completion with ctags database

""{{{

"set nocp "要关闭兼容 (上面已处理)

"map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . "要创建一个tags (上面已处理)

let OmniCpp_NamespaceSearch = 1

let OmniCpp_GlobalScopeSearch = 1

let OmniCpp_ShowAccess = 1

let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters

let OmniCpp_MayCompleteDot = 1 " autocomplete after .

let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->

let OmniCpp_MayCompleteScope = 1 " autocomplete after ::

let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]

"automatically open and close the popup menu / preview window

au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif

"set completeopt=menuone,menu,longest,preview

"自定义快捷键

inoremap pumvisible()?"/ ":"/ "

inoremap pumvisible()?"/ / / ":"/ "

inoremap pumvisible()?"/ / / ":"/ "

inoremap pumvisible()?"/ ":"/ "

"inoremap pumvisible()?"/ ":"/ "

"inoremap pumvisible()?"/ ":"/ "

"=================================

"注意:tab 是选择下一项, shift+tab 是选择上一项

"=================================

"上面的映射都是在插入模式下的映射,解释如下

"如果下拉菜单弹出,回车映射为接受当前所选项目,否则,仍映射为回车

"如果下拉菜单弹出,CTRL-J映射为在下拉菜单中向下翻页。否则映射为CTRL-X CTRL-O

"如果下拉菜单弹出,CTRL-K映射为在下拉菜单中向上翻页,否则仍映射为CTRL-K

"如果下拉菜单弹出,CTRL-U映射为CTRL-E,即停止补全,否则,仍映射为CTRL-U

"如果下拉菜单弹出,CTRL-P映射为在下拉菜单中表示上一项。

"如果下拉菜单弹出,CTRL-N映射为在下拉菜单中表示下一项。

":set omnifunc ? 查看设置的补全插件

autocmd FileType cpp set omnifunc=omni#cpp#complete#Main

""}}}

"OmniCppComplete : C/C++ omni-completion with ctags database

 

 

 

 

"让autocomlpop 支持snipMate.vim ( 上面已说明)

"{{{

"将下面fun写到snipMate.vim

"fun! GetSnipsInCurrentScope()

" let snips = {}

" for scope in [bufnr('%')] + split(&ft, '/.') + ['_']

" call extend(snips, get(s:snippets, scope, {}), 'keep')

" call extend(snips, get(s:multi_snips, scope, {}),'keep')

" endfor

" return snips

"endf

"let g:acp_behaviorSnipmateLength=1

"}}}

"让autocomlpop 支持snipMate.vim ( 上面已说明)

 

 

 

"加速你的补全 -- 插件: SuperTab 使用上面的,可以关闭这个

"{{{

"设置按下 后默认的补全方式, 默认是 ,

"现在改为 . 关于 的补全方式,

"还有其他的补全方式, 你可以看看下面的一些帮助:

":help ins-completion

":help compl-omni

" 0 - 不记录上次的补全方式

" 1 - 记住上次的补全方式,直到用其他的补全命令改变它

" 2 - 记住上次的补全方式,直到按 ESC 退出插入模式为止

"let g:SuperTabRetainCompletionType=2

"let g:SuperTabDefaultCompletionType=" "

"}}}

"加速你的补全 -- 插件: SuperTab 使用上面的,可以关闭这个

 

 

 

"教你高效地浏览源码 -- 插件: TagList

""{{{

"在taglist窗口中,可以使用下面的快捷键:

" 跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样

"o 在一个新打开的窗口中显示光标下tag

" 显示光标下tag的原型定义

"u 更新taglist窗口中的tag

"s 更改排序方式,在按名字排序和按出现顺序排序间切换

"x taglist窗口放大和缩小,方便查看较长的tag

"+ 打开一个折叠,同zo

"- 将tag折叠起来,同zc

"* 打开所有的折叠,同zR

"= 将所有tag折叠起来,同zM

"[[ 跳到前一个文件

"]] 跳到后一个文件

"q 关闭taglist窗口

" 显示帮助

"使用 :Tlist

":help taglist.txt ( ~/.vim/doc/taglist.txt )

"

"快捷键

"map :TlistToggle

"noremap :Tlist

"noremap :TlistSync

"快捷键

"

highlight Pmenu ctermbg=Green "guibg=LightGray

highlight PmenuSel ctermbg=Red "guibg=DarkGray guifg=White

highlight PmenuSbar ctermbg=Blue "guibg=DarkBlue

highlight PmenuThumb ctermbg=Yellow "guibg=Black

"设定Linux系统中ctags程序的位置

let Tlist_Ctags_Cmd = '/usr/bin/ctags'

"设定Linux系统中ctags程序的位置

"

"不同时显示多个文件的tag,只显示当前文件的

"let Tlist_Show_One_File=1

"不同时显示多个文件的tag,只显示当前文件的

"

"如果taglist窗口是最后一个窗口,则退出vim

let Tlist_Exit_OnlyWindow=1

"如果taglist窗口是最后一个窗口,则退出vim

"

"在右侧窗口中显示taglist窗口

let Tlist_Use_Right_Window = 1

"在右侧窗口中显示taglist窗口

"

"在左侧窗口中显示taglist窗口

"let Tlist_Use_Left_Window = 1

"在左右侧窗口中显示taglist窗口

"

" 缺省情况下,在双击一个tag时,才会跳到该tag定义的位置

let Tlist_Use_SingleClick= 1

" 缺省情况下,在双击一个tag时,才会跳到该tag定义的位置

"

"Taglist窗口宽度

let Tlist_WinWidth = 40

"Taglist窗口宽度

"

"在启动VIM后,自动打开taglist窗口

"let Tlist_Auto_Open=1

"在启动VIM后,自动打开taglist窗口

"

"taglist始终解析文件中的tag,不管taglist窗口有没有打开

"let Tlist_Process_File_Always=1

"taglist始终解析文件中的tag,不管taglist窗口有没有打开

"

"set 1 同时显示多个文件中的tag时,可使taglist只显示当前文件tag,其它文件的tag都被折叠起来

let Tlist_File_Fold_Auto_Close=1

"set 1 同时显示多个文件中的tag时,可使taglist只显示当前文件tag,其它文件的tag都被折叠起来

""}}}

"教你高效地浏览源码 -- 插件: TagList

 

 

 

"当查看源码是使用 -- 插件 : Cscope

""{{{

"是否使用 quickfix 窗口来显示 cscope 结果

set cscopequickfix=s-,c-,d-,i-,t-,e-

"0 或 s 查找本 C 符号(可以跳过注释)

"1 或 g 查找本定义

"2 或 d 查找本函数调用的函数 --可以到函数的定义处

"3 或 c 查找调用本函数的函数 --该函数被谁调用

"4 或 t 查找本字符串

"6 或 e 查找本 egrep 模式

"7 或 f 查找本文件

"8 或 i 查找包含本文件的文件

"ctrl + o 可以返回

nmap s :cs find s =expand(" ")

nmap g :cs find g =expand(" ")

nmap c :cs find c =expand(" ")

nmap t :cs find t =expand(" ")

nmap e :cs find e =expand(" ")

nmap f :cs find f =expand(" ")

nmap i :cs find i ^ =expand(" ") $

nmap d :cs find d =expand(" ")

 

"window split horizontally

nmap s :scs find s =expand(" ")     

nmap g :scs find g =expand(" ")     

nmap c :scs find c =expand(" ")     

nmap t :scs find t =expand(" ")     

nmap e :scs find e =expand(" ")     

nmap f :scs find f =expand(" ")     

nmap i :scs find i ^ =expand(" ") $     

nmap d :scs find d =expand(" ")     

 

"window split vertically

nmap s :vert scs find s =expand(" ")

nmap g :vert scs find g =expand(" ")

nmap c :vert scs find c =expand(" ")

nmap t :vert scs find t =expand(" ")

nmap e :vert scs find e =expand(" ")

nmap f :vert scs find f =expand(" ")     

nmap i :vert scs find i ^ =expand(" ") $     

nmap d :vert scs find d =expand(" ")

 

"使用方法

"生成一个 cscope 的数据库

"1.cd /usr/src/linux/

"2.cscope -Rbq

"cs add /usr/src/linux/cscope.out /usr/src/linux/

"reset : 重新初始化所有连接. 用法 : cs reset

"

"1.下載cscope包 http://cscope.sourceforge.net/

"2.安裝cscope A../configure B.make C.make install

"3.修改set csprg 位置 :/usr/local/bin/cscope

"4.F3

"5.测试(1)cscope find g 函数名 (2) cscope find c 函数名

"6. :cw 显示多个结果

"

"下面是shell脚本,放到源码目录下运行

"#!/bin/sh

"find . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files

"cscope -bkq -i cscope.files

"ctags -R

"上面是shell脚本,放到源码目录下运行

"

"下面是对cscope -Rbkq 的解释

"-R: 在生成索引文件时,搜索子目录树中的代码

"-b: 只生成索引文件,不进入cscope的界面

"-k: 在生成索引文件时,不搜索/usr/include目录

"-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度

"下面是对cscope -Rbkq 的解释

"

"-------------当前使用 快键----------

"noremap :!./vitags.sh :cs reset

"noremap :! cscope -Rbq :cs reset

"

"cscope和ctags的兼容问题

if has("cscope")

    set csprg=/usr/bin/cscope

    set csto=0

    set cst "具有Ctags快捷键功能eg. ctrl+] , ctrl + t

    set nocsverb

    " add any database in current directory

    if filereadable("cscope.out")

     cs add cscope.out

    " else add database pointed to by environment

    elseif $CSCOPE_DB !=" "

     "cs add $CSCOPE_DB "这是一个很好的方法

    endif

"个人添加

"========= vim 打开文件时自动加载 ========

cs add /home/tags/cscope.out /home/tags

cs add /usr/include/cscope.out /usr/include

"========= vim 打开文件时自动加载 ========

"个人添加

    set csverb

    set cscopetag

endif

"cscope和ctags的兼容问题

":help if_cscop.txt

":cs show

"}}}

"当查看源码是使用 -- 插件 : Cscope

 

 

 

"利用c.vim插件实现,下载后解压到~/.vim中

""{{{

"1.添加文件头注释(自动完成)

"2.添加c函数(标准模式执行/if, 再输入函数名)

"3.添加main函数(标准模式执行/im)

"4.添加函数注释 (标准模式执行/cfu)

"5.添加注释框架 (标准模式执行/cfr)

"6.添加头文件 (标准模式执行/p

"7.添加宏定义 (标准模式执行/pd)

"8.添加代码片段

"(标准模式执行/nr,需在~/.vim/c-support/codesnippets/中加入存放代码的文件)

" Help -----------------------------------------------

" /hm show manual for word under the cursor (n,i)

" /hp show plugin help (n,i)

 

" -- Comments -------------------------------------------

" /cl end-of-line comment (n,v,i)

" /cj adjust end-of-line comment(s) (n,v,i)

" /cs set end-of-line comment column (n)

" /c* code -> comment /* */ (n,v)

" /cc code -> comment // (n,v)

" /co comment -> code (n,v)

" /cfr frame comment (n,i)

" /cfu function comment (n,i)

" /cme method description (n,i)

" /ccl class description (n,i)

" /cd date (n,v,i)

" /ct date /& time (n,v,i)

 

" -- Statements ------------------------------------------

" /sd do { } while (n,v,i)

" /sfo for { } (n,v,i)

" /sife if { } else { } (n,v,i)

" /se else { } (n,v,i)

" /swh while { } (n,v,i)

" /ss switch (n,v,i)

 

" -- Preprocessor -----------------------------------------

" /p< #include <> (n,i)

" /p'' #include "" (n,i)

" /pd #define (n,i)

" /pu #undef (n,i)

" /pie #if #else #endif (n,v,i)

" /pid #ifdef #else #endif (n,v,i)

" /pin #ifndef #else #endif (n,v,i)

" /pind #ifndef #def #endif (n,v,i)

" /pi0 #if 0 #endif (n,v,i)

" /pr0 remove #if 0 #endif (n,i)

" /pe #error (n,i)

" /pl #line (n,i)

" /pp #pragma (n,i)

 

" -- Idioms ------------------------------------------------

" /if function (n,v,i)

" /isf static function (n,v,i)

" /im main() (n,v,i)

" /i0 for( x=0; x

" /in for( x=n-1; x>=0; x-=1 ) (n,v,i)

" /ie enum + typedef (n,i)

" /is struct + typedef (n,i)

" /iu union + typedef (n,i)

" /ip printf() (n,i)

" /isc scanf() (n,i)

" /ica p=calloc() (n,i)

" /ima p=malloc() (n,i)

" /isi sizeof() (n,v,i)

" /ias assert() (n,v)

" /ii open input file (n,i)

" /io open output file (n,i)

 

" -- Snippets ------------------------------------------------

" /nr read code snippet (n,i)

" /nw write code snippet (n,v,i)

" /ne edit code snippet (n,i)

" /np pick up prototype (n,v,i)

" /ni insert prototype(s) (n,i)

" /nc clear prototype(s) (n,i)

" /ns show prototype(s) (n,i)

" /ntl edit local templates (n,i)

" /ntg edit global templates (n,i)

" /ntr rebuild templates (n,i)

 

" -- C++ ----------------------------------------------------

" /+co cout << << endl; (n,i)

" /+c class (n,i)

" /+cn class (using new) (n,i)

" /+ci class implementation (n,i)

" /+cni class (using new) implementation (n,i)

" /+mi method implementation (n,i)

" /+ai accessor implementation (n,i)

 

" /+tc template class (n,i)

" /+tcn template class (using new) (n,i)

" /+tci template class implementation (n,i)

" /+tcni template class (using new) impl. (n,i)

" /+tmi template method implementation (n,i)

" /+tai template accessor implementation (n,i)

 

" /+tf template function (n,i)

" /+ec error class (n,i)

" /+tr try ... catch (n,v,i)

" /+ca catch (n,v,i)

" /+c. catch(...) (n,v,i)

 

" -- Run ---------------------------------------------------

" /rc save and compile (n,i)

" /rl link (n,i)

" /rr run (n,i)

" /ra set comand line arguments (n,i)

" /rm run make (n,i)

" /rg cmd. line arg. for make (n,i)

" /rp run splint (n,i)

" /ri cmd. line arg. for splint (n,i)

" /rk run CodeCheck (TM) (n,i)

" /re cmd. line arg. for CodeCheck (TM) (n,i)

" /rd run indent (n,v,i)

" /rh hardcopy buffer (n,v,i)

" /rs show plugin settings (n,i)

" /rx set xterm size (n, only Linux/UNIX & GUI)

" /ro change output destination (n,i) ( buffer xterm vim )

"filetype plugin on

"}}}

"利用c.vim插件实现,下载后解压到~/.vim中

 

 

 

"a.vim实现源文件与头文件切换

"{{{

let alternateSearchPath = 'sfr:.,sfr:./include,sfr:../include' "设置include(.h)文件存在何处.

let alternateNoDefaultAlternate = 1 "当没有找到相应的.h文件时,不自动创建

"nnoremap :A "上面已映射

":A 切换当前文件的头文件,在当前窗口打开(或者反过来) "先打开.h .c 文件存于buff中

":AS 功能同:A,但是切换到水平分割窗口的打开

":AV 功能同:A,但是切换到竖直分割的窗口打开

":AT 功能同:A,但是切换到标签页打开

"}}}

"a.vim实现源文件与头文件切换

 

 

 

"ShowMarks高亮功能显示出标记的位置( 先使用vim提供的sign功能进行标记位置 )

"{{{

let showmarks_enable = 1 "使能showmarks插件

"Show which marks:全部的大写标记和小写 ( 推荐只使用小写, 大写可能有bug )

let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

" Ignore help, quickfix, non-modifiable buffers:对文件类型为help, quickfix, 和不可修改的缓冲区,不显示标记的位置

let showmarks_ignore_type = "hqm"

" Hilight lower & upper marks

let showmarks_hlline_lower = 1

let showmarks_hlline_upper = 1

 

hi ShowMarksHLl ctermbg=Red ctermfg=Magenta "guibg=#FFDB72 guifg=Black

hi ShowMarksHLu ctermbg=Yellow ctermfg=Black "guibg=#FFB3FF guifg=Black

 

"ShowMarks插件中已经定义了一些快捷键:

",mt - 打开/关闭ShowMarks插件 ( 常用 )

",mo - 强制打开ShowMarks插件

",mh - 清除当前行的标记 ( 常用 )

",ma - 清除当前缓冲区中所有的标记 ( 常用 )

",mm - 在当前行打一个标记,使用下一个可用的标记名 ( 常用 )

"}}}

"ShowMarks高亮功能显示出标记的位置( 先使用vim提供的sign功能进行标记位置 )

 

 

 

"----------------------

"利用 插件 丰富 功能

"----------------------

 

" 尚未实践的功能

""{{{

"" Highlight All Function

"========================================================

"syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>[^()]*)("me=e-2

"syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>/s*("me=e-1

"hi cFunction gui=NONE guifg=#B5A1FF

"

""========================================================

"" Highlight All Math Operator

" "========================================================

" " C math operators

" syn match cMathOperator display "[-+/*/%=]"

" " C pointer operators

" syn match cPointerOperator display "->/|/."

" " C logical operators - boolean results

" syn match cLogicalOperator display "[!<>]=/="

" syn match cLogicalOperator display "=="

" " C bit operators

" syn match cBinaryOperator display "/(&/||/|/^/|< >/)=/="

" syn match cBinaryOperator display "/~"

" syn match cBinaryOperatorError display "/~="

" " More C logical operators - highlight in preference to binary

" syn match cLogicalOperator display "&&/|||"

" syn match cLogicalOperatorError display "/(&&/|||/)="

"

" " Math Operator

" hi cMathOperator guifg=#3EFFE2

" hi cPointerOperator guifg=#3EFFE2

" hi cLogicalOperator guifg=#3EFFE2

" hi cBinaryOperator guifg=#3EFFE2

" hi cBinaryOperatorError guifg=#3EFFE2

" hi cLogicalOperator guifg=#3EFFE2

" hi cLogicalOperatorError guifg=#3EFFE2))

" "}}}

" 尚未实践的功能

 

" 临时

""{{{

set tags+=/home/tags/tags

""}}}

" 临时

 

 

"==================================以下是个人喜爱使用的vim(or 插件)其他强大功能===========================

"

"vim master

""{{{

"

"Verdancy --- New Commer

""{{{

" f --- find; practic : (before)"aabbbccdd" --> ex: dfc --> (after)"cdd"

"

"寄存器

""{{{

" q[a-z] --- 记录命令, 已q结束, @[a-z]引用 --- 很强大,需要习惯使用

" "[a-z]p --- 可以将寄存器[a-z]中的命令以文本的方式输出,并进行修改

" "[a-z]y$ --- 将寄存器修改后的内容存回到对应寄存器

""}}}

"寄存器

"

""}}}

"Verdancy --- New Commer

"

"Visual 选中模式

""{{{

" shift + v : 配合jk,上下键,整行选择

" ctrl + v : 配合hjkl,上下左右键,灵活选择区域

" o : 在选中的区域中对角线移动

" O : 在选中的区域中行左右移动

" gv : 重新选中原来的选中的区域

" : : 在选中区域后,shift+:到命令模式, : eg. '<,'>s/pattern/newstring/g -- 在选中的区域中查找patte && replace

" ctrl + v 选中一列后, 按I插入字符,Esc退出 : 每一行都添加这个字符,很好的一个注释方法

""}}}

"Visual 选中模式

"

"Command Mode

""{{{

" :g/pattern/d --- delete line contained of string "pattern"

""}}}

"Command Mode

"

"窗口

""{{{

"ctrl + 0 : 恢复窗口大小

"ctrl + = : 窗口等大

"ctrl + w + _ : 窗口最大化

"nctrl + w + _ : 改变窗口的大小

"ctrl + w + ctrl + c : 关闭窗口

"ctrl + w + ctrl + ] : 以函数所在文件分割窗口

"ctrl + w + shift + [hjkl] : 窗口位置放置

"

"shift + z + z : close vim edit. You need set auto write.

"

"vim t1.c t2.c t3.c -o2 : open thress files using two windows. if -o(no number), using three windows here.

""}}}

"窗口

"

"杂项

""{{{

" !!date --- 插入日期

" read !date -R --- 插入日期 ( -R 显示日期的格式而已 man date )

"

" ctr + w ctrl + c --- 关闭当前窗口

"

" %s//s/+$// --- 删除多余的空格

"

" ctrl + K --- 插入特殊字符

" digraph --- 显示特殊字符,字符组合

"

" set ic --- 忽略大小写

"

" . --- 重复前次操作

"

" ctrl + a --- repeat record.

"

" ctrl + r --- 反撤消, 当u撤消后,又想恢复,可以使用

"

" daw && caw && cis --- delete a word && change a word && 修改一个句子

"

" cc && dd --- change one line reserving indent && delete one line

"

" CTRL+U ---- CTRL+D ---> half page move

" CTRL+E ---- CTRL+Y ---> one line move

" CTRL+F ---- CTRL+B ---> one page move

"

" CTRL + O --- 返回刚才位置,每按一次都会退回到之前的位置

" CTRL + I --- 与CTRL+O相反,每按一次退回来

"

" [i --- (将光标移到变量上)显示第一个局部变量定义处

" [I --- (将光标移到变量上)显示所有该变量的定义处

" '' --- 回到刚才停留处

"

" // ---- 精确查找

"

"

""}}}

"杂项

"

""}}}

"vim master

"

"Shell

""{{{

"巧妙去除Linux下代码行中的^M符号和windows下代码编辑引起的警告错

":%s /^M//g ,其中^M的写法是按住ctrl不放,再按v,然后按M,再放ctrl

""{{{

" #wash_error.sh

" #!/bin/sh

" ls *.h *.c | awk '{print $1}' > dealfile

" cat dealfile | while read file

" do

" echo " " >> $file

" done

" #dos2unix *.c *.h

""}}}

"巧妙去除Linux下代码行中的^M符号和windows下代码编辑引起的警告错

""}}}

"Shell

"

"==================================以上是个人喜爱使用的vim(or 插件)其他强大功能===========================

你可能感兴趣的:(Vimrc – 15.0)