Configure Vim

Install plug.vim file

1
curl https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim > ~/.vim/autoload

Configure .vimrc file

Copy the below configuration to ~/.vimrc.

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
call plug#begin('~/.vim/plugged')
"在这里使用 Plug "github用户/项目名" 的方式引入插件
"Import plugin by using Plug "github_username/project_name"

"彩虹括号
"Rainbow bracket
Plug 'luochen1990/rainbow'

"历史记录
"History record
"Plug 'mhinz/vim-startify'

"One Dark Theme
Plug 'joshdick/onedark.vim'
call plug#end()


"设置配色,这里选择的是 desert,也有其他方案,在 vim 中输入 :color 再敲 tab 键可以查看
"Set color. Here is desert by default. Type :color in vim and press tab to view other options
"color desert
color onedark

"设置背景色,每种配色有两种方案,一个 light、一个 dark
"Set background each of which has two mode, light and dark
set background=dark

let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle

"传说中的去掉边框用下边这一句
"Remove border
set go=

"打开语法高亮
"Turn on syntax highlighting
syntax on

"显示行号
"Show line number
set number

"设置缩进有三个取值 cindent(C 风格)、smartindent(智能模式,其实不觉得有什么智能)、autoindent(简单的与上一行保持一致)
"Set Indent with three values: cindent/、smartindent/、autoindent
set cindent

"用空格键替换制表符
"Replace tabs with the space bar
:set expandtab

"制表符占 4 个空格
"Tabs take up 4 spaces
set tabstop=4

"默认缩进 4 个空格大小
"The default indent size is 4 spaces
set shiftwidth=4

"增量式搜索
"Incremental search
set incsearch

"高亮搜索
"Highlight search
set hlsearch

"有时中文会显示乱码,用一下几条命令解决
"Solve Chinese garbled code
let &termencoding=&encoding
set fileencodings=utf-8,gbk

"很多插件都会要求的配置检测文件类型
"Check file type
:filetype on
:filetype plugin on
:filetype indent on

"下边这个很有用可以根据不同的文件类型执行不同的命令
"Run different commands based on different file types
"例如:如果是 C/C++ 类型
"For example, if for C/C++
:autocmd FileType c,cpp :set foldmethod=syntax
:autocmd FileType c,cpp :set number
:autocmd FileType c,cpp :set cindent

"例如:如果是 Python 类型
"For example, if for Python
:autocmd FileType python :set number
:autocmd FileType python :set foldmethod=syntax
:autocmd FileType python :set smartindent

Vim Plugin Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!-- Install specific plugin such as  -->
<!-- :PlugInstall gist-vim -->
:PlugInstall <plugin_name>
<!-- Install all plugins specified in .vimrc -->
:PlugInstall

<!-- Remove plugin -->
<!-- Note that remove or comment out plugin configuration in .vimrc in advance -->
:PlugClean <plugin_name>

<!-- Udgrade vim-plug itself -->
:PlugUpgrade

<!-- Update all plugins -->
:PlugUpdate

<!-- Review the infomation of installed plugin -->
:PlugStatus <plugin_name>

Configure Vim
http://wasprime.github.io/Configuration/Vim/Configure-Vim/
Author
wasPrime
Posted on
March 28, 2023
Updated on
April 10, 2023
Licensed under