_vimrc

" 关闭烦人的当当当声音
set vb t_vb=
" 显示行号
set number
" 高亮显示当前行
set cursorline 
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 列出当前目录文件  
map <F3> :tabnew .<CR>
" 打开树状文件目录  
map <C-F3> \be
" paste模式
set pastetoggle=<F11>
" 设置当文件被改动时自动载入
set autoread
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" 解决无法删除的问题 
set backspace=indent,eol,start
" 自动缩进
set autoindent
" 为特定文件类型载入相关缩进文件
filetype indent on
" 文件类型
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8
" GVIM 字体
set gfn=YaHei_Consolas_Hybrid:h13
" 主题
colorscheme desert

" *************** F9编译 F10运行 F8调试 *****************
map <F9> :call CompileGcc()<CR>
func! CompileGcc()
    exec "w"
    if &filetype == 'c'
        exec "!gcc % -o %< -lm"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %< -std=c++14 -W"
    elseif &filetype == 'java' 
        exec "!javac %" 
    elseif &filetype == 'sh'
        :!./%
    elseif &filetype == 'python'
        exec "!python %"
    elseif &filetype == 'r'
        exec "!Rscript %"
    endif
endfunc

map <F10> :call RunGcc()<CR>
func! RunGcc()
    if &filetype == 'c'
        exec "! ./%<"
    elseif &filetype == 'cpp'
        exec "! ./%<"
    elseif &filetype == 'java' 
        exec "!java %<"
    elseif &filetype == 'sh'
        :!./%
    elseif &filetype == 'python'
        exec "!python %"
    elseif &filetype == 'r'
        exec "!Rscript %"
    endif
endfunc

map <F5> :call Rungdb()<CR>
func! Rungdb()
    exec "w"
    if &filetype == 'c'
        exec "!gcc % -g -o %<"
    elseif &filetype == 'cpp'
        exec "!g++ % -g -o %<"
    endif
    exec "!gdb ./%<"
endfunc

" *************** 自动补全 *****************
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap {<CR> {<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

" *************** 自动文件信息头 *****************
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" 
func SetTitle() 
    if &filetype == 'sh' 
        call setline(1,"\#########################################################################") 
        call append(line("."), "\# File Name: ".expand("%")) 
        call append(line(".")+1, "\# Author: actypedef") 
        call append(line(".")+2, "\# Mail: 1815979752@qq.com") 	
        call append(line(".")+3, "\# Blog: https://www.cnblogs.com/illyasviel") 
        call append(line(".")+4, "\# Created Time: ".strftime("%c")) 
        call append(line(".")+5, "\#########################################################################") 
        call append(line(".")+6, "\#!/bin/bash") 
    else 
        call setline(1, "/*************************************************************************") 
        call append(line("."), "    > File Name: ".expand("%")) 
        call append(line(".")+1, "    > Author: actypedef") 
        call append(line(".")+2, "    > Mail: 1815979752@qq.com") 
        call append(line(".")+3, "    > Blog: https://www.cnblogs.com/illyasviel") 
        call append(line(".")+4, "    > Created Time: ".strftime("%c")) 
        call append(line(".")+5, " ************************************************************************/") 
    endif
    if &filetype == 'cpp'
        call append(line(".")+6, "#include<bits/stdc++.h>")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "int main(){")
        call append(line(".")+9, "	return 0;")
        call append(line(".")+10, "}")
    endif
    if &filetype == 'c'
        call append(line(".")+6, "#include <stdio.h>			//printf()")
        call append(line(".")+7, "#include <stdlib.h>			//exit()")
        call append(line(".")+8, "#include <string.h>			//strlen(), bzero();")
        call append(line(".")+9, "int main(){")
        call append(line(".")+10,	"	return 0;")
        call append(line(".")+11, "}")
    endif
    autocmd BufNewFile * normal G
    if &filetype == 'c' || &filetype == 'cpp'
        autocmd BufNewFile * normal k
        autocmd BufNewFile * normal k
        autocmd BufNewFile * normal k
    endif
endfunc 

" 啊,搞不懂,上面的BufNewFile需要再调用一下才正确
autocmd BufNewFile * exec ":call Test()" 
func Test() 

endfunc
posted @ 2021-07-20 20:23  actypedef  阅读(7)  评论(0编辑  收藏  举报