系列文章

  1. neo|vim高效编辑的基本配置
  2. 进化neovim到lin.nvim风味
  3. 我的Learn Lua in Y minutes
  4. (lin.)nvim启用Copilot补全
  5. lin.nvim中安装其它插件
  6. ubuntu工作环境初始化脚本
  7. 一款流畅的、用于重构代码的neovim插件:ChatGPT.nvim
  8. 填坑:(neo)vim中自动切换中文输入法
  9. lin.nvim中配置编程语言LSP补全

家门不幸啊 😭:

  • 把随身Linux系统格式化重装之后,发现用作Linux数据全盘备份的固态硬盘坏了。
  • 只好找到另一块数据备份的机械硬盘,以恢复随身Linux系统的数据。但是三大件(zsh, tmux, neovim)的配置文件还是几年前的状态。

zshtmux还好,但是neovim的插件都太旧了。趁着这次机会,把neovim相关功能替换成更新潮的插件。但在此之前,我需要把先前的neovim的配置清理一下,提炼出我欣赏的基本功能,并把这些配置做成neovim、vim通用的状态。

安装neovim插件工具

Windows系统的wsl终端中,为neovim安装插件管理工具vim-plug,指令如下:

1
2
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

清理后的init.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
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
set number 
set linebreak
set cursorline
set cursorcolumn
set tabstop=4
set expandtab
set shiftwidth=4
set textwidth=120 "设置文本行最长
set nowrap "不要自动折行
set guifont=Ubuntu\ Mono\ 13
set foldmethod=marker " code fold method
"
"python provider ref. :he python-provider
let g:python3_host_prog = '/usr/bin/python3'
let g:python_host_prog = '/usr/bin/python'


" Vim-Plug (no Plug) "{{{
" Specify a directory for plugins (for Neovim: ~/.local/share/nvim/plugged)
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
Plug 'flazz/vim-colorschemes'
Plug 'jlanzarotta/colorSchemeExplorer'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'jpalardy/vim-slime'
Plug 'edkolev/tmuxline.vim'
Plug 'luochen1990/rainbow'

Plug 'troydm/zoomwintab.vim'
Plug 'zhaocai/GoldenView.Vim'
Plug 'kien/ctrlp.vim'
Plug '907th/vim-auto-save'

Plug 'kshenoy/vim-signature'
Plug 'dimasg/vim-mark'
Plug 'terryma/vim-expand-region'
Plug 'Lokaltog/vim-easymotion'
Plug 'junegunn/vim-easy-align'
Plug 'vim-scripts/VisIncr'
Plug 'cohama/lexima.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'majutsushi/tagbar'

" Initialize plugin system
call plug#end()
"}}}

"------ ColorScheme个性化配置命令------"{{{
set background=dark

"colors molokai
"colors Monokai
colors monokai-chris
"专为Monokai设置的背景色和选中项目颜色
hi Pmenu ctermbg=127
hi PmenuSel ctermbg=105
"}}}

"------ vim-airline ------ "{{{
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_idx_mode = 1

nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9

let g:airline#extensions#tmuxline#enabled = 1
let g:airline_theme="tomorrow"


let airline#extensions#tmuxline#color_template = 'visual'
"}}}

"------ tagbar ------ "{{{
nnoremap tb :TagbarToggle<CR>
let g:tagbar_sort = 0
let g:tagbar_width = 50
let g:tagbar_autofocus = 1
let g:tagbar_show_linenumbers = 2
let g:tagbar_autoclose = 1
let g:tagbar_autoshowtag = 1
"}}}

"------ GoldenView ------"{{{
let g:goldenview__enable_at_startup = 0
let g:goldenview__enable_default_mapping=0
nmap <silent> sv <Plug>GoldenViewSplit
nmap <silent> tm <Plug>GoldenViewSwitchMain
nmap <silent> ts <Plug>GoldenViewSwitchToggle
nmap <silent> tf <Plug>ToggleGoldenViewAutoResize
nmap <silent> sn <Plug>GoldenViewNext
nmap <silent> sp <Plug>GoldenViewPrevious
nmap <silent> tn :tabn<CR>
nmap <silent> tp :tabp<CR>
"}}}

"------ luochen1990/rainbow 彩色括号 ------"{{{
let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle
let g:rainbow_conf = {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'lisp': {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
"}}}

"------ vim-auto-save -------"{{{
let g:auto_save = 1 " enable AutoSave on Vim startup
let g:auto_save_no_updatetime = 1 " do not change the 'updatetime' option
let g:auto_save_in_insert_mode = 0 " do not save while in insert mode
"let g:auto_save_postsave_hook = 'TagsGenerate' " this will run :TagsGenerate after each sav
"let g:auto_save_events = ["InsertLeave", "TextChanged"]
let g:auto_save_keep_marks = 0 " Don't keep the '[ and '] marks. It will break
" the selecting your pasted text mapping:
" http://vim.wikia.com/wiki/Selecting_your_pasted_text
"}}}

"------ vim-slime ---------
" bind tmux
let g:slime_target = "tmux"

"------ easy-align -----------
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)

"------- vim-mark -------
let g:mwDefaultHighlightingPalette = 'extended'
let g:mwDefaultHighlightingNum = 9

"------ Lokaltog/vim-easymotion -------
map , <Plug>(easymotion-prefix)

"------ ctrlp ------
"let g:ctrlp_extensions = ['quickfix', 'dir']
let g:ctrlp_max_depth = 3 "max depth when search direcories

建立公用的插件文件夹

在上述init.vim配置文件中,如下指令配置了neovim插件的安装位置:

1
2
" Specify a directory for plugins (for Neovim: ~/.local/share/nvim/plugged)
call plug#begin('~/.vim/plugged')

之所以放在用户主目录的.vim文件夹之下,是为了与vim编辑器共享插件目录更方便一些。我们不用手动的建立~/.vim/plugged,在利用vim-plug更新插件时,会自动创建该文件夹。终端下执行:

1
nvim

进入neovim后,在命令模式下:

1
:PlugUpdate

收尾与未来的工作计划

至此,对我认为的核心编辑功能,为neovim完成了配置。对于vim也是类似的道理,我们有如下操作:

1
2
3
4
5
6
# 直接用neovim的配置文件,符号链接为vim的配置文件.vimrc
ln -s ~/.config/nvim/init.vim .vimrc

# 为vim安装vim-plug的插件管理工具
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

启动vim,可以看到如下成功启动的画面;而且vimneovim公用同一套配置和插件文件。

vim成功启动界面

有人或许会认为这是多此一举,但事实上,这么做主要时为了冗余和兼容。因为有时候我们远程登录主机,而大多数主机是自带vim终端编辑器的。此时我们可以直接把本地的配置文件同步到远端(并在用户主目录下保存为.vimrc),这样我们直接就有了一个最小化的高效编辑器。

为了简洁,我们只保留了最基本的外观配置、窗口管理、文本编辑(标记/移动/跳转)等。对于代码补全等IDE功能,我们并没有涉及。

下一步,打算基于lin.nvim重构基于neovimIDE,并把本文中的最小化功能合并到我的IDE 中。