标签:
上节,对vim下的插件管理软件Vundle做了介绍,通过配置.vimrc文件以及执行:BundleInstall等命令,就可以方便的安装卸载插件,同时对于每个插件的配置项我们可以放在.vimrc下面,下面主要介绍我自己的.vimrc配置文件,在熟悉之后你可以根据自己的习惯自己定制自己的.vimrc。
配置界面如下:
ctrl+i 前进到下一步操作文件位置(YoucompleteMe插件)
map <leader>ct :!ctags -R . <cr> "generate Ctags sysbols
map <c-j> :YcmCompleter GoToDeclaration<cr>
map <c-k> :YcmCompleter GoToDefinition<cr>
map <c-l> :YcmCompleter GoToDefinitionElseDeclaration<cr>
map <c-h> <c-]>
注:通过ctag、taglist、youcomplete插件将vim编辑器打造成一个强大的IDE环境,可以自动提示补全、查找定义声明自由跳转、一键编译运行调试、多窗口,同时窗口大小位置、快捷键都可以自己定制,使用起来非常方便,赶快抛弃你的SI吧
注:这里就列这几个常用的快捷键,并不全,如果想用所有的vim自带的快捷点,找个vim教程看吧。同时原始的快捷键也可以重新映射。
推荐:笨办法学习vim
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker
"use the marker method of folding for any Vimscript files
"for instance : z-a open and close maker
augroup END
"快捷键映射 MAP -----------{{{
let mapleader = ","
let maplocalleader = "."
"<LocalLeader> is to be used for mappings which are local to a buffer.
nnoremap <F2> :vert diffsplit
nnoremap <F3> :tabnew<cr>
map <F4> gg=G
map <F5> :call CompileRunGcc()<cr>
map <f6> :call Rungdb()<cr>
map <f7> :call Rungdbb()<cr>
map <F9> :NERDTreeToggle<cr>
map <F10> :TagbarToggle<cr>
map <F12> :TlistToggle<cr>
map <leader>ct :!ctags -R . <cr> "generate Ctags sysbols
map <c-j> :YcmCompleter GoToDeclaration<cr>
map <c-k> :YcmCompleter GoToDefinition<cr>
map <c-l> :YcmCompleter GoToDefinitionElseDeclaration<cr>
map <c-h> <c-]>
"echo ">^.^<"
noremap - ddp
"move a row down
noremap _ ddkkp
"move a row up
nnoremap <leader>u viwU
"lowercase -> uppercase
inoremap <leader>u <esc>viwUi
nnoremap <leader>d dd
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
inoremap jk <esc>
" inoremap <esc> <nop>
" noremap <left> <nop>
" noremap <right> <nop>
" noremap <up> <nop>
" noremap <down> <nop>
noremap ;k <c-u> "上半页
noremap ;j <c-d> "下半页
" 映射全选+复制 ctrl+a
map <C-A> ggVGY
map! <C-A> <Esc>ggVGY
" 选中状态下 Ctrl+c 复制
vmap <C-c> "+y
"去空行
"C,C++ 按F5编译运行
func! CompileRunGcc()
exec "w"
if &filetype == ‘c‘
exec "!gcc % -I /home/ltf/apue/include -lpthread /home/ltf/apue/lib/libapue.a -o %<"
exec "! ./%<"
elseif &filetype == ‘cpp‘
exec "!g++ % -std=c++11 -o %<"
exec "! ./%<"
elseif &filetype == ‘java‘
exec "!javac %"
exec "!java %<"
elseif &filetype == ‘sh‘
:!./%
endif
endfunc
"C的调试 f6
func! Rungdb()
exec "w"
exec "!gcc % -g -o %<"
exec "!gdb ./%<"
endfunc
" c++ debug f7
func! Rungdbb()
exec "w"
exec "!g++ % -g -std=c++11 -o %<"
exec "!gdb ./%<"
endfunc
" }}}
" pathogen 插件管理软件 ----{{{
"filetype off
"
"call pathogen#infect()
"
"filetype plugin indent on
" }}}
" Vundle 插件管理软件 ----{{{
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" other plugin to be installed
Plugin ‘gmarik/Vundle.vim‘
Plugin ‘tomasr/molokai‘
Plugin ‘scrooloose/nerdtree‘
Plugin ‘majutsushi/tagbar‘
Plugin ‘vim-scripts/taglist.vim‘
Plugin ‘klen/python-mode‘
"Plugin ‘tpope/vim-pathogen‘
Plugin ‘Valloric/YouCompleteMe‘
call vundle#end()
filetype plugin indent on
" }}}
"plugin config------------{{{
"YouCompleteMe config------------{{{
"don‘t show errorMsg
"let g:ycm_show_diagnostics_ui=0
" >>
let g:ycm_enable_diagnostic_signs = 1
let g:ycm_enable_diagnostic_highlighting = 0
" }}}
"Tagbar config------------{{{
"
let g:tagbar_width = 30
let g:tagbar_left = 1 "by default on right side of vim
" }}}
"molokai config--------------{{{
colorscheme molokai
highlight NonText guibg=#060606
highlight Folded guibg=#0A0A0A guifg=#9090D0
"}}}
"ctaglist config--------------{{{
let Tlist_Ctags_Cmd=‘ctags‘
let Tlist_Show_One_File=1 "不同时显示多个文件的tag,只显示当前文件的
let Tlist_WinWidth =28 "设置taglist的宽度
let Tlist_Use_Right_Window=1 "在右侧窗口中显示taglist窗口
"let Tlist_Use_Left_Window =1 "在左侧窗口中显示taglist窗口
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim
"}}}
"NERD tree config----------" {{{
let NERDChristmasTree=0
let NERDTreeWinSize=25
let NERDTreeChDirMode=2
let NERDTreeIgnore=[‘\~$‘,‘\.pyc$‘,‘\.swp$‘]
let NERDTreeShowBookmarks=1
let NERDTreeWinPos=‘left‘
"Automatically open a NERDTree if no files where specified
"autocmd vimenter * if !argc() | NERDTree | endif
" Close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary")
"OPen a NERDTree
" }}}
" }}}
"新文件标题"" --------{{{
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == ‘sh‘
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: ")
call append(line(".")+2, "\# mail: @qq.com")
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\#########################################################################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: ltf")
call append(line(".")+2, " > Mail: @qq.com ")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if &filetype == ‘cpp‘
call append(line(".")+6, "#include<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == ‘c‘
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
endif
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc
"}}}
"自动匹配------------------{{{
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(‘)‘)<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair(‘}‘)<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(‘]‘)<CR>
":inoremap " ""<ESC>i
":inoremap ‘ ‘‘<ESC>i
function! ClosePair(char)
if getline(‘.‘)[col(‘.‘) - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
"}}}
" 显示相关 --------{{{
set linespace=4
set guifont=Courier_New:h10:cANSI " 设置字体
"syntax on " 语法高亮
set number " 显示行号
autocmd InsertLeave * se nocul " 用浅色高亮当前行
autocmd InsertEnter * se cul " 用浅色高亮当前行
set ruler " 打开状态栏标尺
set laststatus=2 " 启动显示状态行(1),总是显示状态行(2)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容
set cursorline " 突出显示当前行
set guioptions-=T " 隐藏工具栏
set guioptions-=m " 隐藏菜单栏
set showcmd " 输入的命令显示出来,看的清楚些
set cmdheight=1 " 命令行(在状态行下)的高度,设置为1
set novisualbell " 不要闪烁(不明白)
" 显示中文帮助
if version >= 603
set helplang=cn
set encoding=utf-8
endif
"编码设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"语言设置
set langmenu=zh_CN.UTF-8
set helplang=cn
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:set termencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8
" }}}
" 常用设置 ----------{{{
set autoread " 设置当文件被改动时自动载入
set clipboard+=unnamed "共享剪贴板
"set autowrite "自动保存
set nocompatible " 不要使用vi的键盘模式,而是vim自己的
set noeb " 去掉输入错误的提示声音
set confirm " 在处理未保存或只读文件的时候,弹出确认
set autoindent " 自动缩进
set cindent
set tabstop=4 " Tab键的宽度
set softtabstop=4 " 统一缩进为4
set shiftwidth=4
set noexpandtab " 不要用空格代替制表符
set smarttab " 在行和段开始处使用制表符set history=1000 " 历史记录数
set nobackup "禁止生成临时文件
set noswapfile
set ignorecase "搜索忽略大小写
set hlsearch "搜索逐字符高亮
set incsearch
set gdefault "行内替换
"filetype on " 侦测文件类型
set viminfo+=! " 保存全局变量
set iskeyword+=_,$,@,%,#,- " 带有如下符号的单词不要被换行分割
set linespace=0 " 字符间插入的像素行数目
set wildmenu " 增强模式中的命令行自动完成操作
set backspace=2 " 使回格键(backspace)正常处理indent, eol, start等
set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界
set mouse=a " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set selection=exclusive
set selectmode=mouse,key
set report=0 " 通过使用: commands命令,告诉我们文件的哪一行被改变过
set showmatch " 高亮显示匹配的括号
set matchtime=1 " 匹配括号高亮的时间(单位是十分之一秒)
set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离
set smartindent " 为C程序提供自动缩进
au BufRead,BufNewFile * setfiletype txt " 高亮显示普通txt文件(需要txt.vim脚本)
"}}}
标签:
原文地址:http://blog.csdn.net/lanshanxunmeng/article/details/51190340