vim8 插件升级

历史

我也是用了 spf13-vim + vundle 有七八年了, 之中还用过Pathogen 之类的

这次随着ubuntu $20\to 22$的升级, 有不少之前的插件不支持vim8,不能用了, 虽然根据官网消息,似乎vim9已经出来了

vim8 也有自带的package管理方案:h packages, 看起来需要自己用git维护, 而用vim-plug只需要维护vimrc, 而在8之上还有dein,minpac的插件管理工具

而且还有nvim和vscode+vim键位的一些解决方案

但我有点懒 宁愿多配配 也暂时没想着改习惯

本机是ubuntu, 就没管win和mac的, 其它的看各种工具的官方文档吧

使用vim-plug替代原来的Vundle

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

.vimrc

~/.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
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
set nocompatible            " Must be first line

set encoding=utf-8

" Vim-Plug {
" use `:PlugInstall`
call plug#begin('~/.vim/plugged')
" 搞个好看
Plug 'vim-airline/vim-airline'
"Plug 'vim-airline/vim-airline-themes'
"Plug 'powerline/fonts'
Plug 'bling/vim-bufferline'
" file tree
Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle'}
" quick find and open file by fuzzy match
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tacahiroy/ctrlp-funky'
" 括号匹配类成对修改
Plug 'tpope/vim-surround'
" 注释工具, 不如列编辑?
" Plug 'preservim/nerdcommenter'
" 语法检查,似乎停止维护了,它推荐的是https://github.com/dense-analysis/ale
Plug 'vim-syntastic/syntastic'
" 根据mode 决定是 相对行号,还是绝对行号,很实用
Plug 'myusuf3/numbers.vim'
" git 增强 左侧标识行变化
Plug 'mhinz/vim-signify'
" git 增强 冲突展示
Plug 'rhysd/conflict-marker.vim'
" git增强, 但只有git blame配合用起来稍微有用一点,其它真不如直接gitgggG
Plug 'tpope/vim-fugitive'
" 做快速跳位置的,基本没实际使用,本身有相对行跳转和搜索跳转,暂时不知道它能快多少
Plug 'easymotion/vim-easymotion'
" 做代码模板的,简单+可用
Plug 'tibabit/vim-templates'
" 配色方案
Plug 'flazz/vim-colorschemes'
" Plug 'mg979/vim-visual-multi'
" 方便session 管理???
Plug 'vim-scripts/sessionman.vim'
" 感觉99%用不到,正常的undo redo + git管理足够了
" Plug 'mbbill/undotree'
" 缩进的纵线 python的游标卡尺
Plug 'nathanaelkane/vim-indent-guides'
" 文件关闭再打开,保持光标位置和折叠状态
Plug 'vim-scripts/restore_view.vim'
" 使用时间/项目统计
Plug 'wakatime/vim-wakatime'
"Plug 'godlygeek/tabular'
" 代码补全
Plug 'Valloric/YouCompleteMe'
call plug#end()

filetype off

set rtp+=~/.vim/bundle/Vundle.vim
" Initialize directories {
function! InitializeDirectories()
let parent = $HOME
let prefix = 'vim'
let dir_list = {
\ 'backup': 'backupdir',
\ 'views': 'viewdir',
\ 'swap': 'directory',
\ 'undo': 'undodir',}

" To specify a different directory in which to place the vimbackup,
" vimviews, vimundo, and vimswap files/directories, add the following to
" your .vimrc.before.local file:
" let g:spf13_consolidated_directory = <full path to desired directory>
" eg: let g:spf13_consolidated_directory = $HOME . '/.vim/'
let common_dir = parent . '/.' . prefix

for [dirname, settingname] in items(dir_list)
let directory = common_dir . dirname . '/'
if exists("*mkdir")
if !isdirectory(directory)
call mkdir(directory)
endif
endif
if !isdirectory(directory)
echo "Warning: Unable to create backup directory: " . directory
echo "Try: mkdir -p " . directory
else
let directory = substitute(directory, " ", "\\\\ ", "g")
exec "set " . settingname . "=" . directory
endif
endfor
endfunction
call InitializeDirectories()
" }

" config vim-templates
let g:tmpl_author_email="yexiaorain@gmail.com"
let g:tmpl_license="GPL"

let g:ycm_show_diagnostics_ui = 1
let g:syntastic_cpp_compiler_options = ' -std=c++17'
" https://github.com/ycm-core/YouCompleteMe/issues/429
let g:ycm_global_ycm_extra_conf = '/home/cromarmot/.vim/plugged/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf = 0

"let g:airline_powerline_fonts = 1

let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_guide_size = 1
let g:indent_guides_start_level = 2
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=darkgray
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=0

silent! colorscheme molokai

" ctrlp ignore follow .gitignore
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']

" }

" Basics {
let mapleader = ','

" set foldmarker={,}
" set foldlevel=0
" set foldmethod=marker

filetype plugin indent on " Automatically detect file types.
syntax sync minlines=10000 " when jump to line, highlight brokes
syntax on " Syntax highlighting
set mouse=a " Automatically enable mouse usage
set mousehide " Hide the mouse cursor while typing
scriptencoding utf-8

set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter')
set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibility
set virtualedit=onemore " Allow for cursor beyond last character
set history=1000 " Store a ton of history (default is 20)
" }

" Formatting {
set wrap " wrap long lines
set textwidth=0 " soft wrap
"set linebreak " soft wrap
set nolist "
set autoindent " Indent at the same level of the previous line
set shiftwidth=2 " Use indents of 4 spaces
set expandtab " Tabs are spaces, not tabs
set tabstop=2 " An indentation every four columns
set softtabstop=2 " Let backspace delete indent
"autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl,sql autocmd BufWritePre <buffer> if !exists('g:spf13_keep_trailing_whitespace') | call StripTrailingWhitespace() | endif
" }

" UI {
set backspace=indent,eol,start " Backspace for dummies
set linespace=0 " No extra spaces between rows
set number " Line numbers on
set showmatch " Show matching brackets/parenthesis
set incsearch " Find as you type search
set hlsearch " Highlight search terms
set wildmenu " Show list instead of just completing
set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all.
set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
set scrolljump=5 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minimum lines to keep above and below cursor
set foldenable " Auto fold code
set splitright " Puts new vsplit windows to the right of the current
set splitbelow " Puts new split windows to the bottom of the current
set list
set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
" }

set clipboard=unnamed,unnamedplus " yy to clipboard

" undo {
set backup
set undofile " So is persistent undo ...
set undolevels=1000 " Maximum number of changes that can be undone
set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
" }

set laststatus=2

" highlight {
highlight clear SignColumn " SignColumn should match background
highlight clear LineNr " Current line number row will have same background color in relative mode
hi Normal ctermbg=None
"hi CursorLine cterm=NONE ctermbg=darkgray ctermfg=black guibg=#004488 guifg=white
set cursorline " Highlight current line
hi CursorLine cterm=NONE ctermbg=darkgray ctermfg=white guibg=#004488 guifg=white
set cursorcolumn " Highlight current line
hi CursorColumn cterm=NONE ctermbg=darkgray ctermfg=white guibg=#004488 guifg=white
hi Visual ctermbg=white ctermfg=black guibg=Grey
" }

" keymap {
function CompileByFileType()
if &filetype == "cpp"
"!clang++ -o "%<" "%" -std=gnu++17 -O2 -g -Wall -Wcomma -Wextra -fsanitize=integer,undefined,null,alignment
!clang++ -o "%<" "%" -std=gnu++20 -O2 -g -Wall -Wcomma -Wextra -fsanitize=integer,undefined,null,alignment
"!clang++ -o "%<" "%" -std=gnu++14 -O2 -g -Wall -Wcomma -Wextra -fsanitize=integer,undefined,null,alignment
" !clang++ -o "%<" "%" -std=gnu++11 -O2 -g -Wall -Wcomma
"!clang++ -o "%<" "%" -std=gnu++17 -g -Wall -Wcomma
"!g++ -o "%<" "%" -std=gnu++17 -O2 -g -Wall
elseif &filetype == "c"
!gcc -o "%<" "%" -O2 -g
elseif &filetype == "python"
!python3 "%"
elseif &filetype == "go"
!go run "%"
elseif &filetype == "rust"
!rustc "%" -O
elseif &filetype == "sh"
!bash "%"
elseif &filetype == "javascript"
!node "%"
elseif &filetype == "typescript"
!npx ts-node "%"
else
echo "UNKNOWN FILETYPE : "&filetype
endif
endfunction

"auto remove trailing whitespace
autocmd BufWritePre * :%s/\s\+$//e
autocmd FileType * set formatoptions-=cro " from :help fo-table, disable 'o' and 'O' create comment line

nnoremap <F9> :call CompileByFileType() <CR>
nnoremap <F8> :!gdb "%<"<CR>
nnoremap <F2> :NERDTreeToggle<CR>

" }
"

YouCompleteMe 额外操作

1
2
cd ~/.vim/plugged/YouCompleteMe
# git submodule update --init --recursive --depth=1

这玩意儿不知道为啥走用proxychains4有问题,直接下 没代理又太慢, 需要先手动下一些支持

c-like: clang:

https://github.com/ycm-core/llvm/releases/download/14.0.0/libclang-14.0.0-x86_64-unknown-linux-gnu.tar.bz2下载到 ~/.vim/plugged/YouCompleteMe/third_party/ycmd/clang_archives/

c#:

https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.37.11/omnisharp.http-linux-x64.tar.gz 下载到 ~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/omnisharp-roslyn/v1.37.11

1
2
python3 ./install.py --clang-completer --verbose
# python3 ./install.py --all --verbose # 其它语言支持,需要自己去找相应的包,不然这墙难受死

总结

vim的好处就是默认的很足, 即使我在删掉了所有~/.vim时,用起来依然顺手

看着这些老仓库,好多从个人帐号下的变成了组织帐号下的

Ref

vim-plug

Reddit::plugin managers vs vim packages

how to install ycm offline