aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-05-22 13:57:46 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-05-22 13:57:46 +0800
commit76922c395db1d9745e2a47f8c0584545958a3fee (patch)
treed616e2b0eaa79276ca17b513e42b862a102da9de
parentffd076d2c434d6c850dd1a05a19ff477c2a29023 (diff)
Update
-rw-r--r--Makefile6
-rw-r--r--vim/init/basic.vim279
-rw-r--r--vim/init/config.vim182
-rw-r--r--vim/init/keymaps.vim448
-rw-r--r--vim/init/plugins.vim719
-rw-r--r--vim/init/style.vim291
-rw-r--r--vim/init/tabsize.vim44
-rw-r--r--vim/lazy/lazy.lua (renamed from vim/kickstarter.lua)94
-rw-r--r--vim/vimrc (renamed from vim/init.vim)16
9 files changed, 1977 insertions, 102 deletions
diff --git a/Makefile b/Makefile
index 0ed81b5..49c03be 100644
--- a/Makefile
+++ b/Makefile
@@ -15,10 +15,10 @@ tig:
15 ln -sf `pwd`/tigrc ~/.tigrc 15 ln -sf `pwd`/tigrc ~/.tigrc
16 16
17vim: 17vim:
18 ln -sf `pwd`/vim/init.vim ~/.vimrc 18 ln -sf `pwd`/vim/vimrc ~/.vimrc
19 mkdir -p ~/.config/nvim 19 mkdir -p ~/.config/nvim
20 ln -sf `pwd`/vim/init.vim ~/.config/nvim/init.vim 20 ln -sf `pwd`/vim/vimrc ~/.config/nvim/init.vim
21 ln -sf `pwd`/vim/kickstarter.lua ~/.config/nvim/kickstarter.lua 21 ln -sf `pwd`/vim/lazy/lazy.lua ~/.config/nvim/lazy.lua
22 # vim-plug 22 # vim-plug
23 # curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 23 # curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
24 24
diff --git a/vim/init/basic.vim b/vim/init/basic.vim
new file mode 100644
index 0000000..4c6cd45
--- /dev/null
+++ b/vim/init/basic.vim
@@ -0,0 +1,279 @@
1"======================================================================
2"
3" init-basic.vim - Need vim tiny compatible
4"
5" Used for general usecases. No keymap and personal preference
6"
7" Use '*' to search for:
8" VIM_BEHAVIOR
9" VISUAL
10" EDIT
11" JUMP
12" SEARCH
13" SYNTAX_HIGHLIGHT
14" BUFFERS
15" ENCODING_PREFERENCE
16" FOLDING
17" MISC
18"======================================================================
19
20
21"----------------------------------------------------------------------
22" VIM_BEHAVIOR
23"----------------------------------------------------------------------
24
25let mapleader = "," " Always use comma as leader key
26set nocompatible " Disable vi compatible, today is 20XX
27set autochdir " Automatically cd to current file
28set path=.,** " Allow :find with completion
29set mouse= " Disable mouse selection
30set winaltkeys=no " Allow alt key for mapping
31set cursorline
32
33" Turn persistent undo on
34" means that you can undo even when you close a buffer/VIM
35set undofile
36set undodir=~/.vim/.undodir
37set conceallevel=1
38
39" Apply plugin and indent by filetype
40filetype plugin indent on
41
42
43"----------------------------------------------------------------------
44" VISUAL
45"----------------------------------------------------------------------
46
47colorscheme desert " I like desert!
48" In most of the cases, it is overrides by lightline.vim
49set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
50set showmatch " Show pairing brackets
51
52set number relativenumber " Use relativenumber
53set wrap " Disable wrap by default
54set scrolloff=3 " Leave some buffer when scrolling down
55set ruler " Show cursor position
56set laststatus=2 " Always show the status line
57set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20
58
59
60"----------------------------------------------------------------------
61" EDIT
62"----------------------------------------------------------------------
63
64set backspace=eol,start,indent " Set Backspace behaviors
65set autoindent " If current line has indent, automatically set indent for next line
66set cindent
67set ttimeout
68set ttimeoutlen=50
69set updatetime=250
70
71imap <C-c> <Esc>l
72" Change IM to US when exit to Normal mode
73autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true
74
75
76"----------------------------------------------------------------------
77" JUMP
78"----------------------------------------------------------------------
79
80set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file)
81set suffixesadd=.md " Enable reference markdown file without extension
82
83
84"----------------------------------------------------------------------
85" SEARCH
86"----------------------------------------------------------------------
87set ignorecase " Search case without case sensation
88set smartcase
89set hlsearch " Hilight all matched texts
90set incsearch " Show matched strings when typing
91
92
93"----------------------------------------------------------------------
94" SYNTAX_HIGHLIGHT
95"----------------------------------------------------------------------
96
97syntax enable
98
99function! GetHighlightGroupName()
100 let l:syntaxID = synID(line('.'), col('.'), 1)
101 let l:groupName = synIDattr(l:syntaxID, 'name')
102 echo "Highlight Group Name: " . l:groupName
103endfunction
104
105" Defualt highlight for matched parenthesis is so weird in many colorscheme
106" Why the background color is lighter than my caret !?
107highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE
108highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE
109
110" Show trailing spaces
111highlight ExtraWhitespace ctermbg=red guibg=red
112match ExtraWhitespace /\s\+$/
113
114" Persist visualized lines
115" define line highlight color
116highlight MultiLineHighlight ctermbg=LightYellow guibg=LightYellow ctermfg=Black guifg=Black
117" highlight the current line
118nnoremap <silent> <leader><leader>h :call matchadd('MultiLineHighlight', '\%'.line('.').'l')<CR>
119" clear all the highlighted lines
120nnoremap <silent> <leader><leader>H :call clearmatches()<CR>
121
122
123"----------------------------------------------------------------------
124" BUFFERS
125"----------------------------------------------------------------------
126
127" Set to auto read when a file is changed from the outside
128" Unnamed buffer like CmdWindows should prevent this
129set autoread
130autocmd FocusGained,BufEnter .* checktime
131
132let g:quitVimWhenPressingCtrlC = 1
133function! ToggleQuit()
134 let g:quitVimWhenPressingCtrlC = g:quitVimWhenPressingCtrlC ? 0 : 1
135 let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock"
136 echo message
137endfunction
138
139nnoremap gl :call ToggleQuit()<CR>
140
141" Simply exit when closing the last buffer
142function! Bye()
143 " Delete current buffer if working on special filetype
144 let specialFileTypes = ['help', 'netrw', 'vim-plug', 'nerdtree']
145 if index(specialFileTypes, &filetype) != -1
146 :bdelete
147 " Delete current buffer if more than one buffers
148 elseif len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) != 1
149 :bdelete
150 elseif g:quitVimWhenPressingCtrlC
151 " Otherwise, quit vim
152 :silent! qall
153 else
154 :echo "Press gl to allow quit with <C-c>"
155 endif
156endfunction
157
158" Ctrl-C rules!!!
159nnoremap <silent> <C-c> :call Bye()<CR>
160
161" Don't unload a buffer when no longer shown in a window
162" This allows you open a new buffer and leaves current buffer modified
163set hidden
164
165
166" Put these in an autocmd group, so that you can revert them with:
167" ":augroup vimStartup | au! | augroup END"
168augroup vimStartup
169au!
170
171" When editing a file, always jump to the last known cursor position.
172" Don't do it when the position is invalid, when inside an event handler
173" (happens when dropping a file on gvim) and for a commit message
174" (it's likely a different one than last time).
175autocmd BufReadPost *
176 \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
177 \ | exe "normal! g`\""
178 \ | endif
179augroup END
180
181" Set filetype for beancount
182autocmd BufRead,BufNewFile *.bean call PrepareBean()
183function PrepareBean()
184 set filetype=beancount
185 silent !setsid fava ~/bean/main.bean &>/dev/null
186 autocmd VimLeave * silent !killall fava
187endfunction
188
189" Set filetype for index.html
190autocmd BufWrite *.html,*.js,*.css call ReloadServer()
191function ReloadServer()
192 silent !browser-sync reload &>/dev/null
193endfunction
194
195" Hide the first line of a file if editing password file
196" TODO a better way to determine a file is related to password-store, now use
197" files under /dev/shm as filter
198autocmd BufRead /dev/shm/*.txt call SetPasswordFile()
199function SetPasswordFile()
200 setlocal foldminlines=0
201 setlocal foldmethod=manual
202 setlocal foldtext=
203 norm! ggzfl
204endfunction
205
206
207
208"----------------------------------------------------------------------
209" ENCODING_PREFERENCE
210"----------------------------------------------------------------------
211if has('multi_byte')
212 set encoding=utf-8
213 set fileencoding=utf-8
214 " Try encodings by this order
215 set fileencodings=utf-8,big5,ucs-bom,gbk,gb18030,euc-jp,latin1
216endif
217
218
219"----------------------------------------------------------------------
220" FOLDING
221"----------------------------------------------------------------------
222set foldenable " Allow fold
223set foldmethod=indent " Fold contents by indent
224set foldlevel=99 " Expand all by default
225
226
227"----------------------------------------------------------------------
228" MISC
229"----------------------------------------------------------------------
230
231" 顯示括號匹配的時間
232set matchtime=2
233
234" 顯示最後一行
235set display=lastline
236
237" 允許下方顯示目錄
238set wildmenu
239
240" Improve performance
241set lazyredraw
242
243" Format of error message
244set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
245
246" 顯示分隔符號
247set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
248
249" 遇到Unicode值大於255的文本,不必等到空格再折行
250set formatoptions+=m
251
252" 合併兩行中文時,不在中間加空格
253set formatoptions+=B
254
255" Use Unix way to add newline
256set ffs=unix,dos,mac
257
258
259"----------------------------------------------------------------------
260" Ignore these suffixes when find/complete
261"----------------------------------------------------------------------
262set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.pyc,.pyo,.egg-info,.class
263
264set wildignore=*.o,*.obj,*~,*.exe,*.a,*.pdb,*.lib "stuff to ignore when tab completing
265set wildignore+=*.so,*.dll,*.swp,*.egg,*.jar,*.class,*.pyc,*.pyo,*.bin,*.dex
266set wildignore+=*.zip,*.7z,*.rar,*.gz,*.tar,*.gzip,*.bz2,*.tgz,*.xz " MacOSX/Linux
267set wildignore+=*DS_Store*,*.ipch
268set wildignore+=*.gem
269set wildignore+=*.png,*.jpg,*.gif,*.bmp,*.tga,*.pcx,*.ppm,*.img,*.iso
270set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/.rbenv/**
271set wildignore+=*/.nx/**,*.app,*.git,.git
272set wildignore+=*.wav,*.mp3,*.ogg,*.pcm
273set wildignore+=*.mht,*.suo,*.sdf,*.jnlp
274set wildignore+=*.chm,*.epub,*.pdf,*.mobi,*.ttf
275set wildignore+=*.mp4,*.avi,*.flv,*.mov,*.mkv,*.swf,*.swc
276set wildignore+=*.ppt,*.pptx,*.docx,*.xlt,*.xls,*.xlsx,*.odt,*.wps
277set wildignore+=*.msi,*.crx,*.deb,*.vfd,*.apk,*.ipa,*.bin,*.msu
278set wildignore+=*.gba,*.sfc,*.078,*.nds,*.smd,*.smc
279set wildignore+=*.linux2,*.win32,*.darwin,*.freebsd,*.linux,*.android
diff --git a/vim/init/config.vim b/vim/init/config.vim
new file mode 100644
index 0000000..7e08ebf
--- /dev/null
+++ b/vim/init/config.vim
@@ -0,0 +1,182 @@
1"======================================================================
2"
3" init-config.vim - 正常模式下的配置,在 init-basic.vim 后调用
4"
5" Created by skywind on 2018/05/30
6" Last Modified: 2018/05/30 19:20:46
7"
8"======================================================================
9" vim: set ts=4 sw=4 tw=78 noet :
10
11" Open help page in a new tab
12autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif
13
14
15"----------------------------------------------------------------------
16" 有 tmux 何没有的功能键超时(毫秒)
17"----------------------------------------------------------------------
18if $TMUX != ''
19 set ttimeoutlen=30
20elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0
21 set ttimeoutlen=80
22endif
23
24
25"----------------------------------------------------------------------
26" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021
27" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面)
28"----------------------------------------------------------------------
29if has('nvim') == 0 && has('gui_running') == 0
30 function! s:metacode(key)
31 exec "set <M-".a:key.">=\e".a:key
32 endfunc
33 for i in range(10)
34 call s:metacode(nr2char(char2nr('0') + i))
35 endfor
36 for i in range(26)
37 call s:metacode(nr2char(char2nr('a') + i))
38 call s:metacode(nr2char(char2nr('A') + i))
39 endfor
40 for c in [',', '.', '/', ';', '{', '}']
41 call s:metacode(c)
42 endfor
43 for c in ['?', ':', '-', '_', '+', '=', "'"]
44 call s:metacode(c)
45 endfor
46endif
47
48
49"----------------------------------------------------------------------
50" 终端下功能键设置
51"----------------------------------------------------------------------
52function! s:key_escape(name, code)
53 if has('nvim') == 0 && has('gui_running') == 0
54 exec "set ".a:name."=\e".a:code
55 endif
56endfunc
57
58
59"----------------------------------------------------------------------
60" 功能键终端码矫正
61"----------------------------------------------------------------------
62call s:key_escape('<F1>', 'OP')
63call s:key_escape('<F2>', 'OQ')
64call s:key_escape('<F3>', 'OR')
65call s:key_escape('<F4>', 'OS')
66call s:key_escape('<S-F1>', '[1;2P')
67call s:key_escape('<S-F2>', '[1;2Q')
68call s:key_escape('<S-F3>', '[1;2R')
69call s:key_escape('<S-F4>', '[1;2S')
70call s:key_escape('<S-F5>', '[15;2~')
71call s:key_escape('<S-F6>', '[17;2~')
72call s:key_escape('<S-F7>', '[18;2~')
73call s:key_escape('<S-F8>', '[19;2~')
74call s:key_escape('<S-F9>', '[20;2~')
75call s:key_escape('<S-F10>', '[21;2~')
76call s:key_escape('<S-F11>', '[23;2~')
77call s:key_escape('<S-F12>', '[24;2~')
78
79
80"----------------------------------------------------------------------
81" 防止tmux下vim的背景色显示异常
82" Refer: http://sunaku.github.io/vim-256color-bce.html
83"----------------------------------------------------------------------
84if &term =~ '256color' && $TMUX != ''
85 " disable Background Color Erase (BCE) so that color schemes
86 " render properly when inside 256-color tmux and GNU screen.
87 " see also http://snk.tuxfamily.org/log/vim-256color-bce.html
88 set t_ut=
89endif
90
91
92"----------------------------------------------------------------------
93" 备份设置
94"----------------------------------------------------------------------
95
96" 允许备份
97set backup
98
99" 保存时备份
100set writebackup
101
102" 备份文件地址,统一管理
103set backupdir=~/.vim/tmp
104
105" 备份文件扩展名
106set backupext=.bak
107
108" 禁用交换文件
109set noswapfile
110
111" 创建目录,并且忽略可能出现的警告
112silent! call mkdir(expand('~/.vim/tmp'), "p", 0755)
113
114
115"----------------------------------------------------------------------
116" 配置微调
117"----------------------------------------------------------------------
118
119" 修正 ScureCRT/XShell 以及某些终端乱码问题,主要原因是不支持一些
120" 终端控制命令,比如 cursor shaping 这类更改光标形状的 xterm 终端命令
121" 会令一些支持 xterm 不完全的终端解析错误,显示为错误的字符,比如 q 字符
122" 如果你确认你的终端支持,不会在一些不兼容的终端上运行该配置,可以注释
123if has('nvim')
124 set guicursor=
125elseif (!has('gui_running')) && has('terminal') && has('patch-8.0.1200')
126 let g:termcap_guicursor = &guicursor
127 let g:termcap_t_RS = &t_RS
128 let g:termcap_t_SH = &t_SH
129 set guicursor=
130 set t_RS=
131 set t_SH=
132endif
133
134" 打开文件时恢复上一次光标所在位置
135autocmd BufReadPost *
136 \ if line("'\"") > 1 && line("'\"") <= line("$") |
137 \ exe "normal! g`\"" |
138 \ endif
139
140" 定义一个 DiffOrig 命令用于查看文件改动
141if !exists(":DiffOrig")
142 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
143 \ | wincmd p | diffthis
144endif
145
146
147
148"----------------------------------------------------------------------
149" 文件类型微调
150"----------------------------------------------------------------------
151augroup InitFileTypesGroup
152
153 " 清除同组的历史 autocommand
154 au!
155
156 " C/C++ 文件使用 // 作为注释
157 au FileType c,cpp setlocal commentstring=//\ %s
158
159 " markdown 允许自动换行
160 au FileType markdown setlocal wrap
161
162 " lisp 进行微调
163 au FileType lisp setlocal ts=8 sts=2 sw=2 et
164
165 " scala 微调
166 au FileType scala setlocal sts=4 sw=4 noet
167
168 " haskell 进行微调
169 au FileType haskell setlocal et
170
171 " quickfix 隐藏行号
172 au FileType qf setlocal nonumber
173
174 " 强制对某些扩展名的 filetype 进行纠正
175 au BufNewFile,BufRead *.as setlocal filetype=actionscript
176 au BufNewFile,BufRead *.pro setlocal filetype=prolog
177 au BufNewFile,BufRead *.es setlocal filetype=erlang
178 au BufNewFile,BufRead *.asc setlocal filetype=asciidoc
179 au BufNewFile,BufRead *.vl setlocal filetype=verilog
180 au BufRead /tmp/mutt-* set tw=72
181
182augroup END
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim
new file mode 100644
index 0000000..5e472d2
--- /dev/null
+++ b/vim/init/keymaps.vim
@@ -0,0 +1,448 @@
1"======================================================================
2"
3" Only for key mapping
4"
5" - COMMON_MAPPING
6" - LINKS
7" - MOVING_WITH_READLINE
8" - JUMP_TO_TABS_WITH_ALT
9" - MANAGE_TABS
10" - MANAGE_BUFFERS
11" - SURROURD_WITH_CHAR
12" - REDIRECTION_WITH_BUFFER
13" - 终端支持
14" - 编译运行
15" - 符号搜索
16"
17"======================================================================
18" vim: set ts=4 sw=4 tw=78 noet :
19
20"----------------------------------------------------------------------
21" COMMON_MAPPING
22"----------------------------------------------------------------------
23
24" Space for searching
25map <space> /
26
27" j/k will move virtual lines (lines that wrap)
28noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
29noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
30
31" Search for selected test
32vnoremap * y/\V<C-R>=escape(@",'/\')<CR><CR>
33
34" Disable highlight when <leader><cr> is pressed
35map <silent> <leader><cr> :nohlsearch<cr>
36
37" Quick move in a line
38noremap <C-h> 30h
39noremap <C-l> 30l
40
41" Paste register 0
42nnoremap <C-p> "0p
43
44" Fast saving
45nmap <leader>w :w!<cr>
46
47" Fast quit with error
48nmap <leader>cq :cc<cr>
49
50" Switch wrap
51nmap <leader>W :set wrap!<cr>
52
53" :W sudo saves the file
54" (useful for handling the permission-denied error)
55command! W execute 'w !sudo -S tee %' <bar> edit!
56
57" New tab like browser
58nmap <C-t>n :tabnew<CR>
59nmap <C-t>c :tabclose<CR>
60nmap <C-t>m :tabmove
61nmap <C-t>o :tabonly
62
63" Enter to open file
64nnoremap <CR> gf
65nnoremap gF :e <cfile><CR>
66augroup vimrc_CRfix
67 au!
68 " Quickfix, Location list, &c. remap <CR> to work as expected
69 autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
70 autocmd CmdwinEnter * nnoremap <buffer> <CR> <CR>
71 autocmd CmdwinEnter * nnoremap <buffer> <C-c> <C-c>
72augroup END
73
74" Open terminal
75nnoremap <leader>, :.terminal ++noclose<CR>
76vnoremap <leader>, :terminal<CR>
77
78" Toggle paste mode on and off
79map <leader>pp :setlocal paste!<cr>
80
81" Switch CWD to the directory of the open buffer
82map <leader>cd :cd %:p:h<cr>:pwd<cr>
83
84" Move one line up and down
85nnoremap <C-j> ddp
86nnoremap <C-k> ddkP
87
88" In case ALT key is not working
89" execute "set <M-1>=\e1"
90" execute "set <M-2>=\e2"
91" execute "set <M-3>=\e3"
92" execute "set <M-4>=\e4"
93" execute "set <M-5>=\e5"
94" execute "set <M-6>=\e6"
95" execute "set <M-7>=\e7"
96" execute "set <M-8>=\e8"
97" execute "set <M-9>=\e9"
98" execute "set <M-0>=\e0"
99" execute "set <M-f>=\ef"
100" execute "set <M-b>=\eb"
101" execute "set <M-d>=\ed"
102" execute "set <M-l>=\el"
103" execute "set <M-h>=\eh"
104
105" Copy from system clipboard
106nnoremap <leader>P :r !xsel -ob<CR>
107vnoremap Y :w !xsel -ib<CR>
108
109" Spell
110nnoremap <leader>ts :set spell!<CR>
111nnoremap <leader>ss ]s
112nnoremap <leader>S [s
113
114" Show full path by default
115nnoremap <C-g> 1<C-g>
116
117" Translate by Google API
118vnoremap Tz :!trans -t zh-TW -b<CR>
119vnoremap Te :!trans -t en-US -b<CR>
120
121" source .vimrc
122nnoremap <leader>so V:so<CR>
123nnoremap <leader><leader>so :source ~/.vimrc<CR>
124vnoremap so :source<CR>
125
126
127"----------------------------------------------------------------------
128" => Fast editing and reloading of vimrc configs
129"----------------------------------------------------------------------
130nnoremap <leader>e :edit $MYVIMRC<CR>
131autocmd! bufwritepost $MYVIMRC source $MYVIMRC
132
133
134"----------------------------------------------------------------------
135" MOVING_WITH_READLINE
136"----------------------------------------------------------------------
137inoremap <C-f> <Right>
138inoremap <C-b> <Left>
139inoremap <C-a> <C-o>0
140inoremap <C-e> <C-o>$
141inoremap <M-f> <S-Right>
142inoremap <M-b> <S-Left>
143inoremap <C-d> <del>
144inoremap <C-h> <BackSpace>
145inoremap <C-j> <Down>
146inoremap <C-k> <Up>
147
148set cedit=<C-x>
149cnoremap <C-f> <Right>
150cnoremap <C-b> <Left>
151cnoremap <C-a> <Home>
152cnoremap <C-e> <End>
153cnoremap <M-f> <S-Right>
154cnoremap <M-b> <S-Left>
155cnoremap <C-d> <Del>
156cnoremap <C-r> <C-d>
157cnoremap <C-h> <BackSpace>
158cnoremap <C-n> <Down>
159cnoremap <C-p> <Up>
160cnoremap <C-k> <C-x>d$<C-c>
161cnoremap <M-d> <C-x>de<C-c>
162
163" Moving with wrap
164noremap <m-j> gj
165noremap <m-k> gk
166inoremap <m-j> <c-\><c-o>gj
167inoremap <m-k> <c-\><c-o>gk
168
169
170"----------------------------------------------------------------------
171" JUMP_TO_TABS_WITH_ALT
172"----------------------------------------------------------------------
173noremap <silent><A-1> :tabn 1<CR>
174noremap <silent><A-2> :tabn 2<CR>
175noremap <silent><M-3> :tabn 3<CR>
176noremap <silent><M-4> :tabn 4<CR>
177noremap <silent><M-5> :tabn 5<CR>
178noremap <silent><M-6> :tabn 6<CR>
179noremap <silent><M-7> :tabn 7<CR>
180noremap <silent><M-8> :tabn 8<CR>
181noremap <silent><M-9> :tablast<CR>
182inoremap <silent><A-1> <Esc>:tabn 1<CR>
183inoremap <silent><A-2> <Esc>:tabn 2<CR>
184inoremap <silent><M-3> <Esc>:tabn 3<CR>
185inoremap <silent><M-4> <Esc>:tabn 4<CR>
186inoremap <silent><M-5> <Esc>:tabn 5<CR>
187inoremap <silent><M-6> <Esc>:tabn 6<CR>
188inoremap <silent><M-7> <Esc>:tabn 7<CR>
189inoremap <silent><M-8> <Esc>:tabn 8<CR>
190inoremap <silent><M-9> <Esc>:tablast<CR>
191
192
193"----------------------------------------------------------------------
194" MANAGE_TABS
195"----------------------------------------------------------------------
196
197" Useful mappings for managing tabs
198map <leader>tn :tabnew<CR>
199map <leader>to :tabonly<CR>
200map <leader>tc :tabclose<CR>
201map <leader>tm :tabmove<SPACE>
202noremap <silent><m-h> :call Tab_MoveLeft()<cr>
203noremap <silent><m-l> :call Tab_MoveRight()<cr>
204
205" Let <leader>tl toggle between this and the last accessed tab
206let g:lasttab = 1
207nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
208autocmd TabLeave * let g:lasttab = tabpagenr()
209
210" Opens a new tab with the current buffer's path
211" Super useful when editing files in the same directory
212map <leader>te :tabedit <C-r>=expand("%:p:h")<cr>/
213
214" Tab move functions
215function! Tab_MoveLeft()
216 let l:tabnr = tabpagenr() - 2
217 if l:tabnr >= 0
218 exec 'tabmove '.l:tabnr
219 endif
220endfunc
221function! Tab_MoveRight()
222 let l:tabnr = tabpagenr() + 1
223 if l:tabnr <= tabpagenr('$')
224 exec 'tabmove '.l:tabnr
225 endif
226endfunc
227
228
229"----------------------------------------------------------------------
230" MANAGE_BUFFERS
231"----------------------------------------------------------------------
232
233" Open a new buffer
234nmap <leader>O :e /tmp/buffer<CR>
235
236" Next buffer
237noremap <leader>l :bn<CR>
238
239" Let <leader>l toggle between this and the last accessed buffer
240let g:lastbuffer = 1
241noremap <Tab> :exe "buffer ".g:lastbuffer<CR>
242au BufLeave * let g:lastbuffer = bufnr()
243
244"----------------------------------------------------------------------
245" SURROURD_WITH_CHAR
246"----------------------------------------------------------------------
247vnoremap S sa
248vnoremap ' <ESC>`<i'<ESC>`>la'<ESC>
249vnoremap q <ESC>`<i"<ESC>`>la"<ESC>
250vnoremap ( <ESC>`<i(<ESC>`>la)<ESC>
251vnoremap [ <ESC>`<i[<ESC>`>la]<ESC>
252vnoremap { <ESC>`<i{<ESC>`>la}<ESC>
253vnoremap ` <ESC>`<i`<ESC>`>la`<ESC>
254vnoremap <space> <ESC>`<i<space><ESC>`>la<space><ESC>
255vnoremap z <ESC>`<i「<ESC>`>la」<ESC>
256
257
258"----------------------------------------------------------------------
259" REDIRECTION_WITH_BUFFER
260"----------------------------------------------------------------------
261" Usage:
262" :Redir hi ............. show the full output of command ':hi' in a scratch window
263" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window
264"
265function! Redir(cmd)
266 for win in range(1, winnr('$'))
267 if getwinvar(win, 'scratch')
268 execute win . 'windo close'
269 endif
270 endfor
271 if a:cmd =~ '^!'
272 let output = system(matchstr(a:cmd, '^!\zs.*'))
273 else
274 redir => output
275 execute a:cmd
276 redir END
277 endif
278 vnew
279 let w:scratch = 1
280 setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
281 call setline(1, split(output, "\n"))
282endfunction
283
284command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
285nnoremap <leader>rr :Redir
286
287"----------------------------------------------------------------------
288" Markdown items (temproray solution)
289"----------------------------------------------------------------------
290
291" Toggle list item in markdown: "- [ ] XXX" -> "XXX" -> "- XXX" -> "- [ ] XXX"
292autocmd FileType markdown nnoremap <buffer> <leader>i V:!sed -E '/^ *- \[.\]/ { s/^( *)- \[.\] */\1/; q; }; /^ *[^[:space:]-]/ { s/^( *)/\1- /; q; }; /^ *- / { s/^( *)- /\1- [ ] /; q; }'<CR><CR>
293autocmd FileType markdown nnoremap <buffer> <leader>I V:!sed -E 's/^( *)/\1- [ ] /'<CR><CR>
294
295" Toggle task status: "- [ ] " -> "- [x]" -> "- [.] " -> "- [ ] "
296nnoremap <leader>x V:!sed -E '/^ *- \[ \]/ { s/^( *)- \[ \]/\1- [x]/; q; }; /^ *- \[\x\]/ { s/^( *)- \[\x\]/\1- [.]/; q; }; /^ *- \[\.\]/ { s/^( *)- \[\.\]/\1- [ ]/; q; }'<CR><CR>
297
298
299"----------------------------------------------------------------------
300" Common command
301"----------------------------------------------------------------------
302" Show date selector
303nnoremap <leader>dd :r !sh -c 'LANG=en zenity --calendar --date-format="\%Y.\%m.\%d" 2>/dev/null'<CR><CR>
304nnoremap <leader>dD :r !sh -c 'LANG=en zenity --calendar --date-format="\%a \%b \%d" 2>/dev/null'<CR><CR>
305nnoremap <leader>dt :r !date +\%H:\%m<CR>A
306
307
308"----------------------------------------------------------------------
309" 窗口切换:ALT+SHIFT+hjkl
310" 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在
311" bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的
312"----------------------------------------------------------------------
313noremap <m-H> <c-w>h
314noremap <m-L> <c-w>l
315noremap <m-J> <c-w>j
316noremap <m-K> <c-w>k
317inoremap <m-H> <esc><c-w>h
318inoremap <m-L> <esc><c-w>l
319inoremap <m-J> <esc><c-w>j
320inoremap <m-K> <esc><c-w>k
321
322if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1')
323 " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式
324 " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+?
325 " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改
326 set termwinkey=<c-_>
327 tnoremap <m-H> <c-_>h
328 tnoremap <m-L> <c-_>l
329 tnoremap <m-J> <c-_>j
330 tnoremap <m-K> <c-_>k
331 tnoremap <m-q> <c-\><c-n>
332elseif has('nvim')
333 " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式
334 tnoremap <m-H> <c-\><c-n><c-w>h
335 tnoremap <m-L> <c-\><c-n><c-w>l
336 tnoremap <m-J> <c-\><c-n><c-w>j
337 tnoremap <m-K> <c-\><c-n><c-w>k
338 tnoremap <m-q> <c-\><c-n>
339endif
340
341
342
343"----------------------------------------------------------------------
344" 编译运行 C/C++ 项目
345" 详细见:http://www.skywind.me/blog/archives/2084
346"----------------------------------------------------------------------
347
348" 自动打开 quickfix window ,高度为 6
349let g:asyncrun_open = 6
350
351" 任务结束时候响铃提醒
352let g:asyncrun_bell = 1
353
354" 设置 F10 打开/关闭 Quickfix 窗口
355nnoremap <F10> :call asyncrun#quickfix_toggle(6)<cr>
356
357" F9 编译 C/C++ 文件
358nnoremap <silent> <F9> :AsyncRun gcc -Wall -O2 "$(VIM_FILEPATH)" -o "$(VIM_FILEDIR)/$(VIM_FILENOEXT)" <cr>
359
360" F5 运行文件
361nnoremap <silent> <F5> :call ExecuteFile()<cr>
362
363" F7 编译项目
364nnoremap <silent> <F7> :AsyncRun -cwd=<root> make <cr>
365
366" F8 运行项目
367nnoremap <silent> <F8> :AsyncRun -cwd=<root> -raw make run <cr>
368
369" F6 测试项目
370nnoremap <silent> <F6> :AsyncRun -cwd=<root> -raw make test <cr>
371
372" 更新 cmake
373nnoremap <silent> <F4> :AsyncRun -cwd=<root> cmake . <cr>
374
375" Windows 下支持直接打开新 cmd 窗口运行
376if has('win32') || has('win64')
377 nnoremap <silent> <F8> :AsyncRun -cwd=<root> -mode=4 make run <cr>
378endif
379
380
381"----------------------------------------------------------------------
382" F5 运行当前文件:根据文件类型判断方法,并且输出到 quickfix 窗口
383"----------------------------------------------------------------------
384function! ExecuteFile()
385 let cmd = ''
386 if index(['c', 'cpp', 'rs', 'go'], &ft) >= 0
387 " native 语言,把当前文件名去掉扩展名后作为可执行运行
388 " 写全路径名是因为后面 -cwd=? 会改变运行时的当前路径,所以写全路径
389 " 加双引号是为了避免路径中包含空格
390 let cmd = '"$(VIM_FILEDIR)/$(VIM_FILENOEXT)"'
391 elseif &ft == 'python'
392 let $PYTHONUNBUFFERED=1 " 关闭 python 缓存,实时看到输出
393 let cmd = 'python "$(VIM_FILEPATH)"'
394 elseif &ft == 'javascript'
395 let cmd = 'node "$(VIM_FILEPATH)"'
396 elseif &ft == 'perl'
397 let cmd = 'perl "$(VIM_FILEPATH)"'
398 elseif &ft == 'ruby'
399 let cmd = 'ruby "$(VIM_FILEPATH)"'
400 elseif &ft == 'php'
401 let cmd = 'php "$(VIM_FILEPATH)"'
402 elseif &ft == 'lua'
403 let cmd = 'lua "$(VIM_FILEPATH)"'
404 elseif &ft == 'zsh'
405 let cmd = 'zsh "$(VIM_FILEPATH)"'
406 elseif &ft == 'ps1'
407 let cmd = 'powershell -file "$(VIM_FILEPATH)"'
408 elseif &ft == 'vbs'
409 let cmd = 'cscript -nologo "$(VIM_FILEPATH)"'
410 elseif &ft == 'sh'
411 let cmd = 'bash "$(VIM_FILEPATH)"'
412 else
413 return
414 endif
415 " Windows 下打开新的窗口 (-mode=4) 运行程序,其他系统在 quickfix 运行
416 " -raw: 输出内容直接显示到 quickfix window 不匹配 errorformat
417 " -save=2: 保存所有改动过的文件
418 " -cwd=$(VIM_FILEDIR): 运行初始化目录为文件所在目录
419 if has('win32') || has('win64')
420 exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=4 '. cmd
421 else
422 exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=0 '. cmd
423 endif
424endfunc
425
426
427
428"----------------------------------------------------------------------
429" F2 在项目目录下 Grep 光标下单词,默认 C/C++/Py/Js ,扩展名自己扩充
430" 支持 rg/grep/findstr ,其他类型可以自己扩充
431" 不是在当前目录 grep,而是会去到当前文件所属的项目目录 project root
432" 下面进行 grep,这样能方便的对相关项目进行搜索
433"----------------------------------------------------------------------
434if executable('rg')
435 noremap <silent><F2> :AsyncRun! -cwd=<root> rg -n --no-heading
436 \ --color never -g *.h -g *.c* -g *.py -g *.js -g *.vim
437 \ <C-R><C-W> "<root>" <cr>
438elseif has('win32') || has('win64')
439 noremap <silent><F2> :AsyncRun! -cwd=<root> findstr /n /s /C:"<C-R><C-W>"
440 \ "\%CD\%\*.h" "\%CD\%\*.c*" "\%CD\%\*.py" "\%CD\%\*.js"
441 \ "\%CD\%\*.vim"
442 \ <cr>
443else
444 noremap <silent><F2> :AsyncRun! -cwd=<root> grep -n -s -R <C-R><C-W>
445 \ --include='*.h' --include='*.c*' --include='*.py'
446 \ --include='*.js' --include='*.vim'
447 \ '<root>' <cr>
448endif
diff --git a/vim/init/plugins.vim b/vim/init/plugins.vim
new file mode 100644
index 0000000..5b05c8e
--- /dev/null
+++ b/vim/init/plugins.vim
@@ -0,0 +1,719 @@
1"======================================================================
2"
3" init-plugins.vim
4"
5" Created by skywind on 2018/05/31
6" Last Modified: 2018/06/10 23:11
7"
8"======================================================================
9" vim: set ts=4 sw=4 tw=78 noet :
10
11call plug#begin('~/.vim/plugged')
12
13""""""""""""""""""""""""""""""
14" => Set statusline
15""""""""""""""""""""""""""""""
16Plug 'itchyny/lightline.vim'
17let g:lightline = { 'colorscheme': 'wombat' }
18
19""""""""""""""""""""""""""""""
20" => MRU plugin
21""""""""""""""""""""""""""""""
22Plug 'yegappan/mru'
23let MRU_Max_Entries = 400
24nnoremap <leader>f :MRU<CR>
25
26""""""""""""""""""""""""""""""
27" => Goyo for focus
28""""""""""""""""""""""""""""""
29Plug 'junegunn/goyo.vim'
30nnoremap <silent> <leader>z :Goyo<CR>
31
32let g:goyo_width = 80
33let g:goyo_height = "85%"
34let g:goyo_linenr = 0
35
36
37function! s:goyo_enter()
38 let b:quitting = 0
39 let b:quitting_bang = 0
40 autocmd QuitPre <buffer> let b:quitting = 1
41 cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
42endfunction
43
44function! s:goyo_leave()
45 " Quit Vim if this is the only remaining buffer
46 if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
47 if b:quitting_bang
48 qa!
49 else
50 qa
51 endif
52 endif
53endfunction
54
55autocmd! User GoyoEnter call <SID>goyo_enter()
56autocmd! User GoyoLeave call <SID>goyo_leave()
57
58
59""""""""""""""""""""""""""""""
60" => bufExplorer plugin
61""""""""""""""""""""""""""""""
62Plug 'jlanzarotta/bufexplorer'
63let g:bufExplorerDefaultHelp=0
64let g:bufExplorerShowRelativePath=1
65let g:bufExplorerFindActive=1
66let g:bufExplorerSortBy='name'
67map <leader>q ::BufExplorer<CR>
68map <leader>Q ::BufExplorerVerticalSplit<CR>
69
70
71""""""""""""""""""""""""""""""
72" => Auto set tabline (tal)
73""""""""""""""""""""""""""""""
74Plug 'webdevel/tabulous'
75
76
77"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
78" => Nerd Tree
79"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
80Plug 'preservim/nerdtree'
81let g:NERDTreeWinPos = "left"
82let NERDTreeShowHidden=0
83let NERDTreeQuitOnOpen=1
84let NERDTreeIgnore = ['\.pyc$', '__pycache__']
85let g:NERDTreeWinSize=35
86map <C-n> :NERDTreeToggle<cr>
87map <leader>nb :NERDTreeFromBookmark<Space>
88map <leader>nf :NERDTreeFind<cr>
89
90"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
91" => vim-surrounded
92"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
93Plug 'tpope/vim-surround'
94vmap [ S[
95
96
97"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
98" => Markdown
99"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
100Plug 'godlygeek/tabular'
101Plug 'preservim/vim-markdown'
102
103
104"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
105" => ALE (Asynchronous Lint Engine)
106"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
107Plug 'dense-analysis/ale'
108let g:ale_sign_column_always = 1
109let g:ale_sign_error = '>>'
110let g:ale_sign_warning = '--'
111
112" show errors or warnings in my statusline
113let g:airline#extensions#ale#enabled = 1
114
115" use quickfix list instead of the loclist
116let g:ale_set_loclist = 0
117let g:ale_set_quickfix = 1
118
119
120""----------------------------------------------------------------------
121"" 默认情况下的分组,可以再前面覆盖之
122""----------------------------------------------------------------------
123"if !exists('g:bundle_group')
124" let g:bundle_group = ['basic', 'tags', 'enhanced', 'filetypes', 'textobj']
125" let g:bundle_group += ['tags', 'airline', 'nerdtree', 'ale', 'echodoc']
126" let g:bundle_group += ['leaderf']
127"endif
128"
129"
130""----------------------------------------------------------------------
131"" 计算当前 vim-init 的子路径
132""----------------------------------------------------------------------
133"let s:home = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
134"
135"function! s:path(path)
136" let path = expand(s:home . '/' . a:path )
137" return substitute(path, '\\', '/', 'g')
138"endfunc
139"
140"
141""----------------------------------------------------------------------
142"" 在 ~/.vim/bundles 下安装插件
143""----------------------------------------------------------------------
144"call plug#begin(get(g:, 'bundle_home', '~/.vim/bundles'))
145"
146"
147""----------------------------------------------------------------------
148"" 默认插件
149""----------------------------------------------------------------------
150"
151"" 全文快速移动,<leader><leader>f{char} 即可触发
152"Plug 'easymotion/vim-easymotion'
153"
154"" 文件浏览器,代替 netrw
155"Plug 'justinmk/vim-dirvish'
156"
157"" 表格对齐,使用命令 Tabularize
158"Plug 'godlygeek/tabular', { 'on': 'Tabularize' }
159"
160"" Diff 增强,支持 histogram / patience 等更科学的 diff 算法
161"Plug 'chrisbra/vim-diff-enhanced'
162"
163"
164""----------------------------------------------------------------------
165"" Dirvish 设置:自动排序并隐藏文件,同时定位到相关文件
166"" 这个排序函数可以将目录排在前面,文件排在后面,并且按照字母顺序排序
167"" 比默认的纯按照字母排序更友好点。
168""----------------------------------------------------------------------
169"function! s:setup_dirvish()
170" if &buftype != 'nofile' && &filetype != 'dirvish'
171" return
172" endif
173" if has('nvim')
174" return
175" endif
176" " 取得光标所在行的文本(当前选中的文件名)
177" let text = getline('.')
178" if ! get(g:, 'dirvish_hide_visible', 0)
179" exec 'silent keeppatterns g@\v[\/]\.[^\/]+[\/]?$@d _'
180" endif
181" " 排序文件名
182" exec 'sort ,^.*[\/],'
183" let name = '^' . escape(text, '.*[]~\') . '[/*|@=|\\*]\=\%($\|\s\+\)'
184" " 定位到之前光标处的文件
185" call search(name, 'wc')
186" noremap <silent><buffer> ~ :Dirvish ~<cr>
187" noremap <buffer> % :e %
188"endfunc
189"
190"augroup MyPluginSetup
191" autocmd!
192" autocmd FileType dirvish call s:setup_dirvish()
193"augroup END
194"
195"
196""----------------------------------------------------------------------
197"" 基础插件
198""----------------------------------------------------------------------
199"if index(g:bundle_group, 'basic') >= 0
200"
201" " 展示开始画面,显示最近编辑过的文件
202" Plug 'mhinz/vim-startify'
203"
204" " 一次性安装一大堆 colorscheme
205" Plug 'flazz/vim-colorschemes'
206"
207" " 支持库,给其他插件用的函数库
208" Plug 'xolox/vim-misc'
209"
210" " 用于在侧边符号栏显示 marks (ma-mz 记录的位置)
211" Plug 'kshenoy/vim-signature'
212"
213" " 用于在侧边符号栏显示 git/svn 的 diff
214" Plug 'mhinz/vim-signify'
215"
216" " 根据 quickfix 中匹配到的错误信息,高亮对应文件的错误行
217" " 使用 :RemoveErrorMarkers 命令或者 <space>ha 清除错误
218" Plug 'mh21/errormarker.vim'
219"
220" " 使用 ALT+e 会在不同窗口/标签上显示 A/B/C 等编号,然后字母直接跳转
221" Plug 't9md/vim-choosewin'
222"
223" " 提供基于 TAGS 的定义预览,函数参数预览,quickfix 预览
224" Plug 'skywind3000/vim-preview'
225"
226" " Git 支持
227" Plug 'tpope/vim-fugitive'
228"
229" " 使用 ALT+E 来选择窗口
230" nmap <m-e> <Plug>(choosewin)
231"
232" " 默认不显示 startify
233" let g:startify_disable_at_vimenter = 1
234" let g:startify_session_dir = '~/.vim/session'
235"
236" " 使用 <space>ha 清除 errormarker 标注的错误
237" noremap <silent><space>ha :RemoveErrorMarkers<cr>
238"
239" " signify 调优
240" let g:signify_vcs_list = ['git', 'svn']
241" let g:signify_sign_add = '+'
242" let g:signify_sign_delete = '_'
243" let g:signify_sign_delete_first_line = '‾'
244" let g:signify_sign_change = '~'
245" let g:signify_sign_changedelete = g:signify_sign_change
246"
247" " git 仓库使用 histogram 算法进行 diff
248" let g:signify_vcs_cmds = {
249" \ 'git': 'git diff --no-color --diff-algorithm=histogram --no-ext-diff -U0 -- %f',
250" \}
251"endif
252"
253"
254""----------------------------------------------------------------------
255"" 增强插件
256""----------------------------------------------------------------------
257"if index(g:bundle_group, 'enhanced') >= 0
258"
259" " 用 v 选中一个区域后,ALT_+/- 按分隔符扩大/缩小选区
260" Plug 'terryma/vim-expand-region'
261"
262" " 快速文件搜索
263" Plug 'junegunn/fzf'
264"
265" " 给不同语言提供字典补全,插入模式下 c-x c-k 触发
266" Plug 'asins/vim-dict'
267"
268" " 使用 :FlyGrep 命令进行实时 grep
269" Plug 'wsdjeg/FlyGrep.vim'
270"
271" " 使用 :CtrlSF 命令进行模仿 sublime 的 grep
272" Plug 'dyng/ctrlsf.vim'
273"
274" " 配对括号和引号自动补全
275" Plug 'Raimondi/delimitMate'
276"
277" " 提供 gist 接口
278" Plug 'lambdalisue/vim-gista', { 'on': 'Gista' }
279"
280" " ALT_+/- 用于按分隔符扩大缩小 v 选区
281" map <m-=> <Plug>(expand_region_expand)
282" map <m--> <Plug>(expand_region_shrink)
283"endif
284"
285"
286""----------------------------------------------------------------------
287"" 自动生成 ctags/gtags,并提供自动索引功能
288"" 不在 git/svn 内的项目,需要在项目根目录 touch 一个空的 .root 文件
289"" See https://zhuanlan.zhihu.com/p/36279445
290""----------------------------------------------------------------------
291"if index(g:bundle_group, 'tags') >= 0
292"
293" " 提供 ctags/gtags 后台数据库自动更新功能
294" Plug 'ludovicchabant/vim-gutentags'
295"
296" " 提供 GscopeFind 命令并自动处理好 gtags 数据库切换
297" " 支持光标移动到符号名上:<leader>cg 查看定义,<leader>cs 查看引用
298" Plug 'skywind3000/gutentags_plus'
299"
300" " 设定项目目录标志:除了 .git/.svn 外,还有 .root 文件
301" let g:gutentags_project_root = ['.root']
302" let g:gutentags_ctags_tagfile = '.tags'
303"
304" " 默认生成的数据文件集中到 ~/.cache/tags 避免污染项目目录,好清理
305" let g:gutentags_cache_dir = expand('~/.cache/tags')
306"
307" " 默认禁用自动生成
308" let g:gutentags_modules = []
309"
310" " 如果有 ctags 可执行就允许动态生成 ctags 文件
311" if executable('ctags')
312" let g:gutentags_modules += ['ctags']
313" endif
314"
315" " 如果有 gtags 可执行就允许动态生成 gtags 数据库
316" if executable('gtags') && executable('gtags-cscope')
317" let g:gutentags_modules += ['gtags_cscope']
318" endif
319"
320" " 设置 ctags 的参数
321" let g:gutentags_ctags_extra_args = []
322" let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
323" let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
324" let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
325"
326" " 使用 universal-ctags 的话需要下面这行,请反注释
327" " let g:gutentags_ctags_extra_args += ['--output-format=e-ctags']
328"
329" " 禁止 gutentags 自动链接 gtags 数据库
330" let g:gutentags_auto_add_gtags_cscope = 0
331"endif
332"
333"
334""----------------------------------------------------------------------
335"" 文本对象:textobj 全家桶
336""----------------------------------------------------------------------
337"if index(g:bundle_group, 'textobj') >= 0
338"
339" " 基础插件:提供让用户方便的自定义文本对象的接口
340" Plug 'kana/vim-textobj-user'
341"
342" " indent 文本对象:ii/ai 表示当前缩进,vii 选中当缩进,cii 改写缩进
343" Plug 'kana/vim-textobj-indent'
344"
345" " 语法文本对象:iy/ay 基于语法的文本对象
346" Plug 'kana/vim-textobj-syntax'
347"
348" " 函数文本对象:if/af 支持 c/c++/vim/java
349" Plug 'kana/vim-textobj-function', { 'for':['c', 'cpp', 'vim', 'java'] }
350"
351" " 参数文本对象:i,/a, 包括参数或者列表元素
352" Plug 'sgur/vim-textobj-parameter'
353"
354" " 提供 python 相关文本对象,if/af 表示函数,ic/ac 表示类
355" Plug 'bps/vim-textobj-python', {'for': 'python'}
356"
357" " 提供 uri/url 的文本对象,iu/au 表示
358" Plug 'jceb/vim-textobj-uri'
359"endif
360"
361"
362""----------------------------------------------------------------------
363"" 文件类型扩展
364""----------------------------------------------------------------------
365"if index(g:bundle_group, 'filetypes') >= 0
366"
367" " powershell 脚本文件的语法高亮
368" Plug 'pprovost/vim-ps1', { 'for': 'ps1' }
369"
370" " lua 语法高亮增强
371" Plug 'tbastos/vim-lua', { 'for': 'lua' }
372"
373" " C++ 语法高亮增强,支持 11/14/17 标准
374" Plug 'octol/vim-cpp-enhanced-highlight', { 'for': ['c', 'cpp'] }
375"
376" " 额外语法文件
377" Plug 'justinmk/vim-syntax-extra', { 'for': ['c', 'bison', 'flex', 'cpp'] }
378"
379" " python 语法文件增强
380" Plug 'vim-python/python-syntax', { 'for': ['python'] }
381"
382" " rust 语法增强
383" Plug 'rust-lang/rust.vim', { 'for': 'rust' }
384"
385" " vim org-mode
386" Plug 'jceb/vim-orgmode', { 'for': 'org' }
387"endif
388"
389"
390""----------------------------------------------------------------------
391"" airline
392""----------------------------------------------------------------------
393"if index(g:bundle_group, 'airline') >= 0
394" Plug 'vim-airline/vim-airline'
395" Plug 'vim-airline/vim-airline-themes'
396" let g:airline_left_sep = ''
397" let g:airline_left_alt_sep = ''
398" let g:airline_right_sep = ''
399" let g:airline_right_alt_sep = ''
400" let g:airline_powerline_fonts = 0
401" let g:airline_exclude_preview = 1
402" let g:airline_section_b = '%n'
403" let g:airline_theme='deus'
404" let g:airline#extensions#branch#enabled = 0
405" let g:airline#extensions#syntastic#enabled = 0
406" let g:airline#extensions#fugitiveline#enabled = 0
407" let g:airline#extensions#csv#enabled = 0
408" let g:airline#extensions#vimagit#enabled = 0
409"endif
410"
411"
412""----------------------------------------------------------------------
413"" NERDTree
414""----------------------------------------------------------------------
415"if index(g:bundle_group, 'nerdtree') >= 0
416" Plug 'scrooloose/nerdtree', {'on': ['NERDTree', 'NERDTreeFocus', 'NERDTreeToggle', 'NERDTreeCWD', 'NERDTreeFind'] }
417" Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
418" let g:NERDTreeMinimalUI = 1
419" let g:NERDTreeDirArrows = 1
420" let g:NERDTreeHijackNetrw = 0
421" noremap <space>nn :NERDTree<cr>
422" noremap <space>no :NERDTreeFocus<cr>
423" noremap <space>nm :NERDTreeMirror<cr>
424" noremap <space>nt :NERDTreeToggle<cr>
425"endif
426"
427"
428""----------------------------------------------------------------------
429"" LanguageTool 语法检查
430""----------------------------------------------------------------------
431"if index(g:bundle_group, 'grammer') >= 0
432" Plug 'rhysd/vim-grammarous'
433" noremap <space>rg :GrammarousCheck --lang=en-US --no-move-to-first-error --no-preview<cr>
434" map <space>rr <Plug>(grammarous-open-info-window)
435" map <space>rv <Plug>(grammarous-move-to-info-window)
436" map <space>rs <Plug>(grammarous-reset)
437" map <space>rx <Plug>(grammarous-close-info-window)
438" map <space>rm <Plug>(grammarous-remove-error)
439" map <space>rd <Plug>(grammarous-disable-rule)
440" map <space>rn <Plug>(grammarous-move-to-next-error)
441" map <space>rp <Plug>(grammarous-move-to-previous-error)
442"endif
443"
444"
445""----------------------------------------------------------------------
446"" ale:动态语法检查
447""----------------------------------------------------------------------
448"if index(g:bundle_group, 'ale') >= 0
449" Plug 'w0rp/ale'
450"
451" " 设定延迟和提示信息
452" let g:ale_completion_delay = 500
453" let g:ale_echo_delay = 20
454" let g:ale_lint_delay = 500
455" let g:ale_echo_msg_format = '[%linter%] %code: %%s'
456"
457" " 设定检测的时机:normal 模式文字改变,或者离开 insert模式
458" " 禁用默认 INSERT 模式下改变文字也触发的设置,太频繁外,还会让补全窗闪烁
459" let g:ale_lint_on_text_changed = 'normal'
460" let g:ale_lint_on_insert_leave = 1
461"
462" " 在 linux/mac 下降低语法检查程序的进程优先级(不要卡到前台进程)
463" if has('win32') == 0 && has('win64') == 0 && has('win32unix') == 0
464" let g:ale_command_wrapper = 'nice -n5'
465" endif
466"
467" " 允许 airline 集成
468" let g:airline#extensions#ale#enabled = 1
469"
470" " 编辑不同文件类型需要的语法检查器
471" let g:ale_linters = {
472" \ 'c': ['gcc', 'cppcheck'],
473" \ 'cpp': ['gcc', 'cppcheck'],
474" \ 'python': ['flake8', 'pylint'],
475" \ 'lua': ['luac'],
476" \ 'go': ['go build', 'gofmt'],
477" \ 'java': ['javac'],
478" \ 'javascript': ['eslint'],
479" \ }
480"
481"
482" " 获取 pylint, flake8 的配置文件,在 vim-init/tools/conf 下面
483" function s:lintcfg(name)
484" let conf = s:path('tools/conf/')
485" let path1 = conf . a:name
486" let path2 = expand('~/.vim/linter/'. a:name)
487" if filereadable(path2)
488" return path2
489" endif
490" return shellescape(filereadable(path2)? path2 : path1)
491" endfunc
492"
493" " 设置 flake8/pylint 的参数
494" let g:ale_python_flake8_options = '--conf='.s:lintcfg('flake8.conf')
495" let g:ale_python_pylint_options = '--rcfile='.s:lintcfg('pylint.conf')
496" let g:ale_python_pylint_options .= ' --disable=W'
497" let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
498" let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14'
499" let g:ale_c_cppcheck_options = ''
500" let g:ale_cpp_cppcheck_options = ''
501"
502" let g:ale_linters.text = ['textlint', 'write-good', 'languagetool']
503"
504" " 如果没有 gcc 只有 clang 时(FreeBSD)
505" if executable('gcc') == 0 && executable('clang')
506" let g:ale_linters.c += ['clang']
507" let g:ale_linters.cpp += ['clang']
508" endif
509"endif
510"
511"
512""----------------------------------------------------------------------
513"" echodoc:搭配 YCM/deoplete 在底部显示函数参数
514""----------------------------------------------------------------------
515"if index(g:bundle_group, 'echodoc') >= 0
516" Plug 'Shougo/echodoc.vim'
517" set noshowmode
518" let g:echodoc#enable_at_startup = 1
519"endif
520"
521"
522""----------------------------------------------------------------------
523"" LeaderF:CtrlP / FZF 的超级代替者,文件模糊匹配,tags/函数名 选择
524""----------------------------------------------------------------------
525"if index(g:bundle_group, 'leaderf') >= 0
526" " 如果 vim 支持 python 则启用 Leaderf
527" if has('python') || has('python3')
528" Plug 'Yggdroot/LeaderF'
529"
530" " CTRL+p 打开文件模糊匹配
531" let g:Lf_ShortcutF = '<c-p>'
532"
533" " ALT+n 打开 buffer 模糊匹配
534" let g:Lf_ShortcutB = '<m-n>'
535"
536" " CTRL+n 打开最近使用的文件 MRU,进行模糊匹配
537" noremap <c-n> :LeaderfMru<cr>
538"
539" " ALT+p 打开函数列表,按 i 进入模糊匹配,ESC 退出
540" noremap <m-p> :LeaderfFunction!<cr>
541"
542" " ALT+SHIFT+p 打开 tag 列表,i 进入模糊匹配,ESC退出
543" noremap <m-P> :LeaderfBufTag!<cr>
544"
545" " ALT+n 打开 buffer 列表进行模糊匹配
546" noremap <m-n> :LeaderfBuffer<cr>
547"
548" " ALT+m 全局 tags 模糊匹配
549" noremap <m-m> :LeaderfTag<cr>
550"
551" " 最大历史文件保存 2048 个
552" let g:Lf_MruMaxFiles = 2048
553"
554" " ui 定制
555" let g:Lf_StlSeparator = { 'left': '', 'right': '', 'font': '' }
556"
557" " 如何识别项目目录,从当前文件目录向父目录递归知道碰到下面的文件/目录
558" let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git']
559" let g:Lf_WorkingDirectoryMode = 'Ac'
560" let g:Lf_WindowHeight = 0.30
561" let g:Lf_CacheDirectory = expand('~/.vim/cache')
562"
563" " 显示绝对路径
564" let g:Lf_ShowRelativePath = 0
565"
566" " 隐藏帮助
567" let g:Lf_HideHelp = 1
568"
569" " 模糊匹配忽略扩展名
570" let g:Lf_WildIgnore = {
571" \ 'dir': ['.svn','.git','.hg'],
572" \ 'file': ['*.sw?','~$*','*.bak','*.exe','*.o','*.so','*.py[co]']
573" \ }
574"
575" " MRU 文件忽略扩展名
576" let g:Lf_MruFileExclude = ['*.so', '*.exe', '*.py[co]', '*.sw?', '~$*', '*.bak', '*.tmp', '*.dll']
577" let g:Lf_StlColorscheme = 'powerline'
578"
579" " 禁用 function/buftag 的预览功能,可以手动用 p 预览
580" let g:Lf_PreviewResult = {'Function':0, 'BufTag':0}
581"
582" " 使用 ESC 键可以直接退出 leaderf 的 normal 模式
583" let g:Lf_NormalMap = {
584" \ "File": [["<ESC>", ':exec g:Lf_py "fileExplManager.quit()"<CR>']],
585" \ "Buffer": [["<ESC>", ':exec g:Lf_py "bufExplManager.quit()"<cr>']],
586" \ "Mru": [["<ESC>", ':exec g:Lf_py "mruExplManager.quit()"<cr>']],
587" \ "Tag": [["<ESC>", ':exec g:Lf_py "tagExplManager.quit()"<cr>']],
588" \ "BufTag": [["<ESC>", ':exec g:Lf_py "bufTagExplManager.quit()"<cr>']],
589" \ "Function": [["<ESC>", ':exec g:Lf_py "functionExplManager.quit()"<cr>']],
590" \ }
591"
592" else
593" " 不支持 python ,使用 CtrlP 代替
594" Plug 'ctrlpvim/ctrlp.vim'
595"
596" " 显示函数列表的扩展插件
597" Plug 'tacahiroy/ctrlp-funky'
598"
599" " 忽略默认键位
600" let g:ctrlp_map = ''
601"
602" " 模糊匹配忽略
603" let g:ctrlp_custom_ignore = {
604" \ 'dir': '\v[\/]\.(git|hg|svn)$',
605" \ 'file': '\v\.(exe|so|dll|mp3|wav|sdf|suo|mht)$',
606" \ 'link': 'some_bad_symbolic_links',
607" \ }
608"
609" " 项目标志
610" let g:ctrlp_root_markers = ['.project', '.root', '.svn', '.git']
611" let g:ctrlp_working_path = 0
612"
613" " CTRL+p 打开文件模糊匹配
614" noremap <c-p> :CtrlP<cr>
615"
616" " CTRL+n 打开最近访问过的文件的匹配
617" noremap <c-n> :CtrlPMRUFiles<cr>
618"
619" " ALT+p 显示当前文件的函数列表
620" noremap <m-p> :CtrlPFunky<cr>
621"
622" " ALT+n 匹配 buffer
623" noremap <m-n> :CtrlPBuffer<cr>
624" endif
625"endif
626"
627"
628""----------------------------------------------------------------------
629"" 结束插件安装
630""----------------------------------------------------------------------
631"call plug#end()
632"
633"
634"
635""----------------------------------------------------------------------
636"" YouCompleteMe 默认设置:YCM 需要你另外手动编译安装
637""----------------------------------------------------------------------
638"
639"" 禁用预览功能:扰乱视听
640"let g:ycm_add_preview_to_completeopt = 0
641"
642"" 禁用诊断功能:我们用前面更好用的 ALE 代替
643"let g:ycm_show_diagnostics_ui = 0
644"let g:ycm_server_log_level = 'info'
645"let g:ycm_min_num_identifier_candidate_chars = 2
646"let g:ycm_collect_identifiers_from_comments_and_strings = 1
647"let g:ycm_complete_in_strings=1
648"let g:ycm_key_invoke_completion = '<c-z>'
649"set completeopt=menu,menuone,noselect
650"
651"" noremap <c-z> <NOP>
652"
653"" 两个字符自动触发语义补全
654"let g:ycm_semantic_triggers = {
655" \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
656" \ 'cs,lua,javascript': ['re!\w{2}'],
657" \ }
658"
659"
660""----------------------------------------------------------------------
661"" Ycm 白名单(非名单内文件不启用 YCM),避免打开个 1MB 的 txt 分析半天
662""----------------------------------------------------------------------
663"let g:ycm_filetype_whitelist = {
664" \ "c":1,
665" \ "cpp":1,
666" \ "objc":1,
667" \ "objcpp":1,
668" \ "python":1,
669" \ "java":1,
670" \ "javascript":1,
671" \ "coffee":1,
672" \ "vim":1,
673" \ "go":1,
674" \ "cs":1,
675" \ "lua":1,
676" \ "perl":1,
677" \ "perl6":1,
678" \ "php":1,
679" \ "ruby":1,
680" \ "rust":1,
681" \ "erlang":1,
682" \ "asm":1,
683" \ "nasm":1,
684" \ "masm":1,
685" \ "tasm":1,
686" \ "asm68k":1,
687" \ "asmh8300":1,
688" \ "asciidoc":1,
689" \ "basic":1,
690" \ "vb":1,
691" \ "make":1,
692" \ "cmake":1,
693" \ "html":1,
694" \ "css":1,
695" \ "less":1,
696" \ "json":1,
697" \ "cson":1,
698" \ "typedscript":1,
699" \ "haskell":1,
700" \ "lhaskell":1,
701" \ "lisp":1,
702" \ "scheme":1,
703" \ "sdl":1,
704" \ "sh":1,
705" \ "zsh":1,
706" \ "bash":1,
707" \ "man":1,
708" \ "markdown":1,
709" \ "matlab":1,
710" \ "maxima":1,
711" \ "dosini":1,
712" \ "conf":1,
713" \ "config":1,
714" \ "zimbu":1,
715" \ "ps1":1,
716" \ }
717
718
719call plug#end()
diff --git a/vim/init/style.vim b/vim/init/style.vim
new file mode 100644
index 0000000..8d056b0
--- /dev/null
+++ b/vim/init/style.vim
@@ -0,0 +1,291 @@
1"======================================================================
2"
3" init-style.vim - 显示样式设置
4"
5" Created by skywind on 2018/05/30
6" Last Modified: 2018/05/30 20:29:07
7"
8"======================================================================
9" vim: set ts=4 sw=4 tw=78 noet :
10
11
12"----------------------------------------------------------------------
13" 显示设置
14"----------------------------------------------------------------------
15
16" 总是显示状态栏
17set laststatus=2
18
19" 总是显示行号
20set number
21
22" 总是显示侧边栏(用于显示 mark/gitdiff/诊断信息)
23set signcolumn=yes
24
25" 总是显示标签栏
26set showtabline=2
27
28" 设置显示制表符等隐藏字符
29set list
30
31" 右下角显示命令
32set showcmd
33
34" 插入模式在状态栏下面显示 -- INSERT --,
35" 先注释掉,默认已经为真了,如果这里再设置一遍会影响 echodoc 插件
36" set showmode
37
38" 水平切割窗口时,默认在右边显示新窗口
39set splitright
40
41
42"----------------------------------------------------------------------
43" 颜色主题:色彩文件位于 colors 目录中
44"----------------------------------------------------------------------
45
46" 设置黑色背景
47set background=dark
48
49" 允许 256 色
50set t_Co=256
51
52" 设置颜色主题,会在所有 runtimepaths 的 colors 目录寻找同名配置
53" color desert256
54
55
56"----------------------------------------------------------------------
57" 状态栏设置
58"----------------------------------------------------------------------
59set statusline= " 清空状态了
60set statusline+=\ %F " 文件名
61set statusline+=\ [%1*%M%*%n%R%H] " buffer 编号和状态
62set statusline+=%= " 向右对齐
63set statusline+=\ %y " 文件类型
64
65" 最右边显示文件编码和行号等信息,并且固定在一个 group 中,优先占位
66set statusline+=\ %0(%{&fileformat}\ [%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %v:%l/%L%)
67
68
69"----------------------------------------------------------------------
70" 更改样式
71"----------------------------------------------------------------------
72
73" 更清晰的错误标注:默认一片红色背景,语法高亮都被搞没了
74" 只显示红色或者蓝色下划线或者波浪线
75hi! clear SpellBad
76hi! clear SpellCap
77hi! clear SpellRare
78hi! clear SpellLocal
79if has('gui_running')
80 hi! SpellBad gui=undercurl guisp=red
81 hi! SpellCap gui=undercurl guisp=blue
82 hi! SpellRare gui=undercurl guisp=magenta
83 hi! SpellRare gui=undercurl guisp=cyan
84else
85 hi! SpellBad term=standout ctermfg=1 term=underline cterm=underline
86 hi! SpellCap term=underline cterm=underline
87 hi! SpellRare term=underline cterm=underline
88 hi! SpellLocal term=underline cterm=underline
89endif
90
91" 去掉 sign column 的白色背景
92hi! SignColumn guibg=NONE ctermbg=NONE
93
94" 修改行号为浅灰色,默认主题的黄色行号很难看,换主题可以仿照修改
95highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE
96 \ gui=NONE guifg=DarkGrey guibg=NONE
97
98" 修正补全目录的色彩:默认太难看
99hi! Pmenu guibg=gray guifg=black ctermbg=gray ctermfg=black
100hi! PmenuSel guibg=gray guifg=brown ctermbg=brown ctermfg=gray
101
102
103"----------------------------------------------------------------------
104" 终端设置,隐藏行号和侧边栏
105"----------------------------------------------------------------------
106if has('terminal') && exists(':terminal') == 2
107 if exists('##TerminalOpen')
108 augroup VimUnixTerminalGroup
109 au!
110 au TerminalOpen * setlocal nonumber signcolumn=no
111 augroup END
112 endif
113endif
114
115
116"----------------------------------------------------------------------
117" quickfix 设置,隐藏行号
118"----------------------------------------------------------------------
119augroup VimInitStyle
120 au!
121 au FileType qf setlocal nonumber
122augroup END
123
124
125"----------------------------------------------------------------------
126" 标签栏文字风格:默认为零,GUI 模式下空间大,按风格 3显示
127" 0: filename.txt
128" 2: 1 - filename.txt
129" 3: [1] filename.txt
130"----------------------------------------------------------------------
131if has('gui_running')
132 let g:config_vim_tab_style = 3
133endif
134
135
136"----------------------------------------------------------------------
137" 终端下的 tabline
138"----------------------------------------------------------------------
139function! Vim_NeatTabLine()
140 let s = ''
141 for i in range(tabpagenr('$'))
142 " select the highlighting
143 if i + 1 == tabpagenr()
144 let s .= '%#TabLineSel#'
145 else
146 let s .= '%#TabLine#'
147 endif
148
149 " set the tab page number (for mouse clicks)
150 let s .= '%' . (i + 1) . 'T'
151
152 " the label is made by MyTabLabel()
153 let s .= ' %{Vim_NeatTabLabel(' . (i + 1) . ')} '
154 endfor
155
156 " after the last tab fill with TabLineFill and reset tab page nr
157 let s .= '%#TabLineFill#%T'
158
159 " right-align the label to close the current tab page
160 if tabpagenr('$') > 1
161 let s .= '%=%#TabLine#%999XX'
162 endif
163
164 return s
165endfunc
166
167
168"----------------------------------------------------------------------
169" 需要显示到标签上的文件名
170"----------------------------------------------------------------------
171function! Vim_NeatBuffer(bufnr, fullname)
172 let l:name = bufname(a:bufnr)
173 if getbufvar(a:bufnr, '&modifiable')
174 if l:name == ''
175 return '[No Name]'
176 else
177 if a:fullname
178 return fnamemodify(l:name, ':p')
179 else
180 let aname = fnamemodify(l:name, ':p')
181 let sname = fnamemodify(aname, ':t')
182 if sname == ''
183 let test = fnamemodify(aname, ':h:t')
184 if test != ''
185 return '<'. test . '>'
186 endif
187 endif
188 return sname
189 endif
190 endif
191 else
192 let l:buftype = getbufvar(a:bufnr, '&buftype')
193 if l:buftype == 'quickfix'
194 return '[Quickfix]'
195 elseif l:name != ''
196 if a:fullname
197 return '-'.fnamemodify(l:name, ':p')
198 else
199 return '-'.fnamemodify(l:name, ':t')
200 endif
201 else
202 endif
203 return '[No Name]'
204 endif
205endfunc
206
207
208"----------------------------------------------------------------------
209" 标签栏文字,使用 [1] filename 的模式
210"----------------------------------------------------------------------
211function! Vim_NeatTabLabel(n)
212 let l:buflist = tabpagebuflist(a:n)
213 let l:winnr = tabpagewinnr(a:n)
214 let l:bufnr = l:buflist[l:winnr - 1]
215 let l:fname = Vim_NeatBuffer(l:bufnr, 0)
216 let l:num = a:n
217 let style = get(g:, 'config_vim_tab_style', 0)
218 if style == 0
219 return l:fname
220 elseif style == 1
221 return "[".l:num."] ".l:fname
222 elseif style == 2
223 return "".l:num." - ".l:fname
224 endif
225 if getbufvar(l:bufnr, '&modified')
226 return "[".l:num."] ".l:fname." +"
227 endif
228 return "[".l:num."] ".l:fname
229endfunc
230
231
232"----------------------------------------------------------------------
233" GUI 下的标签文字,使用 [1] filename 的模式
234"----------------------------------------------------------------------
235function! Vim_NeatGuiTabLabel()
236 let l:num = v:lnum
237 let l:buflist = tabpagebuflist(l:num)
238 let l:winnr = tabpagewinnr(l:num)
239 let l:bufnr = l:buflist[l:winnr - 1]
240 let l:fname = Vim_NeatBuffer(l:bufnr, 0)
241 let style = get(g:, 'config_vim_tab_style', 0)
242 if style == 0
243 return l:fname
244 elseif style == 1
245 return "[".l:num."] ".l:fname
246 elseif style == 2
247 return "".l:num." - ".l:fname
248 endif
249 if getbufvar(l:bufnr, '&modified')
250 return "[".l:num."] ".l:fname." +"
251 endif
252 return "[".l:num."] ".l:fname
253endfunc
254
255
256
257"----------------------------------------------------------------------
258" 设置 GUI 标签的 tips: 显示当前标签有哪些窗口
259"----------------------------------------------------------------------
260function! Vim_NeatGuiTabTip()
261 let tip = ''
262 let bufnrlist = tabpagebuflist(v:lnum)
263 for bufnr in bufnrlist
264 " separate buffer entries
265 if tip != ''
266 let tip .= " \n"
267 endif
268 " Add name of buffer
269 let name = Vim_NeatBuffer(bufnr, 1)
270 let tip .= name
271 " add modified/modifiable flags
272 if getbufvar(bufnr, "&modified")
273 let tip .= ' [+]'
274 endif
275 if getbufvar(bufnr, "&modifiable")==0
276 let tip .= ' [-]'
277 endif
278 endfor
279 return tip
280endfunc
281
282
283"----------------------------------------------------------------------
284" 标签栏最终设置
285"----------------------------------------------------------------------
286set tabline=%!Vim_NeatTabLine()
287set guitablabel=%{Vim_NeatGuiTabLabel()}
288set guitabtooltip=%{Vim_NeatGuiTabTip()}
289
290
291
diff --git a/vim/init/tabsize.vim b/vim/init/tabsize.vim
new file mode 100644
index 0000000..b383b80
--- /dev/null
+++ b/vim/init/tabsize.vim
@@ -0,0 +1,44 @@
1"======================================================================
2"
3" init-tabsize.vim - 大部分人对 tabsize 都有自己的设置,改这里即可
4"
5" Created by skywind on 2018/05/30
6" Last Modified: 2018/05/30 22:05:44
7"
8"======================================================================
9" vim: set ts=4 sw=4 tw=78 noet :
10
11
12"----------------------------------------------------------------------
13" 默认缩进模式(可以后期覆盖)
14"----------------------------------------------------------------------
15
16set expandtab
17set shiftwidth=2
18set autoindent
19set tabstop=4
20set softtabstop=0
21set smartindent
22
23" 设置缩进宽度
24"set sw=4
25
26" 设置 TAB 宽度
27set ts=4
28
29" 禁止展开 tab (noexpandtab)
30"set noet
31
32" 如果后面设置了 expandtab 那么展开 tab 为多少字符
33set tabstop=4
34set softtabstop=0
35
36
37augroup PythonTab
38 au!
39 " 如果你需要 python 里用 tab,那么反注释下面这行字,否则vim会在打开py文件
40 " 时自动设置成空格缩进。
41 "au FileType python setlocal shiftwidth=4 tabstop=4 noexpandtab
42augroup END
43
44
diff --git a/vim/kickstarter.lua b/vim/lazy/lazy.lua
index 1805fa2..5117e50 100644
--- a/vim/kickstarter.lua
+++ b/vim/lazy/lazy.lua
@@ -1,36 +1,8 @@
1--[[ 1--[[
2 2
3===================================================================== 3From kickstarter
4==================== READ THIS BEFORE CONTINUING ==================== 4
5===================================================================== 5 TODO: The very first thing you should do is to run the command `:Tutor` in Neovim.
6======== .-----. ========
7======== .----------------------. | === | ========
8======== |.-""""""""""""""""""-.| |-----| ========
9======== || || | === | ========
10======== || KICKSTART.NVIM || |-----| ========
11======== || || | === | ========
12======== || || |-----| ========
13======== ||:Tutor || |:::::| ========
14======== |'-..................-'| |____o| ========
15======== `"")----------------(""` ___________ ========
16======== /::::::::::| |::::::::::\ \ no mouse \ ========
17======== /:::========| |==hjkl==:::\ \ required \ ========
18======== '""""""""""""' '""""""""""""' '""""""""""' ========
19======== ========
20=====================================================================
21=====================================================================
22
23What is Kickstart?
24
25 Kickstart.nvim is *not* a distribution.
26
27 Kickstart.nvim is a starting point for your own configuration.
28 The goal is that you can read every line of code, top-to-bottom, understand
29 what your configuration is doing, and modify it to suit your needs.
30
31 Once you've done that, you can start exploring, configuring and tinkering to
32 make Neovim your own! That might mean leaving Kickstart just the way it is for a while
33 or immediately breaking it into modular pieces. It's up to you!
34 6
35 If you don't know anything about Lua, I recommend taking some time to read through 7 If you don't know anything about Lua, I recommend taking some time to read through
36 a guide. One possible example which will only take 10-15 minutes: 8 a guide. One possible example which will only take 10-15 minutes:
@@ -41,47 +13,8 @@ What is Kickstart?
41 - :help lua-guide 13 - :help lua-guide
42 - (or HTML version): https://neovim.io/doc/user/lua-guide.html 14 - (or HTML version): https://neovim.io/doc/user/lua-guide.html
43 15
44Kickstart Guide:
45
46 TODO: The very first thing you should do is to run the command `:Tutor` in Neovim.
47
48 If you don't know what this means, type the following:
49 - <escape key>
50 - :
51 - Tutor
52 - <enter key>
53
54 (If you already know the Neovim basics, you can skip this step.)
55
56 Once you've completed that, you can continue working through **AND READING** the rest
57 of the kickstart init.lua.
58
59 Next, run AND READ `:help`.
60 This will open up a help window with some basic information
61 about reading, navigating and searching the builtin help documentation.
62
63 This should be the first place you go to look when you're stuck or confused
64 with something. It's one of my favorite Neovim features.
65
66 MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation, 16 MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation,
67 which is very useful when you're not exactly sure of what you're looking for. 17 which is very useful when you're not exactly sure of what you're looking for.
68
69 I have left several `:help X` comments throughout the init.lua
70 These are hints about where to find more information about the relevant settings,
71 plugins or Neovim features used in Kickstart.
72
73 NOTE: Look for lines like this
74
75 Throughout the file. These are for you, the reader, to help you understand what is happening.
76 Feel free to delete them once you know what you're doing, but they should serve as a guide
77 for when you are first encountering a few different constructs in your Neovim config.
78
79If you experience any errors while trying to install kickstart, run `:checkhealth` for more info.
80
81I hope you enjoy your Neovim journey,
82- TJ
83
84P.S. You can delete this when you're done too. It's your config now! :)
85--]] 18--]]
86 19
87-- Install package manager 20-- Install package manager
@@ -395,33 +328,12 @@ require('lazy').setup({
395-- [[ Setting options ]] 328-- [[ Setting options ]]
396-- See `:help vim.o` 329-- See `:help vim.o`
397 330
398-- Sync clipboard between OS and Neovim.
399-- Remove this option if you want your OS clipboard to remain independent.
400-- See `:help 'clipboard'`
401
402-- vim.o.clipboard = 'unnamedplus'
403
404-- Let cursor be line in insert mode 331-- Let cursor be line in insert mode
405vim.opt.guicursor = "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20" 332vim.opt.guicursor = "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20"
406 333
407-- Enable break indent 334-- Enable break indent
408vim.o.breakindent = true 335vim.o.breakindent = true
409 336
410-- Save undo history
411vim.o.undofile = true
412
413-- Case-insensitive searching UNLESS \C or capital in search
414vim.o.ignorecase = true
415vim.o.smartcase = true
416
417-- Keep signcolumn on by default
418vim.wo.signcolumn = 'yes'
419
420-- Decrease update time
421vim.o.updatetime = 250
422vim.o.timeout = true
423vim.o.timeoutlen = 300
424
425-- Set completeopt to have a better completion experience 337-- Set completeopt to have a better completion experience
426vim.o.completeopt = 'menuone,noselect' 338vim.o.completeopt = 'menuone,noselect'
427 339
diff --git a/vim/init.vim b/vim/vimrc
index 6a2373e..78a96b1 100644
--- a/vim/init.vim
+++ b/vim/vimrc
@@ -7,7 +7,7 @@ endif
7 7
8" Get current dir 8" Get current dir
9" let s:home = fnamemodify(resolve(expand('<sfile>:p')), ':h') 9" let s:home = fnamemodify(resolve(expand('<sfile>:p')), ':h')
10let s:home = '~/.vim/vim-init' 10let s:home = '~/helper/vim'
11 11
12" Load script in current dir 12" Load script in current dir
13" command! -nargs=1 LoadScript exec 'source '.s:home.'/'.'<args>' 13" command! -nargs=1 LoadScript exec 'source '.s:home.'/'.'<args>'
@@ -21,24 +21,24 @@ execute 'set runtimepath+='.s:home
21"---------------------------------------------------------------------- 21"----------------------------------------------------------------------
22 22
23" Basic configuration 23" Basic configuration
24source ~/.vim/vim-init/init/init-basic.vim 24source ~/helper/vim/init/basic.vim
25 25
26" Key mappings 26" Key mappings
27source ~/.vim/vim-init/init/init-keymaps.vim 27source ~/helper/vim/init/keymaps.vim
28 28
29" UI 29" UI
30" source ~/.vim/vim-init/init/init-style.vim 30source ~/helper/vim/init/style.vim
31 31
32" Extra config for different contexts 32" Extra config for different contexts
33source ~/.vim/vim-init/init/init-config.vim 33source ~/helper/vim/init/config.vim
34 34
35" Set tabsize 35" Set tabsize
36source ~/.vim/vim-init/init/init-tabsize.vim 36source ~/helper/vim/init/tabsize.vim
37 37
38if has('nvim') 38if has('nvim')
39 " For nvim 39 " For nvim
40 source ~/.config/nvim/kickstarter.lua 40 source ~/.config/nvim/lazy.lua
41else 41else
42 " Plugin 42 " Plugin
43 source ~/.vim/vim-init/init/init-plugins.vim 43 source ~/helper/vim/init/plugins.vim
44endif 44endif