GVim_配置分享

来给大家分享一下个人使用的GVim配置,该文章后续会一直更新。我是一位初学vim的小萌新,打算用这篇文章记录下GVim的学习历程哈哈。希望也能帮到大家。如有不足,欢迎留言。🙏

自我介绍

LazyVim 出现以后,我也尝试过 neovim 。但一段时间后,又转回了GVim。有两方面原因:

  • LazyVim很方便,提供了大量的快捷键操作,快捷的插件管理。但是正因如此,我需要花费大量的成本去学习。现在的我确实没有足够的时间成本去学习这门工具
  • 自己更喜欢从无到有,一步一个脚印的去掌握这门工具。从根基开始建立一栋大楼,更加有成就感。同时,这也能让我在实践中确切明白自身的需求,回归工具的本质。提高熟练度的同时,规避了臃肿的配置。

插件配置

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
call plug#begin('~/vimfiles/plugged')
Plug 'chr4/nginx.vim'
Plug 'vim-scripts/c.vim'
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/syntastic'
Plug 'preservim/vim-indent-guides'
Plug 'neoclide/coc.nvim', {'branch': 'release'} "补全
Plug 'vim-airline/vim-airline' "状态栏
Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdcommenter' "注释
Plug 'junegunn/vim-easy-align' "对齐
Plug 'dense-analysis/ale' "语法检查
call plug#end()

"-------------- vim 的插件设置------------------"

" NerdTree
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>
let NERDTreeShowBookmarks=1 "当打开NERDTree窗口时,自动显示Bookmarks

" YouCompleteMe


"vim-indent
" 随 vim 自启动
let g:indent_guides_enable_on_vim_startup=1
" 从第二层开始可视化显示缩进
let g:indent_guides_start_level=2
" 色块宽度
let g:indent_guides_guide_size=1

"---------------------------------------------------"

界面基础设置

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
" 字体设置
set guifont=Fira_Code_medium:h14:W500:cANSI:qDRAFT
" 案件映射
map J 5gj
map K 5gk

map j gj
map k gk

map H ^
map L $

imap jk <Esc>

nmap <space><Cr> :nohls<Cr>
"代码高亮
syntax on
"工具栏取消
set guioptions=
"显示行号
set number
"gvim的tab默认长度
set tabstop=4
set expandtab
set shiftwidth=4
"指定文件的编码方式
"Vim 在与屏幕/键盘交互时使用的编码(取决于实际的终端的设定)
" 编码设置
set encoding=utf-8
set fileencodings=utf-8,cp936,gb2123
if has("win32")
set fileencoding=utf-8
else
set fileencoding=utf-8
endif
source $VIMRUNTIME/delmenu.vim "解决菜单乱码
source $VIMRUNTIME/menu.vim
language messages zh_CN.utf-8 "解决consle输出乱码
"显示括号之间的匹配
set showmatch
"支持鼠标操作
set mouse=a
"自动缩进
set autoindent
"set smartindent
"最后状态栏变为两行
set laststatus=2
"看到每次输入的指令
set showcmd
"支持256位颜色
set t_Co=256
"通过退格键换行
set backspace=start,eol,indent
"开启搜索代码高亮
set hlsearch
set incsearch
"保证最下面5行
set scrolloff=5
"组合键的时间间隔
set timeoutlen=500
"指定行数和列数
set lines=30 columns=80
"背景颜色
colorscheme darcula


GUI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
" 标签页
set showtabline=2 " 总是显示标签栏
set showcmd " 状态栏显示目前所执行的指令
set laststatus=2 " 开启状态栏信息
set cmdheight=1 " 命令行的高度
"不显示工具/菜单栏
set guioptions-=T "工具栏
"set guioptions-=m "菜单栏
set guioptions-=L "左边滚动条
set guioptions-=r "右边滚动条
set guioptions-=b " 底部滚动条
set guioptions-=e " 使用内置 tab 样式而不是 gui
let g:airline_powerline_fonts = 1 "关于状态栏的配置
" 缺省自动匹配主题
let g:airline_theme='base16_classic'
let g:airline#extensions#tabline#enabled = 1 " Air-line 显示上面的buffer tab
let g:airline#extensions#ale#enabled = 1
let g:airline#extensions#coc#enabled = 1 "coc
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're usin

自动括号匹配

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
inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {}<Esc>i
autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<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
endf
function! CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf
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
endf

编译、运行

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
func! CompileC()  " 编译C源文件
exec "w"
exec "!g++ -Wall %"
endfunc
func! CompileCpp() " 编译C++源文件
exec "w"
exec "!g++ -Wall %"
endfunc
func! Compilefortran() " 编译fortran源文件
exec "w"
exec "!gfortran -Wall %"
endfunc
func! RunLua() " 运行Lua源文件
exec "w"
exec "!lua %"
endfunc
func! RunPerl() " 运行Perl源文件
exec "w"
exec "!perl %"
endfunc
func! RunPython() " 运行Python源文件
exec "w"
exec "!python %"
endfunc
func! CompileCode() " 根据文件类型自动选择相应的编译函数
exec "w"
if &filetype == "c"
exec "call CompileC()"
elseif &filetype == "cpp"
exec "call CompileCpp()"
elseif &filetype == "fortran"
exec "call Compilefortran()"
elseif &filetype == "lua"
exec "call RunLua()"
elseif &filetype == "perl"
exec "call RunPerl()"
elseif &filetype == "python"
exec "call RunPython()"
endif
endfunc
func! RunResult() " 运行可执行文件
exec "w"
if &filetype == "c"
exec "w"
exec "!gcc % -Wall -std=c99 -O2 -o %<.exe"
exec "!start cmd /c \"\"%<.exe\" & pause & del *.exe\""
elseif &filetype == "cpp"
exec "w"
exec "!g++ % -Wall -std=c++11 -O2 -o %<.exe"
exec "!start cmd /c \"\"%<.exe\" & pause & del *.exe\""
elseif &filetype == "fortran"
exec "w"
exec "!gfortran % -Wall -O2 -o %<.exe"
exec "!start cmd /c \"\"%<.exe\" & pause & del *.exe\""
elseif &filetype == "lua"
exec "!start cmd /c lua %<.lua & pause"
elseif &filetype == "perl"
exec "!start cmd /c perl %<.pl & pause"
elseif &filetype == "python"
exec "w"
exec "!start cmd /c \"python %<.py & pause\""
elseif &filetype == "markdown"
exec "w"
exec "MarkdownPreview"
endif
endfunc
" Ctrl + f5 一键保存、编译
map <C-f5> :call CompileCode()<CR>
imap <C-f5> <ESC>:call CompileCode()<CR>
vmap <C-f5> <ESC>:call CompileCode()<CR>
" Ctrl + b 一键保存、运行
map <C-b> :call RunResult()<CR>
imap <C-b> <ESC>:call RunResult()<CR>
vmap <C-b> <ESC>:call RunResult()<CR>

效果图

image-20240226023121950


评论