zoukankan      html  css  js  c++  java
  • 关于vim的一些记录

    vim 配置

    http://www.162cm.com/archives/906.html

    vim 编码问题

    http://blog.csdn.net/topgun38/article/details/8016227

    用vim 转码

    http://www.cnblogs.com/joeblackzqq/archive/2011/04/11/2012008.html

    vim的自动补全

    http://www.vim.org/scripts/script.php?script_id=2358

    http://www.cnblogs.com/xuqiang/archive/2011/04/15/2016475.html 

    OmniCppComplete plugin安装步骤:http://blog.copyninja.info/2010/02/cc-auto-complete-for-vim.html

    1. OmniCppComplete plugin for the vim
    2. exuberant-ctags. (if you are using Debian based distro's you can use this command sudo apt-get install exuberant-ctags)
    3. CPP STL source for ctags

    我目前的vimrc

      1 " All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
      2 " /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
      3 " you can find below.  If you wish to change any of those settings, you should
      4 " do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
      5 " everytime an upgrade of the vim packages is performed.  It is recommended to
      6 " make changes after sourcing debian.vim since it alters the value of the
      7 " 'compatible' option.
      8 
      9 " This line should not be removed as it ensures that various options are
     10 " properly set to work with the Vim-related packages available in Debian.
     11 runtime! debian.vim
     12 
     13 " Uncomment the next line to make Vim more Vi-compatible
     14 " NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
     15 " options, so any other options should be set AFTER setting 'compatible'.
     16 "set compatible
     17 
     18 " Vim5 and later versions support syntax highlighting. Uncommenting the next
     19 " line enables syntax highlighting by default.
     20 if has("syntax")
     21   syntax on
     22 endif
     23 
     24 " If using a dark background within the editing area and syntax highlighting
     25 " turn on this option as well
     26 "set background=dark
     27 
     28 " Uncomment the following to have Vim jump to the last position when
     29 " reopening a file
     30 "if has("autocmd")
     31 "  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
     32 "endif
     33 
     34 " Uncomment the following to have Vim load indentation rules and plugins
     35 " according to the detected filetype.
     36 "if has("autocmd")
     37 "  filetype plugin indent on
     38 "endif
     39 
     40 " The following are commented out as they cause vim to behave a lot
     41 " differently from regular Vi. They are highly recommended though.
     42 "set showcmd        " Show (partial) command in status line.
     43 "set showmatch        " Show matching brackets.
     44 "set ignorecase        " Do case insensitive matching
     45 "set smartcase        " Do smart case matching
     46 "set incsearch        " Incremental search
     47 "set autowrite        " Automatically save before commands like :next and :make
     48 "set hidden             " Hide buffers when they are abandoned
     49 "set mouse=a        " Enable mouse usage (all modes)
     50 
     51 " Source a global configuration file if available
     52 if filereadable("/etc/vim/vimrc.local")
     53   source /etc/vim/vimrc.local
     54 endif
     55 
     56 
     57 " An example for a vimrc file.
     58 "
     59 " Maintainer: a18ccms <a18ccms@gmail.com>
     60 " Last change: 2010 03 12
     61 "
     62 " To use it, copy it to
     63 " for Unix and OS/2: ~/.vimrc
     64 " for Amiga: s:.vimrc
     65 " for MS-DOS and Win32: $VIM\_vimrc
     66 " for OpenVMS: sys$login:.vimrc
     67  
     68 " When started as "evim", evim.vim will already have done these settings.
     69 if v:progname =~? "evim"
     70 finish
     71 endif
     72  
     73 set history=50   " keep 50 lines of command line history
     74 set showcmd   " display incomplete commands
     75  
     76 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
     77 " let &guioptions = substitute(&guioptions, "t", "", "g")
     78  
     79 " Don't use Ex mode, use Q for formatting
     80 map Q gq
     81  
     82 " Convenient command to see the difference between the current buffer and the
     83 " file it was loaded from, thus the changes you made.
     84 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
     85 \ | wincmd p | diffthis
     86 \ | wincmd p | diffthis
     87  
     88 set guioptions-=T
     89  
     90 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     91 " 一般设定
     92 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     93 " 设定默认解码
     94 set encoding=utf-8
     95 set fileencodings=utf-8,chinese,latin-1
     96 if has("win32")
     97 set fileencoding=chinese
     98 else
     99 set fileencoding=utf-8
    100 endif
    101 language message zh_CN.utf-8
    102 "解决菜单乱码
    103 source $VIMRUNTIME/delmenu.vim
    104 source $VIMRUNTIME/menu.vim
    105 "set font
    106 "set guifont=Nsimsun
    107  
    108 "设置窗口大小
    109 set lines=35
    110 set columns=120
    111  
    112 " 不要使用vi的键盘模式,而是vim自己的
    113 "set nocompatible
    114  
    115 " 在处理未保存或只读文件的时候,弹出确认
    116 set confirm
    117  
    118 " 与windows共享剪贴板
    119 set clipboard+=unnamed
    120  
    121 " 侦测文件类型
    122 filetype on
    123  
    124 " 载入文件类型插件
    125 filetype plugin on
    126  
    127 " 为特定文件类型载入相关缩进文件
    128 filetype indent on
    129  
    130 " 带有如下符号的单词不要被换行分割
    131 set iskeyword+=_,$,@,%,#,-
    132  
    133 " 语法高亮
    134 syntax on
    135  
    136 " 高亮字符,让其不受100列限制
    137 ":highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
    138 ":match OverLength '\%101v.*'
    139  
    140 " 状态行颜色
    141 "highlight StatusLine guifg=SlateBlue guibg=Yellow
    142 "highlight StatusLineNC guifg=Gray guibg=White
    143  
    144 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    145 " 文件设置
    146 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    147 " 不要备份文件(根据自己需要取舍)
    148 set nobackup
    149  
    150 " 不要生成swap文件,当buffer被丢弃的时候隐藏它
    151 setlocal noswapfile
    152 set bufhidden=hide
    153  
    154 " 字符间插入的像素行数目
    155 set linespace=0
    156  
    157 " 增强模式中的命令行自动完成操作
    158 set wildmenu
    159  
    160 " 在状态行上显示光标所在位置的行号和列号
    161 set ruler
    162 set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
    163  
    164 " 命令行(在状态行下)的高度,默认为1,这里是2
    165 set cmdheight=2
    166  
    167 " 使回格键(backspace)正常处理indent, eol, start等
    168 set backspace=2
    169  
    170 " 允许backspace和光标键跨越行边界
    171 set whichwrap+=<,>,h,l
    172  
    173 " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
    174 set mouse=a
    175 set selection=exclusive
    176 set selectmode=mouse,key
    177  
    178 " 启动的时候不显示那个援助索马里儿童的提示
    179 set shortmess=atI
    180  
    181 " 通过使用: commands命令,告诉我们文件的哪一行被改变过
    182 set report=0
    183  
    184 " 不让vim发出讨厌的滴滴声
    185 set noerrorbells
    186  
    187 " 在被分割的窗口间显示空白,便于阅读
    188 set fillchars=vert:\ ,stl:\ ,stlnc:\
    189  
    190 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    191 " 搜索和匹配
    192 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    193 " 高亮显示匹配的括号
    194 set showmatch
    195  
    196 " 匹配括号高亮的时间(单位是十分之一秒)
    197 set matchtime=5
    198  
    199 " 在搜索的时候忽略大小写
    200 set ignorecase
    201  
    202 " 高亮被搜索的句子(phrases)
    203 set hlsearch
    204  
    205 " 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
    206 set incsearch
    207  
    208 " 输入:set list命令是应该显示些啥?
    209 set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
    210  
    211 " 光标移动到buffer的顶部和底部时保持3行距离
    212 set scrolloff=3
    213  
    214 " 不要闪烁
    215 set novisualbell
    216  
    217 " 我的状态行显示的内容(包括文件类型和解码)
    218 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
    219  
    220 " 总是显示状态行
    221 set laststatus=2
    222  
    223 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    224 " 文本格式和排版
    225 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    226 " 自动格式化
    227 set formatoptions=tcrqn
    228  
    229 " 继承前一行的缩进方式,特别适用于多行注释
    230 set autoindent
    231  
    232 " 为C程序提供自动缩进
    233 set smartindent
    234  
    235 " 使用C样式的缩进
    236 set cindent
    237  
    238 " 制表符为4
    239 set tabstop=4
    240  
    241 " 统一缩进为4
    242 set softtabstop=4
    243 set shiftwidth=4
    244  
    245 " 不要用空格代替制表符
    246 set noexpandtab
    247  
    248 " 不要换行
    249 set nowrap
    250  
    251 " 在行和段开始处使用制表符
    252 set smarttab
    253  
    254 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    255 " Autocommands
    256 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    257 " 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示
    258  
    259 if has("autocmd")
    260    autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number
    261    autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
    262    autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o
    263    autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
    264    autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
    265    autocmd BufReadPost *
    266       \ if line("'\"") > 0 && line("'\"") <= line("$") |
    267       \   exe "normal g`\"" |
    268       \ endif
    269 endif " has("autocmd")
    270  
    271 "设置Java代码的自动补全
    272 au FileType java setlocal omnifunc=javacomplete#Complete
    273  
    274 let mapleader = "."
    275 "绑定自动补全的快捷键<C-X><C-O>到<leader>;
    276 imap <leader>; <C-X><C-O>
    277  
    278 "设定开关Taglist插件的快捷键为F4,可以在VIM的左侧栏列出函数列表等
    279 map <F4> :Tlist<CR>
    280  
    281 "设置程序的编译运行和调试的快捷键F5,F6,Ctrl-F5
    282 map <F5> :call CompileRun()<CR>
    283 map <C-F5> :call Debug()<CR>
    284 map <F6> :call Run()<CR>
    285  
    286 "设置代码格式化快捷键F3
    287 map <F3> :call FormartSrc()<CR>
    288  
    289 "设置tab操作的快捷键,绑定:tabnew到<leader>t,绑定:tabn, :tabp到<leader>n,
    290 "<leader>p
    291 map <leader>t :tabnew<CR>
    292 map <leader>n :tabn<CR>
    293 map <leader>p :tabp<CR>
    294  
    295 "用cscope支持
    296 "set csprg=d:\bin\cscope
    297  
    298 "使用<leader>e打开当前文件同目录中的文件
    299 if has("unix")
    300 map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
    301 else
    302 map ,e :e <C-R>=expand("%:p:h") . "\" <CR>
    303 endif
    304  
    305 "定义CompileRun函数,用来调用进行编译和运行
    306 func CompileRun()
    307 exec "w"
    308 "C程序
    309 if &filetype == 'c'
    310 exec "!del %<.exe"
    311 exec "!gcc % -o %<.exe"
    312 exec "!%<.exe"
    313 elseif &filetype == 'cpp'
    314 exec "!del %<.exe"
    315 exec "!g++ % -o %<.exe"
    316 exec "!%<.exe"
    317 "Java程序
    318 elseif &filetype == 'java'
    319 exec "!del %<.class"
    320 exec "!javac %"
    321 exec "!java %<"
    322 endif
    323 endfunc
    324 "结束定义CompileRun
    325  
    326 "定义Run函数,用来调用进行编译和运行
    327 func Run()
    328 exec "w"
    329 "C程序
    330 if &filetype == 'c'
    331 exec "!%<.exe"
    332 elseif &filetype == 'cpp'
    333 exec "!%<.exe"
    334 "Java程序
    335 elseif &filetype == 'java'
    336 exec "!java %<"
    337 endif
    338 endfunc
    339 "结束定义Run
    340  
    341 "定义Debug函数,用来调试程序
    342 func Debug()
    343 exec "w"
    344 "C程序
    345 if &filetype == 'c'
    346 exec "!del %<.exe"
    347 exec "!gcc % -g -o %<.exe"
    348 exec "!gdb %<.exe"
    349 elseif &filetype == 'cpp'
    350 exec "!del %<.exe"
    351 exec "!g++ % -g -o %<.exe"
    352 exec "!gdb %<.exe"
    353 "Java程序
    354 exec "!del %<.class"
    355 elseif &filetype == 'java'
    356 exec "!javac %"
    357 exec "!jdb %<"
    358 endif
    359 endfunc
    360 "结束定义Debug
    361 "定义FormartSrc()
    362 func FormartSrc()
    363 exec "w"
    364 "C程序,Perl程序,Python程序
    365 if &filetype == 'c'
    366 exec "!astyle --style=gnu --suffix=none %"
    367 exec "e! %"
    368 elseif &filetype == 'cpp'
    369 exec "!astyle --style=gnu --suffix=none %"
    370 exec "e! %"
    371 elseif &filetype == 'perl'
    372 exec "!astyle --style=gnu --suffix=none %"
    373 exec "e! %"
    374 elseif &filetype == 'py'
    375 exec "!astyle --style=gnu --suffix=none %"
    376 exec "e! %"
    377 "Java程序
    378 elseif &filetype == 'java'
    379 exec "!astyle --style=java --suffix=none %"
    380 exec "e! %"
    381 elseif &filetype == 'jsp'
    382 exec "!astyle --style=gnu --suffix=none %"
    383 exec "e! %"
    384 elseif &filetype == 'xml'
    385 exec "!astyle --style=gnu --suffix=none %"
    386 exec "e! %"
    387 elseif &filetype == 'html'
    388 exec "!astyle --style=gnu --suffix=none %"
    389 exec "e! %"
    390  
    391 elseif &filetype == 'htm'
    392 exec "!astyle --style=gnu --suffix=none %"
    393 exec "e! %"
    394  
    395 endif
    396 endfunc
    397 "结束定义FormartSrc
    398  
    399 " 能够漂亮地显示.NFO文件
    400 set encoding=utf-8
    401 function! SetFileEncodings(encodings)
    402     let b:myfileencodingsbak=&fileencodings
    403     let &fileencodings=a:encodings
    404 endfunction
    405 function! RestoreFileEncodings()
    406     let &fileencodings=b:myfileencodingsbak
    407     unlet b:myfileencodingsbak
    408 endfunction
    409  
    410 au BufReadPre *.nfo call SetFileEncodings('cp437')|set ambiwidth=single
    411 au BufReadPost *.nfo call RestoreFileEncodings()
    412  
    413 " 高亮显示普通txt文件(需要txt.vim脚本)
    414 au BufRead,BufNewFile * setfiletype txt
    415  
    416 " 用空格键来开关折叠
    417 set foldenable
    418 set foldmethod=manual
    419 nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
    420  
    421 "colo darkblue
    422 set tags+=~/.vim/tags/cpp
    423 set tags+=~/.vim/tags/gl
    424 set tags+=~/.vim/tags/sdl
    425 set tags+=~/.vim/tags/qt4
    426 
    427 
    428 "自动补全
    429 "
    430 :inoremap ( ()<ESC>i
    431 "
    432 :inoremap ) <c-r>=ClosePair(')')<CR>
    433 "
    434 :inoremap { {<CR>}<ESC>O
    435 "
    436 :inoremap } <c-r>=ClosePair('}')<CR>
    437 "
    438 :inoremap [ []<ESC>i
    439 "
    440 :inoremap ] <c-r>=ClosePair(']')<CR>
    441 "
    442 :inoremap " ""<ESC>i
    443 "
    444 :inoremap ' ''<ESC>i
    445 "
    446 function! ClosePair(char)
    447     if getline('.')[col('.') - 1] == a:char
    448             return "\<Right>"
    449     else
    450         return a:char
    451     endif
    452 endfunction
    453 
    454 set completeopt=longest,menu
    455 
    456 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    457 
    458 " CTags的设定  
    459 "
    460 " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    461 
    462 let Tlist_Sort_Type = "name"    " 按照名称排序  
    463 
    464 let Tlist_Use_Right_Window = 1  " 在右侧显示窗口  
    465 
    466 let Tlist_Compart_Format = 1    " 压缩方式  
    467 
    468 let Tlist_Exist_OnlyWindow = 1  " 如果只有一个buffer,kill窗口也kill掉buffer  
    469 
    470 let Tlist_File_Fold_Auto_Close = 0  " 不要关闭其他文件的tags  
    471 
    472 let Tlist_Enable_Fold_Column = 0    " 不要显示折叠树  
    473 
    474 autocmd FileType java set tags+=D:\tools\java\tags  
    475 
    476 autocmd FileType h,cpp,cc,c set tags+=D:\tools\cpp\tags  
    477 
    478 let Tlist_Show_One_File=1            "不同时显示多个文件的tag,只显示当前文件的
    479 
    480 ""设置tags  
    481 
    482 set tags=tags  
    483 
    484 "set autochdir 
    485 
    486 
    487 
    488 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    489 
    490 "其他东东
    491 
    492 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    493 
    494 "默认打开Taglist 
    495 
    496 let Tlist_Auto_Open=1 
    497 
    498 """""""""""""""""""""""""""""" 
    499 
    500 " Tag list (ctags) 
    501 
    502 """""""""""""""""""""""""""""""" 
    503 
    504 let Tlist_Ctags_Cmd = '/usr/bin/ctags' 
    505 
    506 let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的 
    507 
    508 let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim 
    509 let TList_Use_Left_Window = 1 

    我的vimrc(二)

      1 " All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
      2  " /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
      3  " you can find below.  If you wish to change any of those settings, you should
      4  " do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
      5  " everytime an upgrade of the vim packages is performed.  It is recommended to
      6  " make changes after sourcing debian.vim since it alters the value of the
      7  " 'compatible' option.
      8  
      9  " This line should not be removed as it ensures that various options are
     10  " properly set to work with the Vim-related packages available in Debian.
     11  runtime! debian.vim
     12  
     13  " Uncomment the next line to make Vim more Vi-compatible
     14  " NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
     15  " options, so any other options should be set AFTER setting 'compatible'.
     16  "set compatible
     17  
     18  " Vim5 and later versions support syntax highlighting. Uncommenting the next
     19  " line enables syntax highlighting by default.
     20  if has("syntax")
     21    syntax on
     22  endif
     23  
     24  " If using a dark background within the editing area and syntax highlighting
     25  " turn on this option as well
     26  "set background=dark
     27  
     28  " Uncomment the following to have Vim jump to the last position when
     29  " reopening a file
     30  "if has("autocmd")
     31  "  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
     32  "endif
     33  
     34  " Uncomment the following to have Vim load indentation rules and plugins
     35  " according to the detected filetype.
     36  "if has("autocmd")
     37  "  filetype plugin indent on
     38  "endif
     39  
     40  " The following are commented out as they cause vim to behave a lot
     41  " differently from regular Vi. They are highly recommended though.
     42  "set showcmd        " Show (partial) command in status line.
     43  "set showmatch        " Show matching brackets.
     44  "set ignorecase        " Do case insensitive matching
     45  "set smartcase        " Do smart case matching
     46  "set incsearch        " Incremental search
     47  "set autowrite        " Automatically save before commands like :next and :make
     48  "set hidden             " Hide buffers when they are abandoned
     49  "set mouse=a        " Enable mouse usage (all modes)
     50  
     51  " Source a global configuration file if available
     52  if filereadable("/etc/vim/vimrc.local")
     53    source /etc/vim/vimrc.local
     54  endif
     55  
     56  
     57  " An example for a vimrc file.
     58  "
     59  " Maintainer: a18ccms <a18ccms@gmail.com>
     60  " Last change: 2010 03 12
     61  "
     62  " To use it, copy it to
     63  " for Unix and OS/2: ~/.vimrc
     64  " for Amiga: s:.vimrc
     65  " for MS-DOS and Win32: $VIM\_vimrc
     66  " for OpenVMS: sys$login:.vimrc
     67   
     68  " When started as "evim", evim.vim will already have done these settings.
     69  if v:progname =~? "evim"
     70  finish
     71  endif
     72   
     73  set history=50   " keep 50 lines of command line history
     74  set showcmd   " display incomplete commands
     75   
     76  " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
     77  " let &guioptions = substitute(&guioptions, "t", "", "g")
     78   
     79  " Don't use Ex mode, use Q for formatting
     80  map Q gq
     81   
     82  " Convenient command to see the difference between the current buffer and the
     83  " file it was loaded from, thus the changes you made.
     84  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
     85  \ | wincmd p | diffthis
     86  \ | wincmd p | diffthis
     87   
     88  set guioptions-=T
     89   
     90  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     91  " 一般设定
     92  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     93  " 设定默认解码
     94  set encoding=utf-8
     95  set fileencodings=utf-8,chinese,latin-1
     96  if has("win32")
     97  set fileencoding=chinese
     98  else
     99  set fileencoding=utf-8
    100  endif
    101  language message zh_CN.utf-8
    102  "解决菜单乱码
    103  source $VIMRUNTIME/delmenu.vim
    104  source $VIMRUNTIME/menu.vim
    105  "set font
    106  "set guifont=Nsimsun
    107   
    108  "设置窗口大小
    109  set lines=35
    110  set columns=120
    111   
    112  " 不要使用vi的键盘模式,而是vim自己的
    113  "set nocompatible
    114   
    115  " 在处理未保存或只读文件的时候,弹出确认
    116  set confirm
    117   
    118  " 与windows共享剪贴板
    119  set clipboard+=unnamed
    120   
    121  " 侦测文件类型
    122  filetype on
    123   
    124  " 载入文件类型插件
    125  filetype plugin on
    126   
    127  " 为特定文件类型载入相关缩进文件
    128  filetype indent on
    129   
    130  " 带有如下符号的单词不要被换行分割
    131  set iskeyword+=_,$,@,%,#,-
    132   
    133  " 语法高亮
    134  syntax on
    135   
    136  " 高亮字符,让其不受100列限制
    137  ":highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
    138  ":match OverLength '\%101v.*'
    139   
    140  " 状态行颜色
    141  "highlight StatusLine guifg=SlateBlue guibg=Yellow
    142  "highlight StatusLineNC guifg=Gray guibg=White
    143   
    144  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    145  " 文件设置
    146  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    147  " 不要备份文件(根据自己需要取舍)
    148  set nobackup
    149   
    150  " 不要生成swap文件,当buffer被丢弃的时候隐藏它
    151  setlocal noswapfile
    152  set bufhidden=hide
    153   
    154  " 字符间插入的像素行数目
    155  set linespace=0
    156   
    157  " 增强模式中的命令行自动完成操作
    158  set wildmenu
    159   
    160  " 在状态行上显示光标所在位置的行号和列号
    161  set ruler
    162  set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
    163   
    164  " 命令行(在状态行下)的高度,默认为1,这里是2
    165  set cmdheight=2
    166   
    167  " 使回格键(backspace)正常处理indent, eol, start等
    168  set backspace=2
    169   
    170  " 允许backspace和光标键跨越行边界
    171  set whichwrap+=<,>,h,l
    172   
    173  " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
    174  set mouse=a
    175  set selection=exclusive
    176  set selectmode=mouse,key
    177   
    178  " 启动的时候不显示那个援助索马里儿童的提示
    179  set shortmess=atI
    180   
    181  " 通过使用: commands命令,告诉我们文件的哪一行被改变过
    182  set report=0
    183   
    184  " 不让vim发出讨厌的滴滴声
    185  set noerrorbells
    186   
    187  " 在被分割的窗口间显示空白,便于阅读
    188  set fillchars=vert:\ ,stl:\ ,stlnc:\
    189   
    190  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    191  " 搜索和匹配
    192  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    193  " 高亮显示匹配的括号
    194  set showmatch
    195   
    196  " 匹配括号高亮的时间(单位是十分之一秒)
    197  set matchtime=5
    198   
    199  " 在搜索的时候忽略大小写
    200  set ignorecase
    201   
    202  " 高亮被搜索的句子(phrases)
    203  set hlsearch
    204   
    205  " 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
    206  set incsearch
    207   
    208  " 输入:set list命令是应该显示些啥?
    209  set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
    210   
    211  " 光标移动到buffer的顶部和底部时保持3行距离
    212  set scrolloff=3
    213   
    214  " 不要闪烁
    215  set novisualbell
    216   
    217  " 我的状态行显示的内容(包括文件类型和解码)
    218  set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
    219   
    220  " 总是显示状态行
    221  set laststatus=2
    222   
    223  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    224  " 文本格式和排版
    225  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    226  " 自动格式化
    227  set formatoptions=tcrqn
    228   
    229  " 继承前一行的缩进方式,特别适用于多行注释
    230  set autoindent
    231   
    232  " 为C程序提供自动缩进
    233  set smartindent
    234   
    235  " 使用C样式的缩进
    236  set cindent
    237   
    238  " 制表符为4
    239  set tabstop=4
    240   
    241  " 统一缩进为4
    242  set softtabstop=4
    243  set shiftwidth=4
    244   
    245  " 不要用空格代替制表符
    246  set noexpandtab
    247   
    248  " 不要换行
    249  set nowrap
    250   
    251  " 在行和段开始处使用制表符
    252  set smarttab
    253   
    254  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    255  " Autocommands
    256  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    257  " 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示
    258   
    259  if has("autocmd")
    260     autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number
    261     autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
    262     autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o
    263     autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
    264     autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
    265     autocmd BufReadPost *
    266        \ if line("'\"") > 0 && line("'\"") <= line("$") |
    267        \   exe "normal g`\"" |
    268        \ endif
    269  endif " has("autocmd")
    270   
    271  "设置Java代码的自动补全
    272  au FileType java setlocal omnifunc=javacomplete#Complete
    273   
    274  let mapleader = "."
    275  "绑定自动补全的快捷键<C-X><C-O>到<leader>;
    276  imap <leader>; <C-X><C-O>
    277   
    278  "设定开关Taglist插件的快捷键为F4,可以在VIM的左侧栏列出函数列表等
    279  map <F4> <ESC>:Tlist<CR>
    280   
    281  "设置程序的编译运行和调试的快捷键F5,F6,Ctrl-F5
    282  map <F5> <ESC>:call CompileRun()<CR>
    283  map <C-F5> <ESC>:call Debug()<CR>
    284  map <F6> <ESC>:call Run()<CR>
    285   
    286  "设置代码格式化快捷键F3
    287  map <F3> <ESC>:call FormartSrc()<CR>
    288 
    289  "NERDTree"
    290  map <F2> <ESC>:exe 'NERDTreeToggle'<CR>
    291   
    292  "设置tab操作的快捷键,绑定:tabnew到<leader>t,绑定:tabn, :tabp到<leader>n,
    293  "<leader>p
    294  map <leader>t :tabnew<CR>
    295  map <leader>n :tabn<CR>
    296  map <leader>p :tabp<CR>
    297   
    298  "用cscope支持
    299  "set csprg=d:\bin\cscope
    300   
    301  "使用<leader>e打开当前文件同目录中的文件
    302  if has("unix")
    303  map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
    304  else
    305  map ,e :e <C-R>=expand("%:p:h") . "\" <CR>
    306  endif
    307   
    308  "定义CompileRun函数,用来调用进行编译和运行
    309  func CompileRun()
    310  exec "w"
    311  "C程序
    312  if &filetype == 'c'
    313  exec "!del %<.out"
    314  exec "!gcc % -o %<.out"
    315  exec "!./%<.out"
    316  elseif &filetype == 'cpp'
    317  exec "!del %<.out"
    318  exec "!g++ % -o %<.out"
    319  exec "!./%<.out"
    320  "Java程序
    321  elseif &filetype == 'java'
    322  exec "!del %<.class"
    323  exec "!javac %"
    324  exec "!java %<"
    325  endif
    326  endfunc
    327  "结束定义CompileRun
    328   
    329  "定义Run函数,用来调用进行编译和运行
    330  func Run()
    331  exec "w"
    332  "C程序
    333  if &filetype == 'c'
    334  exec "!%<.exe"
    335  elseif &filetype == 'cpp'
    336  exec "!%<.exe"
    337  "Java程序
    338  elseif &filetype == 'java'
    339  exec "!java %<"
    340  endif
    341  endfunc
    342  "结束定义Run
    343   
    344  "定义Debug函数,用来调试程序
    345  func Debug()
    346  exec "w"
    347  "C程序
    348  if &filetype == 'c'
    349  exec "!del %<.exe"
    350  exec "!gcc % -g -o %<.exe"
    351  exec "!gdb %<.exe"
    352  elseif &filetype == 'cpp'
    353  exec "!del %<.exe"
    354  exec "!g++ % -g -o %<.exe"
    355  exec "!gdb %<.exe"
    356  "Java程序
    357  exec "!del %<.class"
    358  elseif &filetype == 'java'
    359  exec "!javac %"
    360  exec "!jdb %<"
    361  endif
    362  endfunc
    363  "结束定义Debug
    364  "定义FormartSrc()
    365  func FormartSrc()
    366  exec "w"
    367  "C程序,Perl程序,Python程序
    368  if &filetype == 'c'
    369  exec "!astyle --style=gnu --suffix=none %"
    370  exec "e! %"
    371  elseif &filetype == 'cpp'
    372  exec "!astyle --style=gnu --suffix=none %"
    373  exec "e! %"
    374  elseif &filetype == 'perl'
    375  exec "!astyle --style=gnu --suffix=none %"
    376  exec "e! %"
    377  elseif &filetype == 'py'
    378  exec "!astyle --style=gnu --suffix=none %"
    379  exec "e! %"
    380  "Java程序
    381  elseif &filetype == 'java'
    382  exec "!astyle --style=java --suffix=none %"
    383  exec "e! %"
    384  elseif &filetype == 'jsp'
    385  exec "!astyle --style=gnu --suffix=none %"
    386  exec "e! %"
    387  elseif &filetype == 'xml'
    388  exec "!astyle --style=gnu --suffix=none %"
    389  exec "e! %"
    390  elseif &filetype == 'html'
    391  exec "!astyle --style=gnu --suffix=none %"
    392  exec "e! %"
    393   
    394  elseif &filetype == 'htm'
    395  exec "!astyle --style=gnu --suffix=none %"
    396  exec "e! %"
    397   
    398  endif
    399  endfunc
    400  "结束定义FormartSrc
    401   
    402  " 能够漂亮地显示.NFO文件
    403  set encoding=utf-8
    404  function! SetFileEncodings(encodings)
    405      let b:myfileencodingsbak=&fileencodings
    406      let &fileencodings=a:encodings
    407  endfunction
    408  function! RestoreFileEncodings()
    409      let &fileencodings=b:myfileencodingsbak
    410      unlet b:myfileencodingsbak
    411  endfunction
    412   
    413  au BufReadPre *.nfo call SetFileEncodings('cp437')|set ambiwidth=single
    414  au BufReadPost *.nfo call RestoreFileEncodings()
    415   
    416  " 高亮显示普通txt文件(需要txt.vim脚本)
    417  au BufRead,BufNewFile * setfiletype txt
    418   
    419  " 用空格键来开关折叠
    420  set foldenable
    421  set foldmethod=manual
    422  nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
    423   
    424  colo slate
    425  set tags+=~/.vim/tags/cpp
    426  set tags+=~/.vim/tags/gl
    427  set tags+=~/.vim/tags/sdl
    428  set tags+=~/.vim/tags/qt4
    429  
    430  
    431  "自动补全
    432  "
    433  :inoremap ( ()<ESC>i
    434  "
    435  :inoremap ) <c-r>=ClosePair(')')<CR>
    436  "
    437  :inoremap { {<CR>}<ESC>O
    438  "
    439  :inoremap } <c-r>=ClosePair('}')<CR>
    440  "
    441  :inoremap [ []<ESC>i
    442  "
    443  :inoremap ] <c-r>=ClosePair(']')<CR>
    444  "
    445  :inoremap " ""<ESC>i
    446  "
    447  :inoremap ' ''<ESC>i
    448  "
    449  function! ClosePair(char)
    450      if getline('.')[col('.') - 1] == a:char
    451              return "\<Right>"
    452      else
    453          return a:char
    454      endif
    455  endfunction
    456  
    457  set completeopt=longest,menu
    458  
    459  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    460  
    461  " CTags的设定  
    462  "
    463  " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    464  
    465  let Tlist_Sort_Type = "name"    " 按照名称排序  
    466  
    467  let Tlist_Use_Right_Window = 1  " 在右侧显示窗口  
    468  
    469  let Tlist_Compart_Format = 1    " 压缩方式  
    470  
    471  let Tlist_Exist_OnlyWindow = 1  " 如果只有一个buffer,kill窗口也kill掉buffer  
    472  
    473  let Tlist_File_Fold_Auto_Close = 0  " 不要关闭其他文件的tags  
    474  
    475  let Tlist_Enable_Fold_Column = 0    " 不要显示折叠树  
    476  
    477  "autocmd FileType java set tags+=D:\tools\java\tags  
    478  
    479  "autocmd FileType h,cpp,cc,c set tags+=~/.vim/tags/cpp
    480 
    481 
    482  " colo darkblue
    483  set tags+=~/.vim/tags/c
    484  set tags+=~/.vim/tags/cpp
    485  set tags+=~/.vim/tags/gl
    486  set tags+=~/.vim/tags/sdl
    487  set tags+=~/.vim/tags/qt4
    488  
    489  
    490  let Tlist_Show_One_File=1            "不同时显示多个文件的tag,只显示当前文件的
    491  
    492  ""设置tags  
    493  
    494  set tags+=tags  
    495  
    496  "set autochdir 
    497  
    498  
    499  
    500  """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    501  
    502  "其他东东
    503  
    504  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    505  
    506  "默认打开Taglist 
    507  
    508  let Tlist_Auto_Open=1 
    509  
    510  """""""""""""""""""""""""""""" 
    511  
    512  " Tag list (ctags) 
    513  
    514  """""""""""""""""""""""""""""""" 
    515  let Tlist_Ctags_Cmd = '/usr/bin/ctags' 
    516  let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的 
    517  
    518  let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim 
    519  let TList_Use_Left_Window = 1
    520 
    521 "Nerd_commenter"
    522  map <F9> <leader>cc
    523  map <F10> <leader>cu
    524 
    525 
    526  "DoxygenToolkit"
    527  map <F11> :Dox<CR> 
    528  let g:DoxygenToolkit_briefTag_pre="@Brief: "
    529  let g:DoxygenToolkit_paramTag_pre="@Param: "
    530  let g:DoxygenToolkit_returnTag_pre="@Returns: "
    531  let g:DoxygenToolkit_authorName="Isaac_Li"
    532  let g:DoxygenToolkit_briefTag_funcName="yes"
    533  let g:Doxygen_enhanced_color=1
    534  let g:DoxygenToolkit_blackHeader="===================================================="
    535  let g:DoxygenToolkit_blackFooter="===================================================="
    536 
    537  "Cscope"
    538  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    539 " cscope setting
    540 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    541 if has("cscope")
    542   set csprg=/usr/local/bin/cscope
    543   set csto=1
    544   set cst
    545   set nocsverb
    546   " add any database in current directory
    547   if filereadable("cscope.out")
    548       cs add cscope.out
    549   endif
    550   set csverb
    551 endif
    552 
    553 nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
    554 nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
    555 nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
    556 nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
    557 nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
    558 nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
    559 nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    560 nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
  • 相关阅读:
    Java实现 LeetCode 136 只出现一次的数字
    Java实现 LeetCode 136 只出现一次的数字
    Java实现 LeetCode 136 只出现一次的数字
    Java实现 LeetCode 135 分发糖果
    Java实现 LeetCode 135 分发糖果
    Java实现 LeetCode 135 分发糖果
    Java实现 LeetCode 134 加油站
    Java实现 LeetCode 134 加油站
    Java实现 LeetCode 134 加油站
    Java实现 LeetCode 133 克隆图
  • 原文地址:https://www.cnblogs.com/hengli/p/2814137.html
Copyright © 2011-2022 走看看