您的位置:首页 > 其它

vim基础配置及常用插件配置

2013-08-11 16:10 288 查看
vim基础配置:

set background=dark
set number
filetype on
set ruler
"set cursorline              " 突出显示当前行
set tabstop=4                " 设置tab键的宽度
set shiftwidth=4             " 换行时行间交错使用4个空格
set autoindent               " 自动对齐
set backspace=2              " 设置退格键可用
set cindent shiftwidth=4     " 自动缩进4空格
set smartindent              " 智能自动缩进
set ai!                      " 设置自动缩进
set hlsearch                 " 开启高亮显示结果
"set laststatus=2             " 开启状态栏信息
"set cmdheight=2              " 命令行的高度,默认为1,这里设为2
set showcmd		" Show (partial) command in status line.
set showmatch		" Show matching brackets.
set ignorecase		" Do case insensitive matching
set smartcase		" Do smart case matching
set incsearch		" Incremental search
set autowrite		" Automatically save before commands like :next and :make
set hidden             " Hide buffers when they are abandoned
set mouse=a		" Enable mouse usage (all modes)

" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif

" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

" 设置编码
set fenc=utf-8
set encoding=utf-8
set fileencodings=utf-8,gbk,cp936,latin-1
" 解决consle输出乱码
language messages zh_CN.utf-8

" ======= 引号 && 括号自动匹配 ======= "

:inoremap ( ()<ESC>i

:inoremap ) <c-r>=ClosePair(')')<CR>

:inoremap { {}<ESC>i

:inoremap } <c-r>=ClosePair('}')<CR>

:inoremap [ []<ESC>i

:inoremap ] <c-r>=ClosePair(']')<CR>

"":inoremap < <><ESC>i

"":inoremap > <c-r>=ClosePair('>')<CR>

":inoremap " ""<ESC>i

:inoremap ' ''<ESC>i

:inoremap ` ``<ESC>i


ctags and Tlist

安装ctags 5.8

用下面的命令解压安装:

$ tar -xzvf ctags-5.6.tar.gz

$ cd ctags-5.6

$ make

# make install // 需要root权限
然后去你的源码目录, 如果你的源码是多层的目录, 就去最上层的目录, 在该目录下运行命令: ctags -R

我现在以 vim71 的源码目录做演示

$ cd /home/wooin/vim71

$ ctags -R
此时在/home/wooin/vim71目录下会生成一个 tags 文件, 现在用vim打开 /home/wooin/vim71/src/main.c

$ vim /home/wooin/vim71/src/main.c
再在vim中运行命令:

:set tags=/home/wooin/vim71/tags
该命令将tags文件加入到vim中来, 你也可以将这句话放到~/.vimrc中去, 如果你经常在这个工程编程的话.

将光标移到某个函数名上,按Ctrl + ],Vim将自动跳转到该函数的定义,按Ctrl + T返回

MiniBufExplorer

上面那个狭长的窗口就是MiniBufExplorer窗口, 其中列出了当前所有已经打开的buffer, 当你把光标置于这个窗口时, 有下面几个快捷键可以用:

<Tab>向前循环切换到每个buffer名上
<S-Tab>向后循环切换到每个buffer名上
<Enter>在打开光标所在的buffer
d删除光标所在的buffer
以下的两个功能需要在~/.vimrc中增加:

let g:miniBufExplMapCTabSwitchBufs = 1
<C-Tab>向前循环切换到每个buffer上,并在但前窗口打开
<C-S-Tab>向后循环切换到每个buffer上,并在但前窗口打开
如果在~/.vimrc中设置了下面这句:

let g:miniBufExplMapWindowNavVim = 1
则可以用<C-h,j,k,l>切换到上下左右的窗口中去,就像:

C-w,h j k l 向"左,下,上,右"切换窗口.

在~/.vimrc中设置:

let g:miniBufExplMapWindowNavArrows = 1
是用<C-箭头键>切换到上下左右窗口中去

插件A

下面介绍它的用法:

作为一个C程序员, 日常Coding时在源文件与头文件间进行切换是再平常不过的事了, 直接用vim打开其源/头文件其实也不是什么麻烦事, 但是只用一个按键就切换过来了, 这是多么贴心的功能啊....

安装好a.vim后有下面的几个命令可以用了:

:A在新Buffer中切换到c/h文件
:AS横向分割窗口并打开c/h文件
:AV纵向分割窗口并打开c/h文件
:AT新建一个标签页并打开c/h文件
其他还有一些命令, 你可以在它的网页上看看, 我都没用过, 其实也都是大同小异, 找到自己最顺手的就行了.

我在~/.vimrc中增加了一句:

nnoremap <silent> <F12> :A<CR>
意思是按F12时在一个新的buffer中打开c/h文件, 这样在写程序的时候就可以不假思索地在c/h文件间进行切换, 减少了按键的次数, 思路也就更流畅了, 阿弥陀佛....

"======== 加载语法模板和作者、时间信息 ========"

" :LoadTemplate 根据文件后缀自动加载模板

let g:template_path='~/.vim/template/'

" :AuthorInfoDetect 自动添加作者、时间等信息,本质是NERD_commenter && authorinfo的结合 可修改authorinfo.vim中插入到具体选项

let g:vimrc_author='wayne'

let g:vimrc_email='wayne.zeng87@gmail.com'

let g:vimrc_company='TrueWayne'

" Ctrl + E 一步加载语法模板和作者、时间信息

map <c-e> <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi

imap <c-e> <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi

vmap <c-e> <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi

"======== java complete======="

setlocal completefunc=javacomplete#CompleteParamsInfo

autocmd FileType java set omnifunc=javacomplete#Complete

"======== ;alias======="

let mapleader=";"

nmap <silent> <leader>tl :Tlist<cr>

nmap <silent> <lender>cal :Calendar<cr>

"nmap <silent> <lender>cah :CalendarH<cr>

" ======= 编译 && 运行 ======= "

" 编译C源文件

func! CompileGcc()

exec "w"

let compilecmd="!gcc -Wall -pedantic -std=c99 "

let compileflag="-o %<"

exec compilecmd." % ".compileflag

endfunc

" 编译C++源文件

func! CompileCpp()

exec "w"

let compilecmd="!g++ -Wall -pedantic -std=c++98 "

let compileflag="-o %<"

exec compilecmd." % ".compileflag

endfunc

" 编译Java源文件

func! CompileJava()

exec "w"

exec "!javac %"

endfunc

" 根据文件类型自动选择相应的编译函数

func! CompileCode()

exec "w"

if &filetype == "c"

exec "call CompileGcc()"

elseif &filetype == "cpp"

exec "call CompileCpp()"

elseif &filetype == "java"

exec "call CompileJava()"

elseif &filetype == "lua"

exec "!lua %<.lua"

elseif &filetype == "perl"

exec "!perl %<.pl"

elseif &filetype == "python"

exec "!python %<.py"

elseif &filetype == "ruby"

exec "!ruby %<.rb"

endif

endfunc

" 运行可执行文件

func! RunResult()

exec "w"

if &filetype == "c"

exec "! %<"

elseif &filetype == "cpp"

exec "! %<"

elseif &filetype == "java"

exec "!java %<"

elseif &filetype == "lua"

exec "!lua %<.lua"

elseif &filetype == "perl"

exec "!perl %<.pl"

elseif &filetype == "python"

exec "!python %<.py"

elseif &filetype == "ruby"

exec "!ruby %<.rb"

endif

endfunc

" Ctrl + C 一键保存、编译

map <c-c> :call CompileCode()<CR>

imap <c-c> <ESC>:call CompileCode()<CR>

vmap <c-c> <ESC>:call CompileCode()<CR>

" Ctrl + R 一键保存、运行

map <c-r> :call RunCode()<CR>

imap <c-r> <ESC>:call RunCode()<CR>

vmap <c-r> <ESC>:call RunCode()<CR>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: