「个人vim插件+配置」

2017.7.20

复制代码时执行`set paste`来取消自动缩进,再`set nopaste`恢复。

ubuntu下面的适合acm的配置

filetype indent on
syntax on
set nu ai ci si
set sw=4 ts=4
set autochdir
set backspace=2
set mouse=a

map<F4> :w <CR> :!g++ -g % -o %< -std=c++11 <CR> :!./%< <CR>
imap<F4> <ESC> :w <CR> :!g++ -g % -o %< -std=c++11 <CR> :!./%< <CR>

map<F5> :w <CR> :!g++ -g % -o %< <CR> :!gdb ./%< <CR>
imap<F5> <ESC> :w <CR> :!g++ -g % -o %< <CR> :!gdb ./%< <CR>

map<F8> :split %<.in <CR>
map<F9> :split %<.out <CR>

vmap <C-c> "+y
map<F3> :w <CR> :!javac % <CR> :!java %< <CR>
imap<F3> <ESC> :w <CR> :!javac % <CR> :!java %< <CR>

 2016.10.4

适合做acm题目写c++程序的配置

filetype indent on
syntax on
set nu ai ci si
set sw=4 ts=4
set autochdir
set backspace=2
color slate
set mouse=a
set cursorline
"---------- windows 配置
cd e:acm
set gfn=consolas:h18 "gvim
map<F4> :w <CR> :!g++ % -g -o %<.exe && %<.exe <CR>
imap<F4> <ESC> :w <CR> :!g++ % -g -o %<.exe && %<.exe <CR>
"---------- Linux 配置
" map<F4> :w <CR> :!g++ -g % -o %< <CR> :!%< <CR>
" imap<F4> <ESC> :w <CR> :!g++ -g % -o %< <CR> :!%< <CR>
"----------------------
map<F8> :split %<.in <CR>
map<F9> :split %<.out <CR>

---

2016.9.3日更新:

命令行几句完成vim配置的方法:

rm ~/.vimrc

rm -rf  ~/.vim

curl http://vim.teamsz.xyz | sh

然后可以加上一键编译运行的配置。适合写前端的配置。

------------

2016.9.2

vim真是不好上手,感觉好烦。

另外linux下连校园wifi上网特别慢,git clone也一直提示fatal: unable to access 'https://github.com/XXXXXXX/XXX.GIT': GnuTLS recv error (-54): Error in the pull function.
各种解决方法都尝试了还是不行,于是只好手机开热点。

安装了一些插件:

(相应链接提供下載/教程)

ctags(Tagbar需要),vundle(管理插件的插件),Tagbar(显示函数列表),NERDTree(文件目录列表),MiniBufExplorer(多文件同时编辑)。

YouCompleteMe(代码补全)。

配置文件.vimrc:

"==========================
"2016.9.2,Ubuntu ~/.vimrc
"==========================
set nocompatible    " 关闭 vi 兼容模式
syntax on           " 自动语法高亮
set showmatch       " 设置匹配模式,输入左括号时会匹配相应的右括号
colorscheme desert  "设置颜色模式
set number          " 显示行号
set cursorline      " 突出显示当前行
set ruler           " 打开状态栏标尺
set shiftwidth=4    " 设定 << 和 >> 命令移动时的宽度为 4
set softtabstop=4   " 使得按退格键时可以一次删掉 4 个空格
set tabstop=4       " 设定 tab 长度为 4
set autochdir       " 自动切换当前目录为当前文件所在的目录
set backupcopy=yes  " 设置备份时的行为为覆盖
set ignorecase smartcase    " 搜索时忽略大小写,但在有一个或以
                            " 上大写字母时仍保持对大小写敏感
set incsearch       " 输入搜索内容时就显示搜索结果
set hlsearch        " 搜索时高亮显示被找到的文本
set showmatch       " 插入括号时,短暂地跳转到匹配的对应括号
set matchtime=2     " 短暂跳转到匹配括号的时间
set magic           " 设置魔术
set hidden          " 没有保存的缓冲区可以自动被隐藏
set guioptions-=T  " 隐藏工具栏
set guioptions-=m  " 隐藏菜单栏
set smartindent     " 开启新行时使用智能自动缩进
set backspace=indent,eol,start
                    " 不设定在插入状态无法用退格键和 Delete 键删除回车符
set cmdheight=1     " 设定命令行的行数为 1
set laststatus=2    " 显示状态栏 (默认值为 1, 无法显示状态栏)
set statusline= %<%F[%2*%M%*%n%R%H]%= %y %0(%{&fileformat} %{&encoding} %c:%l/%L%)
                        " 设置在状态行显示的信息
set foldenable          " 开始折叠
set foldmethod=syntax   " 设置语法折叠
setlocal foldlevel=1    " 设置折叠层数为
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
                        " 用空格键来开关折叠
"------------------------------------------------------
"Vundle 管理插件
"------------------------------------------------------
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
"插件nerdtree
Plugin 'scrooloose/nerdtree'
let NERDTreeWinPos='right'
let NERDTreeWinSize=30
map <F2> :NERDTreeToggle<CR>
"插件Tagbar
Plugin 'majutsushi/tagbar'
let g:tagbar_ctags_bin='ctags'            "ctags程序的路径
let g:tagbar_width=30                    "窗口宽度的设置
map <F3> :Tagbar<CR>
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen()
"如果是c语言的程序的话,tagbar自动开启
"插件miniBuf,快速切換buff
Plugin 'fholgado/minibufexpl.vim'
let g:miniBufExplMapWindowNavVim = 1   
let g:miniBufExplMapWindowNavArrows = 1   
let g:miniBufExplMapCTabSwitchBufs = 1   
let g:miniBufExplModSelTarget = 1  
let g:miniBufExplMoreThanOne=0
map <F11> :MBEbp<CR>
map <F12> :MBEbn<CR>
"插件YouCompleteMe 自动补全
Plugin 'Valloric/YouCompleteMe'
let leader=";"
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
let g:ycm_error_symbol = '>>'
let g:ycm_warning_symbol = '>*'
let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'
nmap <F4> :YcmDiags<CR>
call vundle#end()
filetype plugin indent on  
"------------------------------------------------------
"快捷键设置
"------------------------------------------------------
" wv垂直分割当前窗口
nmap wv     <C-w>v    
" wc关闭当前窗口
nmap wc     <C-w>c     
" ws水平分割当前窗口
nmap ws     <C-w>s 
" ctrl+A全选复制
map <C-A> ggVG$"+y 
" ctrl+c选中下复制
vmap <C-c> "+y
" ctrl+x剪切
vmap <C-x> "+x
" ctrl+v粘贴
imap <C-v> <Esc>"*pa
map <C-v> "*pa
" ctrl+a行首
imap <C-a> <Esc>^
" ctrl+e行尾
imap <C-e> <Esc>$
" F5去除空行 
nmap <F5> :g/^s*$/d<CR> 
"自动补全  
imap ( ()<ESC>i  
imap ) <c-r>=ClosePair(')')<CR>  
imap { {<CR>}<ESC>O  
imap } <c-r>=ClosePair('}')<CR>  
imap [ []<ESC>i  
imap ] <c-r>=ClosePair(']')<CR>  
imap " ""<ESC>i  
imap ' ''<ESC>i  
function! ClosePair(char)  
    if getline('.')[col('.') - 1] == a:char  
        return "<Right>"  
    else  
        return a:char  
    endif  
endfunction  
filetype plugin indent on  
"-----------------------------------------------------
"配置一键编译运行<F7>
"-----------------------------------------------------
map <F7> :call CompileRunGcc()<CR>
func! CompileRunGcc()  
    exec "w"  
    if &filetype == 'c'  
        exec "!g++ % -o %<"  
        exec "! ./%<"  
    elseif &filetype == 'cpp'  
        exec "!g++ % -o %<"  
        exec "! ./%<"  
    elseif &filetype == 'java'   
        exec "!javac %"   
        exec "!java %<"  
    elseif &filetype == 'sh'  
        :!./%  
    endif  
endfunc
"-----------------------------------------------------
"C,C++的调试<F8>
"-----------------------------------------------------
map <F8> :call Rungdb()<CR>  
func! Rungdb()  
    exec "w"  
    exec "!g++ % -g -o %<"  
    exec "!gdb ./%<"  
endfunc 
"-----------------------------------------------------
"新建.c,.h,.java文件,自动插入文件头 
"-----------------------------------------------------
autocmd BufNewFile *.cpp,*.[ch],*.java exec ":call SetTitle()"   
""定义函数SetTitle,自动插入文件头   
func SetTitle()   
        call setline(1, "/*******************************************") 
        call append(line("."), "    > File Name: ".expand("%"))   
        call append(line(".")+1, "    > Author: flipped")   
        call append(line(".")+2, "    > Mail: 823188494@qq.com ")   
        call append(line(".")+3, "    > Created Time: ".strftime("%c")) 
        call append(line(".")+4, " *********************************/") 
        call append(line(".")+5, "")  
    if &filetype == 'cpp'  
        call append(line(".")+6, "#include<iostream>")  
        call append(line(".")+7, "#include<cstdio>")  
        call append(line(".")+8, "#include<cstring>")
        call append(line(".")+9, "#include<algorithm>")
        call append(line(".")+10, "using namespace std;")  
        call append(line(".")+11, "int main(){")
        call append(line(".")+12, "")
        call append(line(".")+13, "}")
        call append(line(".")+14, "")
    endif  
    if &filetype == 'c'    
        call append(line(".")+6, "#include<stdio.h>")  
        call append(line(".")+7, "int main(){")
        call append(line(".")+8, "")
        call append(line(".")+9, "}")
        call append(line(".")+10, "")
    endif
    "新建文件后,自动定位到文件末尾  
    autocmd BufNewFile * normal G  
endfunc 
View Code
原文地址:https://www.cnblogs.com/flipped/p/5831642.html