适合ACM竞赛的vimrc和 MyVimConf

适合ACM竞赛的vimrc

涵盖了自动缩进,自动补全花括号,输入文件重定向等

.vimrc 比较短,真正需要手打的只有 8 行,一般可以在 30 秒左右敲完

  • F9 是运行程序(从控制台读取输入)
  • F5 是运行程序(将同目录下 in 文件的内容作为输入,效果等于 freopen(“in”, “r”, stdin))
1
2
3
4
5
6
7
8
9
10
11
12
13
set nu sts=4 ts=4 sw=4 cin
map <F5> :call CR()<CR>
func CR()
exec "w"
exec "!clear && g++ % -std=c++11 -W -o a && ./a < in"
endfunc
map <F9> :call CRr()<CR>
func CRr()
exec "w"
exec "!clear && g++ % -std=c++11 -W -o a && ./a"
endfunc
imap {<CR> {<CR>}<C-O>O<left><right>
syn on

在 Normal 模式下,输入 :20vsp in 可以快速分屏并打开 in 文件以进行编辑

分屏技巧

1
2
3
4
5
6
7
:sp ## 上下分屏
:res y ## 设置当前分屏高度为y
:vsp ## 左右分屏
:vertical res x ## 设置当前分屏宽度为x
Ctrl + w + hjkl ## 先按Ctrl + w,然后再按hjkl在分屏之间移动
:e ## 刷新当前文件
:e filename ## 在当前窗口打开名字为filename的文件

我自己的vimrc配置 MyVimConf

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
" Color
set t_Co=256
syntax on
" set background=dark

" Line Numbers
" set relativenumber
set number

" Clipboard
set clipboard=unnamed

" Make backspace work
set backspace=2

" Maps space to colon, time saver
nmap <space> :

" Indentation
set tabstop=2
set expandtab
set shiftwidth=2
set autoindent
" set ignorecase

" Allows for mouse scrolling
set mouse=a

" Highlight Current Line
set cursorline
highlight NERDTreeFile ctermfg=14

" Highlight All Search Pattern
set hlsearch

let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'

let g:ycm_confirm_extra_conf = 0

" set the runtime path to include Vundle and initialize
call plug##begin('~/.vim/plugged')

" YouCompleteme
Plug 'valloric/youcompleteme'

" Color Schemes
Plug 'flazz/vim-colorschemes'
Plug 'joshdick/onedark.vim'
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html##usage > for more information.)
if (empty($TMUX))
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (guicolors option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD##20160511 >
if (has("termguicolors"))
set termguicolors
endif
endif

" NERDTree
Plug 'scrooloose/nerdtree'
map <silent> <C-e> :NERDTree<CR>
map <silent> <C-w> :NERDTreeFind<CR>
nmap <leader>nt :NERDTreeFind<CR>
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$']
let NERDTreeChDirMode=0
let NERDTreeQuitOnOpen=1
let NERDTreeMouseMode=2
let NERDTreeShowHidden=1
let NERDTreeKeepTreeInNewTab=1
let g:nerdtree_tabs_open_on_gui_startup=0
" NERDTrees File highlighting
function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg)
exec 'autocmd FileType nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:guibg .' guifg='. a:guifg
exec 'autocmd FileType nerdtree syn match ' . a:extension .' ##^\s\+.*'. a:extension .'$##'
endfunction
au VimEnter * call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '##151515')
au VimEnter * call NERDTreeHighlightFile('ini', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('md', 'blue', 'none', '##3366FF', '##151515')
au VimEnter * call NERDTreeHighlightFile('yml', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('config', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('conf', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('html', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('styl', 'cyan', 'none', 'cyan', '##151515')
au VimEnter * call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '##151515')
au VimEnter * call NERDTreeHighlightFile('coffee', 'Red', 'none', 'red', '##151515')
au VimEnter * call NERDTreeHighlightFile('js', 'Red', 'none', '##ffa500', '##151515')
au VimEnter * call NERDTreeHighlightFile('rb', 'Red', 'none', '##ffa500', '##151515')
au VimEnter * call NERDTreeHighlightFile('php', 'Magenta', 'none', '##ff00ff', '##151515')
autocmd VimEnter * call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '##151515')
highlight! link NERDTreeFlags NERDTreeDir

" Airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
set laststatus=2
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols = {}
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = '☰'
let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.dirty='⚡'
let g:airline_theme = 'onedark'

" Code Formatter
" Plug 'Chiel92/vim-autoformat'
" nnoremap <Leader><Leader>a :Autoformat<cr>

" All of your Plugins must be added before the following line
call plug##end()
" Color
set t_Co=256
syntax on
" set background=dark

" Line Numbers
" set relativenumber
set number

" Clipboard
set clipboard=unnamed

" Make backspace work
set backspace=2

" Maps space to colon, time saver
nmap <space> :

" Indentation
set tabstop=2
set expandtab
set shiftwidth=2
set autoindent
" set ignorecase

" Allows for mouse scrolling
set mouse=a

" Highlight Current Line
set cursorline
highlight NERDTreeFile ctermfg=14

" Highlight All Search Pattern
set hlsearch

let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'

let g:ycm_confirm_extra_conf = 0

" set the runtime path to include Vundle and initialize
call plug##begin('~/.vim/plugged')

" YouCompleteme
Plug 'valloric/youcompleteme'

" Color Schemes
Plug 'flazz/vim-colorschemes'
Plug 'joshdick/onedark.vim'
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html##usage > for more information.)
if (empty($TMUX))
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (guicolors option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD##20160511 >
if (has("termguicolors"))
set termguicolors
endif
endif

" NERDTree
Plug 'scrooloose/nerdtree'
map <silent> <C-e> :NERDTree<CR>
map <silent> <C-w> :NERDTreeFind<CR>
nmap <leader>nt :NERDTreeFind<CR>
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$']
let NERDTreeChDirMode=0
let NERDTreeQuitOnOpen=1
let NERDTreeMouseMode=2
let NERDTreeShowHidden=1
let NERDTreeKeepTreeInNewTab=1
let g:nerdtree_tabs_open_on_gui_startup=0
" NERDTrees File highlighting
function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg)
exec 'autocmd FileType nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:guibg .' guifg='. a:guifg
exec 'autocmd FileType nerdtree syn match ' . a:extension .' ##^\s\+.*'. a:extension .'$##'
endfunction
au VimEnter * call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '##151515')
au VimEnter * call NERDTreeHighlightFile('ini', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('md', 'blue', 'none', '##3366FF', '##151515')
au VimEnter * call NERDTreeHighlightFile('yml', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('config', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('conf', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('html', 'yellow', 'none', 'yellow', '##151515')
au VimEnter * call NERDTreeHighlightFile('styl', 'cyan', 'none', 'cyan', '##151515')
au VimEnter * call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '##151515')
au VimEnter * call NERDTreeHighlightFile('coffee', 'Red', 'none', 'red', '##151515')
au VimEnter * call NERDTreeHighlightFile('js', 'Red', 'none', '##ffa500', '##151515')
au VimEnter * call NERDTreeHighlightFile('rb', 'Red', 'none', '##ffa500', '##151515')
au VimEnter * call NERDTreeHighlightFile('php', 'Magenta', 'none', '##ff00ff', '##151515')
autocmd VimEnter * call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '##151515')
highlight! link NERDTreeFlags NERDTreeDir

" Airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
set laststatus=2
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols = {}
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = '☰'
let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.dirty='⚡'
let g:airline_theme = 'onedark'

" Code Formatter
" Plug 'Chiel92/vim-autoformat'
" nnoremap <Leader><Leader>a :Autoformat<cr>

" All of your Plugins must be added before the following line
call plug##end()

本文作者:jujimeizuo
本文地址https://blog.jujimeizuo.cn/2021/11/25/vimrc/
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0 协议。转载请注明出处!