Vim也装完了,现在该配置Vim了,vim的插件很多,我这里只写出我自己用的,其他的大家可以自行搜索。
一、配置文件
vim有很多配置文件,有不同的优先级,我用的是账户目录下的.vimrc,下面是我的配置文件:
"语法高亮
syntax on
"括号匹配
set showmatch
"显示行号
set nu
"设置Tab长度为4格
set tabstop=4
"不要用空格代替制表符
set noexpandtab
"不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide
"history文件中需要记录的行数
set history=100
"高亮搜索后的结果
set hlsearch
"不要备份文件
set nobackup
"在状态行上显示光标所在位置的行号和列号
set ruler
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
"可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set selection=exclusive
set selectmode=mouse,key
"自动格式化
set formatoptions=tcrqn
"继承前一行的缩进方式,特别适用于多行注释
set autoindent
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
set showcmd
colorscheme desert
syntax enable
set tags=tags;
set backspace=indent,eol,start
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplorerMoreThanOne=2
nnoremap <silent> <F3> :Grep<CR>
let Grep_Default_Options='-r --exclude-dir=.svn'
set cscopequickfix=s-,c-,d-,i-,t-,e-
"VBundle
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Bundle 'gmarik/Vundle.vim'
" my Bundle here
Bundle 'a.vim'
Bundle 'taglist.vim'
Bundle 'winmanager'
Bundle 'minibufexpl.vim'
Bundle 'grep.vim'
Bundle 'wolfpython/cscope_map.vim'
" Bundle 'Valloric/YouCompleteMe'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :BundleList - lists configured plugins
" :BundleInstall - installs plugins; append `!` to update or just :PluginUpdate
" :BundleSearch foo - searches for foo; append `!` to refresh local cache
" :BundleClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line02006034536@163.gd VQPUIVXN
里面有些是插件的配置,如果你们不用,可以删掉。
二、插件
首先我要介绍一个很好用的管理插件的插件Vundle,基本上你只要下了这个插件,剩下的其它插件的安装直接交给它就行了,具体介绍官网上有,网上也有很多介绍,这里我就不多说了,官网地址是:
https://github.com/VundleVim/Vundle.vim。
这里简单介绍下如何安装,首先需要git,如果没安装,apt-get一下,然后直接执行命令:git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim,然后在.vimrc里面添加配置信息即可,官网上有,我提供的vimrc文件里面也有。最后直接打开vim,执行:BundleInstall即可,它就会安装配置了的插件,相当方便,相当于你只要把.vimrc文件备份好,你就可以随时随地在一台新的机器中用自己配置的vim,很不错吧。如果要更新插件,执行:BundleInstall即可,不过插件一般很少更新,所以这个命令很少用了。
我用的插件都比较常见,我这里就不一一介绍了,大家自行google。
三、cscope
这个插件大家一定不陌生,这里主要说一些我的配置和经验。
首先,这个插件要安装的,apt-get cscope,同时也可以apt-get ctags下,之后就是用命令生成cscope文件了,这里我自己写了一个shell脚本,执行后自动生成,大家可以参考下,具体如下:
#!/bin/bash
find . -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.lua" > cscope.files
cscope -Rbq
ctags -R
里面搜索的文件类型大家可以根据自己的需要添加删除,然后在下个cscope_map.vim插件(上面已包含),基本就够用了,具体怎么用这里就不写了,网上有很多文章的。这里加个小技巧,就是将cscope搜索出来的结果放到quickfix里面,这个有些文章有写,有些没有,只要在vimrc文件里面添加这么一句:set cscopequickfix=s-,c-,d-,i-,t-,e-(上面的配置文件已包含)。每次查找完如果要看搜索历史,直接:cw即可,这个技巧在大型文件项目里面很有用,希望对大家有帮助。
四、总结
上面只是我个人的一些用法,相对比较简单,写的也比较随意一些,大家自取。