-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaudai.vimrc
311 lines (278 loc) · 10.4 KB
/
laudai.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
" _ ____
" \_|_) (| \ o
" | __, | | __,
" _| / | | | _| |/ | |
" (/\___/\_/|_/ \_/|_/ (/\___/ \_/|_/|_/
"
" Github : https://github.com/laudai
" Medium : https://laudaihe.medium.com/
" Use Vim settings, rather than Vi settings (much better!).
" " This must be first, because it changes other options as a side effect.
" VI Setting
set number "nu"
set relativenumber "rnu"
"ai, 自動縮排,如果此行從第四字元開始,按下Enter後,下行就會從第四字元開始。Default is noai"
set autoindent
" VIM Setting
"nocp, no compatible to vi,can use vim plugin.Default is nocp"
set nocompatible "disable backwards compatibility with vi
set background=dark "bg"
set t_Co=256 "number of colors"
set laststatus=2 "ls, 下方的狀態橫Bar。Default is 1"
set ruler "ru, 狀態列最右邊的資訊,共有Top, Bot, All, %"
set shiftwidth=4 "sw, 使用>>的字元寬度,如果是0會使用tabstop設定"
set softtabstop=4 "sts"
set tabstop=4 "ts"
"set expandtab=4 "et, 還不確定是什麼功能"
" search-setting
set hlsearch "hls, highlith all its matches."
set incsearch "is, 即時前往符合搜尋條件的字
set ignorecase "ic, 忽略大小寫
set smartcase "scs, 智慧搜尋
" works likes bash shell
" set wildmode=longest,list
" works likes zsh
set wildmenu "wmnu, default is off"
set wildmode=full "wim, default is full"
set history=200 "set history number, default is 50
set pastetoggle=<F7> "pt, toggle vim paste mode"
" edit-setting
" enable X11-based-system clipboard, In Ubuntu & Debian, u need install vim-gtk3
set clipboard=unnamedplus
filetype plugin indent on " enable filetype plugins and indent
set undofile
set autochdir " acd, 當開啟多個不同資料夾檔案時,會自動切換到目前編輯檔案路徑
set autoread " ar, 當文件僅在vim外部進行修改,可進行自動讀檔(有焦點使用限制)
" misc-setting
" 將vim中的0開頭數字視為10進制,這樣就可以直接用快鍵加減
" number<C-a> or number<C-x>
set nrformats=bin,hex,alpha
" Highlight setting
highlight CursorLine cterm=bold,underline ctermbg=black ctermfg=None
" Abbreviations setting ,ab
iab [] []()<left><left><left>
" Keybindings
" map-modes
":map :noremap :unmap Normal, Visual, Select, Operator-pending
":nmap :nnoremap :nunmap Normal
":vmap :vnoremap :vunmap Visual and Select
":smap :snoremap :sunmap Select
":xmap :xnoremap :xunmap Visual
":omap :onoremap :ounmap Operator-pending
":map! :noremap! :unmap! Insert and Command-line
":imap :inoremap :iunmap Insert
":lmap :lnoremap :lunmap Insert, Command-line, Lang-Arg
":cmap :cnoremap :cunmap Command-line
":tmap :tnoremap :tunmap Terminal-Job
" nnoremap : Normal no recursion map
map! jk <ESC>
imap <C-]> <ESC>:e<CR> "re-edit this file in insert mode"
inoremap <C-v><C-v> <C-v>
inoremap <C-d> <Del>
" Insert newline without entering insert mode
" https://vim.fandom.com/wiki/Insert_newline_without_entering_insert_mode
nnoremap oo o<Esc>k
nnoremap OO O<Esc>j
" Shifting blocks visually
" https://vim.fandom.com/wiki/Shifting_blocks_visually
vnoremap > >gv
vnoremap < <gv
inoremap <S-Tab> <C-D>
vnoremap <Tab> >v
vnoremap <S-Tab> <v
map <ESC>n <M-n>
map <ESC>p <M-p>
nnoremap <M-n> :tabn<CR> \| :echo 'Change to next tab'<CR>
nnoremap <M-p> :tabp<CR> \| :echo 'Change to previous tab'<CR>
nnoremap <C-p> :bp<CR> \| :echo 'Change to previous buffer'<CR>
nnoremap <C-n> :bn<CR> \| :echo 'Change to next buffer'<CR>
nnoremap ` '
nnoremap ' `
" onoremap ' `
" onoremap ` '
" you can modified operator pending mode to use y'' d''
" also can use operatorPendingModeKeyBindings in VSCode vim keymap
" https://vi.stackexchange.com/questions/12576/how-to-remap-backtick-mark-with-single-quote-mark-globally
nmap qq :q<CR>
nmap q; q:
map <ESC>j <M-j>
map <ESC>k <M-k>
nn <M-j> :.m+1<CR>
nn <M-k> :.m-2<CR>
" You can't send C-j to vim in gnome-terminal. It will parse to C-M.
" But you can use it in Windows terminal, guake terminal.
nn <C-j> <C-w>j
nn <C-k> <C-w>k
nn <C-l> <C-w>l
nn <C-h> <C-w>h
nn <C-\> <C-w>w
nn a; :
nn aj 5j \| :echo 'Downward 5 linewise.'<CR>
nn ak 5k \| :echo 'Upward 5 linewise.'<CR>
nn H ^
nn L g_
nn Y y$
nn <C-v><C-v> <C-v>
" set manual store/restore vim session
set <S-F4>=[1;2S
nn <S-F4> :mksession! ~/.vim_manual_session.vim<CR> \| :echo 'stores session to ~/.vim_manual_session.vim'<CR>
nn <F4> :source ~/.vim_manual_session.vim<CR> \| :echo 'restores session from ~/.vim_manual_session.vim'<CR>
" break undo sequence, start new change for the Ctrl-w, Ctrl-u, Ctrl-h, Ctrl-d
" https://vim.fandom.com/wiki/Recover_from_accidental_Ctrl-U
inoremap <C-u> <C-g>u<C-u>
inoremap <C-w> <C-g>u<C-w>
inoremap <C-h> <C-g>u<C-h>
inoremap <C-d> <C-g>u<Del>
" Toggle Cursorline on/off with one key press
" https://stackoverflow.com/questions/1497404/toggle-cursorline-on-off-with-one-key-press
" Mapping 'fast' keycodes
" https://vim.fandom.com/wiki/Mapping_fast_keycodes_in_terminal_Vim
" You should test keystroke in VIM ex mode via :{C-v}{C-S-F2}
" There is a <S-F2> keycodes but no <C-S-F2>. You should map keystroke to <C-S-F2>
" :h keycodes, :h terminal-key-codes
" <ESC> equal ^[
set <S-F2>=[1;2Q
map <S-F2> :set cursorline!<CR>
map <ESC>[1;5Q <C-F2>
map <C-F2> :set cursorcolumn!<CR>
map <ESC>[1;6Q <C-S-F2>
map <C-S-F2> :set cursorcolumn!<Bar>set cursorline!<CR>
" Toggle relativenumber
map <ESC>[1;6R <C-S-F3>
map <C-S-F3> :set rnu!<CR>
" <leader> mapleader, <leader> key default is '\'
let mapleader="\<space>"
nmap <leader>n :noh<CR>
nmap <leader>w <ESC>:w<CR>
nmap <leader>d ^dg_ \| :echo "Delete whole line without linewise from
\ non-block to non-block char!"<CR>
nmap <leader>bd :bd<CR>
" buffer only can mapping via keybinding or use plugin BufOnly.vim
" https://stackoverflow.com/questions/4545275/vim-close-all-buffers-but-this-one
nmap <leader>bo :%bd\|e#<CR>
nmap <leader>qq <ESC>:cq<CR>
nnoremap <leader>ev :vsp ~/.vimrc<CR>
nnoremap <leader>r :reg<CR>
nnoremap <leader>rr :source ~/.vimrc<CR>
nmap <leader>tt :tabe<CR>
nmap <leader>te :tabe<space>
nmap <leader>to :tabo<CR>
nmap <leader>tc <ESC>:tabc<CR>
nmap <leader>ma :marks<CR>
nmap <leader>ju :jumps<CR>
nn <leader>H H
nn <leader>M M
nn <leader>L L
" use system clipboard, also u can use xsel,xclip command.
noremap <Leader>y "+y
noremap <Leader>p "0p
noremap <Leader>P "+P
noremap <Leader>x "_x
noremap <Leader>dd "_dd
noremap <Leader>dw "_dw
inoremap <C-v> <ESC>"+pa
vnoremap <C-c> "+y
vnoremap <C-d> "+d
" VIM学习笔记 键盘映射 (Map)
" http://yyq123.blogspot.com/2010/12/vim-map.html
" 快捷鍵設定教學
" 中文版 http://haoxiang.org/2011/09/vim-modes-and-mappin/
" 英文版 https://medium.com/vim-drops/understand-vim-mappings-and-create-your-own-shortcuts-f52ee4a6b8ed
" Plugin
" vim-plug automatic installation
" https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
"
" airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" https://python.libhunt.com/compare-python-mode-vs-jedi-vim
" Developing python with vim, what plugin to choose? (python-mode vs. jedi-vim)
Plug 'davidhalter/jedi-vim'
" Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' }
" edit file more smoothly
Plug 'tpope/vim-surround'
Plug 'wellle/targets.vim'
Plug 'easymotion/vim-easymotion'
Plug 'justinmk/vim-sneak'
Plug 'yggdroot/indentline'
"
" Initialize plugin system
call plug#end()
" Plugin setting
" airline plugin
let g:airline_theme='base16_google'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = '‧'
let g:airline#extensions#tabline#left_alt_sep = '┊'
let g:airline#extensions#tabline#formatter = 'unique_tail'
" jedi-vim plugin
let g:jedi#goto_command = "<leader>d"
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_stubs_command = "<leader>s"
let g:jedi#goto_definitions_command = ""
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>u"
let g:jedi#completions_command = "<C-Space>"
let g:jedi#auto_initialization = 1
let g:jedi#popup_on_dot = 0
autocmd FileType python setlocal completeopt-=preview
" indentLine plugin
let g:indentLine_enabled = 1
let g:indentLine_setColors = 1
let g:indentLine_color_term = 214
"let g:indentLine_bgcolor_term = 240
let g:indentLine_defaultGroup = 'SpecialKey'
let g:indentLine_char = '§'
let g:indentLine_char_list = ['|', '¦', '┆', '┊']
""" This is copy from vim74 example
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" This is copy from vim74 example
" Bash Script header
autocmd BufNewFile *.sh 0put =\"#!/usr/bin/env bash\<nl>\"|$
autocmd BufNewFile *.sh 1put =\"# Author : laudai\<nl>\"|$
autocmd BufNewFile *.sh 2put =\"\<nl>\"|$
" Python header
autocmd BufNewFile *.py 0put =\"#!/usr/bin/env python\<nl>\"|$
autocmd BufNewFile *.py 1put =\"# encoding: utf8\<nl>\"|$
autocmd BufNewFile *.py 2put =\"# Author : laudai\<nl>\"|$
autocmd BufNewFile *.py 3put =\"\<nl>\"|$
" Vim’s absolute, relative and hybrid line numbers
" https://jeffkreeftmeijer.com/vim-number/
augroup displaytoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
\| set cursorline
\| highlight LineNr ctermfg=darkgray
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
\| set nocursorline
\| highlight LineNr ctermfg=yellow
augroup END