-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
309 lines (273 loc) · 9.34 KB
/
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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Modify from amix/vimrc Basic version
"
" Maintainer:
" ctjoy
"
" Sections:
" -> General
" -> Plugin setup
" -> Editing mappings
" -> VIM user interface
" -> Colors and Fonts
" -> Files and backups
" -> Fold
" -> Text, tab and indent related
" -> Moving around, tabs and buffers
" -> Status line
" -> Spell checking
" -> Skeleton file setting
" -> Copy and Paste setting
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set history=8192 " more history
filetype plugin indent on
let mapleader = ","
let g:mapleader = ","
nmap <leader>w :w!<cr>
set mouse+=a " enable mouse mode (scrolling, selection, etc)
" disable audible bell
set noerrorbells visualbell t_vb=
" unbind keys
map <C-a> <Nop>
packloadall
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin setup
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim linghtline
set noshowmode
let g:lightline = {
\ 'colorscheme': 'seoul256',
\ }
" NERDTree Plugin
" open NERDTree the quick way
map <leader>n :NERDTreeToggle<CR>
let NERDTreeIgnore=['\.pyc$', '\~$'] " ignore files in NERDTree
" if the only window left open then close it
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" " Ctrlp Plugin, ignore
nnoremap ; :CtrlPBuffer<CR>
let g:ctrlp_show_hidden = 1
let g:ctrlp_working_path_mode = 'ra'
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe " Windows
let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git'
"
" EasyMotion Plugin, mapping
map <Space> <Plug>(easymotion-bd-w)
let g:EasyMotion_startofline = 0 " keep cursor column when JK motion
let g:EasyMotion_smartcase = 1
let g:EasyMotion_use_smartsign_us = 1
" vim-gitgutter Plugin
set updatetime=100
" T-Comment Plugin, fast shortcut for commenting
map <leader>c <c-_><c-_>
" gundo
nnoremap <Leader>u :GundoToggle<CR>
if has('python3')
let g:gundo_prefer_python3 = 1
endif
" vim vista
nnoremap <Leader>v :Vista!!<CR>
let g:vista#renderer#enable_icon = 0
" vim prettier
" Allow auto formatting for files without @format or @prettier tag
let g:prettier#autoformat_require_pragma = 0
" vim jsx pretty work with vim javascript
let g:vim_jsx_pretty_colorful_config = 1 " default 0
" vim python black formatter
nnoremap <Leader>b :Black<CR>
"auto format when close the file
autocmd BufWritePre *.py execute ':Black'
let g:black_linelength = 120
" " vim syntastic
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_wq = 0
" let g:syntastic_mode_map = {
" \ 'mode': 'passive',
" \ 'active_filetypes': [],
" \ 'passive_filetypes': []
" \}
" nnoremap <Leader>s :SyntasticCheck<CR>
" nnoremap <Leader>r :SyntasticReset<CR>
" nnoremap <Leader>i :SyntasticInfo<CR>
" nnoremap <Leader>m :SyntasticToggleMode<CR>
" vim syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" let g:syntastic_javascript_checkers = ['eslint']
" let g:syntastic_javascript_eslint_exe = 'npm run lint --'
" let g:syntastic_python_checkers = ['pylint']
"
" highlight link SyntasticError ErrorMsg
" highlight link SyntasticErrorSign WarningMsg
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map 9 $
map 0 ^
imap jk <Esc>
" nmap <space> :
nmap <CR> o<Esc>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set hlsearch " highlight search
set incsearch " incremental search (as string is being typed)
set showmatch " show matching braces when text indicator is over them
set number " number lines
set relativenumber " relative line numbering
set clipboard=unnamed
set timeout timeoutlen=1000 ttimeoutlen=100 " fix slow O inserts
" toggle relative numbering
nnoremap <C-n> :set rnu!<CR>
" smart case-sensitive search
set ignorecase
set smartcase
set ruler " show current position in file
set scrolloff=5 " show lines above and below cursor (when possible)
set lazyredraw " skip redrawing screen in some cases
" set cursorline
" highlight current line, but only in active window
augroup CursorLineOnlyInActiveWindow
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable
set encoding=utf8
" vim can autodetect this based on $TERM (e.g. 'xterm-256color')
" but it can be set to force 256 colors
" set t_Co=256
if &t_Co < 256
colorscheme default
set nocursorline " looks bad in this mode
else
set background=dark
if filereadable(expand("~/.vimrc_background"))
let base16colorspace=256
source ~/.vimrc_background
endif
endif
" Use Unix as the standard file type
set fileformats=unix,dos,mac
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nobackup
set nowritebackup
set noswapfile
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Fold
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=2
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set listchars=tab:>>,nbsp:~ " set list to see tabs and non-breakable spaces
set autoindent
set smartindent
set backspace=indent,eol,start " allow backspacing over everything
set nojoinspaces " suppress inserting two spaces between sentences
set smarttab
set expandtab
set fileformat=unix
" use 2 spaces instead of tabs during formatting
set tabstop=2
set softtabstop=2
set shiftwidth=2
" Linebreak on 500 characters
set linebreak
set textwidth=500
set wrap
" tab completion for files/bufferss
set wildmode=longest,list
set wildmenu
" mark extra whitespace as bad, and color it red.
highlight BadWhitespace ctermbg=red guibg=darkred
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
"Remove all trailing whitespace by pressing leader dw
"Credit http://vi.stackexchange.com/questions/454/whats-the-simplest-way-to-strip-trailing-whitespace-from-all-lines-in-a-file
nnoremap <leader>dw :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Moving around window fast
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
" solution 1 solution 1 Buffer solution from Josh Davis solution 1 solution 1
" This allows buffers to be hidden if you've modified a buffer.
" This is almost a must if you wish to use buffers in this way.
set hidden
" To open a new empty buffer
" This replaces :tabnew which I used to bind to this mapping
nmap <leader>t :enew<cr>
" Tab to next buffer
nnoremap <tab> :bnext<cr>
" Shift-tab to previous buffer
nnoremap <s-tab> :bprevious<cr>
" Close the current buffer and move to the previous one
" This replicates the idea of closing a tab
nmap <leader>q :bp <BAR> bd #<CR>
set autochdir " automatically set current directory to directory of last opened file
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
" open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
set laststatus=2
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
" Shortcuts using <leader>
" ]s go to the next spell mistake
" [s go to the previous spell mistake
" zg add the new word to the spell file
" z= choice one of the option
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Skeleton file setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
au BufNewFile *.html 0r ~/.vim/skeleton/skeleton.html | let IndentStyle = "html"
au BufNewFile *.sh 0r ~/.vim/skeleton/skeleton.sh | let IndentStyle = "sh"
au BufNewFile *.py 0r ~/.vim/skeleton/skeleton.py | let IndentStyle = "py"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Copy and Paste setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" copy and paste to another program
vnoremap <leader>y "+y
map <leader>p "+P