vimrc
通常,我是在 goland 中使用 vim 编程,使用的是 ideavim 插件,在 ideavim 官方 github 的 issue (opens new window) 中有一个关于.ideamvimrc文件的分享
注意:下面配置中的插件依赖于git,使用时若不需要可移除插件
" 插件管理,自动装载插件 start --------------------------------------
let mapleader="\<space>"
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin()
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-sensible'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'mileszs/ack.vim'
Plug 'easymotion/vim-easymotion'
let g:plug_timeout=300
Plug 'Valloric/YouCompleteMe'
call plug#end()
" 插件管理,自动装载插件 end --------------------------------------
set nocompatible " 去除VIM一致性
filetype off
packloadall " 加载所有插件
silent! helptags ALL " 为插件加载帮助文档
noremap <leader>w :w<cr>
syntax on " 语法高亮显示
filetype plugin indent on " 支持根据文件类型自动缩进
set autoindent " 开始新行时处理缩进
set spell
set expandtab " 将制表符展开为空格
set tabstop=4 " 要计算的空格数
set shiftwidth=4 " 用于自动缩进的空格数
set backspace=2 " 在多数终端上修改退格键Backspace的行为
colorscheme murphy
set nu " 显示行号
set ruler
set hls " 高亮显示搜索结果,等同于set hlsearch
set incsearch " 使用搜索时,自动匹配单词的位置高亮显示
set cursorline " 高亮显示当前行
"set cursorcolumn " 高亮显示当前列
set foldenable
set foldmethod=indent
setlocal foldlevel=1
set foldlevelstart=99
"set foldcolumn=0
set laststatus=2
"set showcmd
highlight CursorLine cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
"highlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
" 文件头自动填充 start ----------------------------------------------
autocmd BufNewFile *.cpp exec ":call SetTitle()"
autocmd BufNewFile *.py exec ":call SetTitle()"
func SetTitle()
if &filetype == 'cpp'
call setline(1, "/*****************************************************")
call append(line("."), "* @file ".expand("%"))
call append(line(".")+1, "* @author GaoShuai")
call append(line(".")+2, "* @email boringmanman@qq.com")
call append(line(".")+3, "* @date ".strftime("%Y/%m/%d %H:%M"))
call append(line(".")+4, "* @brief file details.")
call append(line(".")+5, "******************************************************/")
call append(line(".")+6, "")
call append(line(".")+6,"#include<iostream>")
call append(line(".")+7,"using namespace std;")
call append(line(".")+8,"")
elseif &filetype == "python"
call setline(1, "# -*- coding:utf-8 -*-")
call setline(2, '"""')
call setline(3, 'Create on '.strftime("%Y/%m/%d %H:%M"))
call setline(4, '@Author: GaoShuai')
call setline(5, '"""')
call setline(6, '')
endif
endfunc
" 文件头自动填充 end ----------------------------------------------
" F5 执行文件 ----------------------------------
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'cpp'
exec "!g++ -std=c++11 -pthread % -o %<"
exec "! ./%<"
elseif &filetype == 'python'
exec "!python3 %"
endif
endfunc
" F5 执行文件 end ------------------------------
" => 自动补齐, 匹配括号和引号 -----------------------------------{{{1
: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" <c-r>=QuoteDelim('"')<CR>
:inoremap' <c-r>=QuoteDelim("'")<CR>
function! ClosePair(char)
if getline('.')[col('.')-1] == a:char
return "\<Right>"
else
return a:char
endif
endfunc
function! QuoteDelim(char)
let line = getline(".")
let col = col(".")
if line[col-2] == "\\"
return a:char
elseif line[col-1] == a:char
return "\<Right>"
else
return a:char.a:char."\<Esc>i"
endif
endfunc
" 自动补齐 end -------------------------------------------------{{{2
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
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
编辑 (opens new window)
上次更新: 2024/01/17, 10:57:24