我用于算法竞赛的 Vim 配置

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
set noundofile
set nobackup
set nocompatible
set smartindent
set nu
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set cin
set autoindent
set cursorline
let mapleader = "\<Space>"

syntax on
filetype plugin indent on
autocmd BufNewFile,BufRead *.cpp exec ":call SetCppFile()"
autocmd BufNewFile,BufRead *.c exec ":call SetCppFile()"
autocmd BufNewFile,BufRead *.py exec ":call SetPythonFile()"
" autocmd BufNewFile,BufRead *.rs exec ":call SetRustFile()"
command! -nargs=0 -bar W  exec "w"
command! -nargs=0 -bar Wq  exec "wq"

if has('win32')
    autocmd GUIEnter * call libcallnr($VIM."\\vimfiles\\vimtweak.dll", "SetAlpha", 255)
    set enc=utf-8
    set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
    set langmenu=zh_CN.UTF-8
    source $VIMRUNTIME/delmenu.vim
    source $VIMRUNTIME/menu.vim
    language messages zh_CN.utf-8
    set guifont=Consolas:h12
    set guifontwide=YaHei\ Consolas\ Hybrid
elseif has('unix')
    set guifont=Monaco\ 12 
elseif has('mac')
    set guifont=Monaco\ 12
endif

if has('clipboard')
    if has('unnamedplus')
        set clipboard=unnamed,unnamedplus
    else " On mac and Windows, use * register for copy-paste
        set clipboard=unnamed
    endif
endif

function SetCppFile()
    packadd termdebug
    map <F9> : make <CR>
    map <F10> : call Run() <CR>
    " map <F11> : Termdebug %<.run <CR>
    map <F8> : call FormatCode()<CR>
    map <F12> : call Build_And_Run() <CR>
    set makeprg=g++\ \"%\"\ -o\ \"%<.exe\"\ -g\ -O2
endfunction

function SetPythonFile()
    map <F9> : ! python % <CR>
endfunction

function Run()
    if &filetype == 'cpp' || &filetype == 'c'
        if has('win32')
            exec "! %<.exe"
        elseif has('unix')
            exec "!time ./%<.exe"
        endif
    elseif &filetype == 'sh'
        exec "!bash %"
    endif
endfunction

function Build_And_Run()
    exec "make"
    call Run()
endfunction

func! FormatCode()
    exec "w"
    if &filetype == 'cpp' || &filetype == 'c' || &filetype == 'h'
        exec "!astyle --style=java -n \"%\""
        exec "e \"%\""
    endif
endfunc

call plug#begin('$VIM/vimfiles/plugged')
Plug 'junegunn/vim-easy-align'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'luochen1990/rainbow'
Plug 'Valloric/ListToggle'
Plug 'rakr/vim-one'
Plug 'roman/golden-ratio'
Plug 'jiangmiao/auto-pairs'
call plug#end()

if has('gui_running')
    set lines=54 columns=90
    set guioptions-=T
    set background=dark
    let g:one_allow_italics = 1
    colorscheme one
endif

let g:rainbow_active = 1
Licensed under CC BY-NC-SA 4.0