Loading

.vimrc

color ron     " 设置背景主题  
set showcmd         " 输入的命令显示出来,看的清楚些  
autocmd BufNewFile *.cpp exec ":call SetTitle()" 
func SetTitle() 
    if &filetype == 'cpp'
	call setline(1,"#include <iostream>")
    call append(line("."), "#include <cstring>")
    call append(line(".")+1, "#include <cstdio>")
    call append(line(".")+2, "#include <algorithm>")
	call append(line(".")+3, "using namespace std;")
	call append(line(".")+4, "")
	call append(line(".")+5, "inline int read(){")
	call append(line(".")+6, "	int x = 0, w = 1;")
	call append(line(".")+7, "	char ch = getchar();")
	call append(line(".")+8, "	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') w = -1;")
	call append(line(".")+9, "	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';")
	call append(line(".")+10, "	return x * w;")
	call append(line(".")+11, "}")
	call append(line(".")+12, "")
    endif
endfunc 

"去空行  
nnoremap <F2> :g/^\s*$/d<CR> 
"C,C++ 按F5编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    if &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "! ./%<"
    endif
endfunc
"C,C++的调试
map <F8> :call Rungdb()<CR>
func! Rungdb()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb ./%<"
endfunc
"从不备份  
set nobackup
" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 显示行号
set number
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
" 高亮显示匹配的括号
set showmatch
"自动补全
: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
function! ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endfunction
posted @ 2020-09-11 09:45  Gary_818  阅读(141)  评论(0编辑  收藏  举报