??做嵌入式开发,经常能够在一些新的环境下配置各种各样的环境,做为默认使用的编辑器,VIM非常重要,但是每次都要折腾来折腾去的配置,所以今天特意记录一下,方便后续直接使用。
??主要特性:
1. C语言自动提示和补齐 2. 显示行号、语法高亮等 3. 在默认模式下按下空格进行命令行模式
??主要的配置内容如下所示。
" .vimrc - Vim configuration file.
" Copyright (c) 2010 Jeffy Du. All Rights Reserved.
"
" Maintainer: Jeffy Du <jeffy.du@gmail.com>
" Created: 2010-01-01
" LastChange: 2010-04-22
"colorscheme mycolor "修改背景的风格
" GENERAL SETTINGS: {{{1
" To use VIM settings, out of VI compatible mode.
set nocompatible
" Enable file type detection.
filetype plugin indent on
" Syntax highlighting.
syntax on
"Setting colorscheme
"color mycolor
" Other settings.
set autoindent
set autoread
set autowrite
set background=dark
set backspace=indent,eol,start
set nobackup
set cindent
set cinoptions=:0
set cursorline
set completeopt=longest,menuone
set noexpandtab
set fileencodings=utf-8,gb2312,gbk,gb18030
set fileformat=unix
set foldenable
set foldmethod=marker
set guioptions-=T
set guioptions-=m
set guioptions-=r
set guioptions-=l
set helpheight=10
set helplang=cn
set hidden
set history=100
set hlsearch
set ignorecase
set incsearch
set laststatus=2
set mouse=a
set number
set pumheight=10
set ruler
set scrolloff=5
set shiftwidth=4
set showcmd
set smartindent
set smartcase
set tabstop=4
set termencoding=utf-8
set textwidth=80
set whichwrap=h,l
set wildignore=*.bak,*.o,*.e,*~
set wildmenu
set wildmode=list:longest,full
set nowrap
" AUTO COMMANDS: {{{1
" auto expand tab to blanks
"autocmd FileType c,cpp set expandtab
" Restore the last quit position when open file.
"
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif
let mapleader=","
" SHORTCUT SETTINGS: {{{1
" " Set mapleader
" Space to command mode.
nnoremap <space> :
vnoremap <space> :
"nnoremap <alt> + <space> :
"vnoremap <Alt> + <space> :
" Switching between buffers.
nnoremap <C-h> <C-W>h
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-l> <C-W>l
inoremap <C-h> <Esc><C-W>h
inoremap <C-j> <Esc><C-W>j
inoremap <C-k> <Esc><C-W>k
inoremap <C-l> <Esc><C-W>l
let OpenDir=system("pwd")
nmap <silent> <leader>cd :exe 'cd ' . OpenDir<cr>:pwd<cr>
let g:Tlist_Auto_Update=1
let g:Tlist_Process_File_Always=1
let g:Tlist_Exit_OnlyWindow=1
let g:Tlist_Show_One_File=1
let g:Tlist_WinWidth=25
let g:Tlist_Enable_Fold_Column=0
let g:Tlist_Auto_Highlight_Tag=1
let g:NERDTreeWinPos="right"
let g:NERDTreeWinSize=25
let g:NERDTreeShowLineNumbers=1
let g:NERDTreeQuitOnOpen=1
if has("cscope")
set csto=1
set cst
set nocsverb
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
let g:OmniCpp_DefaultNamespaces=["std"]
let g:OmniCpp_MayCompleteScope=1
let g:OmniCpp_SelectFirstItem=2
if has("gdb")
set asm=0
let g:vimgdb_debug_file=""
run macros/gdb_mappings.vim
endif
let g:LookupFile_TagExpr='"./tags.filename"'
let g:LookupFile_MinPatLength=2
let g:LookupFile_PreserveLastPattern=0
let g:LookupFile_PreservePatternHistory=1
let g:LookupFile_AlwaysAcceptFirst=1
let g:LookupFile_AllowNewFiles=0
source $VIMRUNTIME/ftplugin/man.vim
"新建.c,.h,.cpp文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
if &filetype == 'cpp'
call setline(1,"#include<iostream>")
call append(line("."), "using namespace std;")
call append(line(".")+1, "")
endif
if &filetype == 'c'
call setline(1,"#include<stdio.h>")
call append(line("."), "#include<stdlib.h>;")
call append(line(".")+1, "")
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
filetype plugin indent on
"使用tab自动补全的设定
function! CleverTab()
if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
return "\<Tab>"
else
return "\<C-N>"
endif
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
"C,C++ 按F5编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "! %<"
elseif &filetype == 'cpp'
echo "Compiling ..."
exec "!g++ % -o %< -std=c++11"
echo "Compiled successfully ..."
exec "! %<"
elseif &filetype == 'java'
exec "!javac %"
exec "!java %<"
elseif &filetype == 'sh'
:!./%
elseif &filetype == 'py'
exec "!python %"
exec "!python %<"
endif
endfunc
"C,C++的调试
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -g -o %<"
"exec "!gdb ./%<"
endfunc
set tags+=/usr/share/vim/peizhi/cpp_src/head " 修改为刚开始生成索引文件的绝对路径
" OmniCppComplete
let OmniCpp_DisplayMode=1 "显示类成员
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " 显示函数参数列表
let OmniCpp_MayCompleteDot = 1 " 输入 . 后自动补全
let OmniCpp_MayCompleteArrow = 1 " 输入 -> 后自动补全
let OmniCpp_MayCompleteScope = 1 " 输入 :: 后自动补全
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" 自动关闭补全窗口
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest
let g:snips_author="Du Jianfeng"
let g:snips_email="cmdxiaoha@163.com"
let g:snips_copyright="SicMicro, Inc"
function! RunShell(Msg, Shell)
echo a:Msg . '...'
call system(a:Shell)
echon 'done'
endfunction
nmap <F2> :TlistToggle<cr>
nmap <F3> :NERDTreeToggle<cr>
nmap <F4> :MRU<cr>
nmap <F5> <Plug>LookupFile<cr>
nmap <F6> :vimgrep /<C-R>=expand("<cword>")<cr>/ **/*.c **/*.h<cr><C-o>:cw<cr>
nmap <F9> :call RunShell("Generate tags", "ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .")<cr>
nmap <F10> :call HLUDSync()<cr>
nmap <F11> :call RunShell("Generate filename tags", "~/.vim/shell/genfiletags.sh")<cr>
nmap <F12> :call RunShell("Generate cscope", "cscope -Rb")<cr>:cs add cscope.out<cr>
nmap <leader>sa :cs add cscope.out<cr>
nmap <leader>ss :cs find s <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sg :cs find g <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sc :cs find c <C-R>=expand("<cword>")<cr><cr>
nmap <leader>st :cs find t <C-R>=expand("<cword>")<cr><cr>
nmap <leader>se :cs find e <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sf :cs find f <C-R>=expand("<cfile>")<cr><cr>
nmap <leader>si :cs find i <C-R>=expand("<cfile>")<cr><cr>
nmap <leader>sd :cs find d <C-R>=expand("<cword>")<cr><cr>
nmap <leader>zz <C-w>o
nmap <leader>gs :GetScripts<cr>
syntax on
set hlsearch
colorscheme desert "修改背景的风格
highlight CursorLine cterm=NONE ctermbg=black ctermfg=NONE guibg=NONE guifg=NONE
"ab main
"ab mian #include "stdio.h"<cr>#include "stdlib.h"<cr>#include "string.h"<cr><cr>int main(int argc, const char argv[])<cr>{<cr>return 0;<cr>}
set tags+=/usr/include/tags
set backspace=2 "能使用backspace回删
set ruler "显示最后一行的状态
set bg=dark "背景色设置
set hlsearch "高亮度反白
set laststatus=2 "两行状态行+一行命令行
set t_Co=256 "指定配色方案为256
set mouse=a "设置可以在VIM使用鼠标
set tabstop=4 "设置TAB宽度
set history=1000 "设置历史记录条数
set nocompatible "设置不兼容
filetype plugin on "允许插件
filetype plugin indent on "启动智能补全
let g:SuperTabRetainCompletionType=2 "记住上次的补全方式,直到按Esc退出插入模式位置
map <silent> <F2> :TlistToggle<CR>
map <Alt> oanother line <Escmap <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
exec "!time python2.7 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'mkd'
exec "!~/.vim/markdown.pl % > %.html &"
exec "!firefox %.html &"
endif
endfunc>
set completeopt=preview,menu
set guifont=Courier_New\ 22
set guifont=Courier_New:h22
??git提交的信息的模板,名称为 .gitcommit.template。
[提交等级]:
[主要问题]
1.
[导致原因/解决方案]
1.
[简要概述]
1.
|