-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnvimrc
329 lines (266 loc) · 10.5 KB
/
nvimrc
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
" ============================================================================
" UI
" ============================================================================
" Should at the top since it will affect bundles.vim (maybe?)
if $TERM == "xterm-256color"
set t_Co=256
elseif $TERM == "screen-256color"
set t_Co=256
endif
if has("termguicolors")
set termguicolors
endif
" Ruler
set colorcolumn=79
" ============================================================================
" General
" ============================================================================
" Encoding
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
set fileencoding=utf-8
set fencs=utf-8,chinese
syntax on
filetype on
set history=100
set nobackup
set autoread " When a file has been detected to have been changed outside of Vim and
" it has not been changed inside of Vim, automatically read it again.
" When the file has been deleted this is not done.
set ff=unix
set backspace=indent,eol,start
" Indent
set smarttab " a <Tab> in front of a line inserts blanks according to
" 'shiftwidth'. 'tabstop' or 'softtabstop' is used in other places
set shiftwidth=4 " Number of spaces to use for each step of (auto)indent.
set tabstop=4 " Number of spaces that a <Tab> in the file counts for.
set softtabstop=4 " Number of spaces that a <Tab> counts for while performing editing
" operations, like inserting a <Tab> or using <BS>.
set autoindent " Copy indent from current line when starting a new line
set expandtab " In Insert mode: Use the appropriate number of spaces to insert a
" <Tab>. Spaces are used in indents with the '>' and '<' commands and
" when 'autoindent' is on. To insert a real tab when 'expandtab' is
" on, use CTRL-V<Tab>
" Set 'tabstop' and 'shiftwidth' to whatever you prefer and use
" 'expandtab'. This way you will always insert spaces. The
" formatting will never be messed up when 'tabstop' is changed.
set smartindent " Do smart autoindenting when starting a new line. Works for C-like
" programs, but can also be used for other languages. 'cindent' does
" something like this, works better in most cases, but is more strict
inoremap # X<BS>#
" Search
set hlsearch
set incsearch
set smartcase
set ignorecase
set scrolloff=5
" Tabs
set tabpagemax=7
set showtabline=2
set splitright " To make vsplit put the new buffer on the right of the current buffer:
set splitbelow
" Fold
set foldmethod=indent
"set foldlevel=2
set nofoldenable
" Display
set ruler " Show the line and column number of the cursor position, separated by a comma.
set showcmd " Show (partial) command in the last line of the screen.
set cmdheight=1 " Number of screen lines to use for the command-line.
set relativenumber " relative number
"set number
set laststatus=2 " The value of this option influences when the last window will have a
" status line:
" 0: never
" 1: only if there are at least two windows
" 2: always
set cursorline " Highlight the screen line of the cursor with CursorLine
set wildmenu " When 'wildmenu' is on, command-line completion operates in an enhanced
" mode. On pressing 'wildchar' (usually <Tab>) to invoke completion,
" the possible matches are shown just above the command line, with the
" first match highlighted (overwriting the status line, if there is
" one). Keys that show the previous/next match, such as <Tab> or
" CTRL-P/CTRL-N, cause the highlight to move to the appropriate match.
"set wildchar=
"set wildmode=
" A comma separated list of options for Insert mode completion
set completeopt=menuone,longest
" get rid of the fucking preview window
"set completeopt-=preview
" Storage
" centralize backups, swapfiles and undo history
set backupdir=~/.nvim/.backups
set directory=~/.nvim/.swaps
set undodir=~/.nvim/.undos
set undofile
" File Specials
"autocmd FileType text setlocal textwidth=80
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
autocmd FileType typescript setlocal shiftwidth=2 tabstop=2
autocmd FileType json setlocal shiftwidth=2 tabstop=2
autocmd FileType crontab setlocal nowritebackup
autocmd FileType yaml setlocal shiftwidth=2 tabstop=2 indentexpr=
autocmd FileType lua setlocal shiftwidth=2 tabstop=2 softtabstop=2 expandtab
autocmd FileType html setlocal shiftwidth=2 tabstop=2 indentexpr=
autocmd FileType scss setlocal shiftwidth=2 tabstop=2 indentexpr=
autocmd FileType pico8 setlocal noexpandtab shiftwidth=2 tabstop=2 softtabstop=2
"autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript
au BufRead,BufNewFile */nginx*/*.conf set ft=nginx
au BufRead,BufNewFile */supervisor/*.conf set ft=dosini
au BufRead,BufNewFile *.conf set ft=dosini
au BufRead,BufNewFile *.pac set ft=javascript
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif |
\ endif
" Misc
set mouse=a
" Prevent flashing when execute external command from vim
set shellpipe=&>
" netrw
let g:netrw_liststyle = 3
" quickfix list auto height
au FileType qf call AdjustWindowHeight(3, 10)
function! AdjustWindowHeight(minheight, maxheight)
exe max([min([line("$"), a:maxheight]), a:minheight]) . "wincmd _"
endfunction
" ============================================================================
" Highlight
" ============================================================================
" Line number
highlight LineNr term=bold gui=NONE guifg=gray25 guibg=gray13
" Highlight TODO, FIXME, NOTE, etc.
autocmd Syntax * call matchadd('Todo', '\W\zs\(TODO\|FIXME\|CHANGED\|XXX\|BUG\|HACK\)')
autocmd Syntax * call matchadd('Debug', '\W\zs\(NOTE\|INFO\|IDEA\|SECTION\)')
" Diff
highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
" tab characters display dot
set list!
set listchars=tab:>-
" <- a tab char
" highlight tab char
autocmd ColorScheme * highlight Whitespace ctermbg=gray guibg=gray10 guifg=gray20
highlight Whitespace ctermbg=gray guibg=gray10 guifg=gray20
" highlight trailing whitespace (now controlled by vim-better-whitespace)
"autocmd ColorScheme * highlight TrailWhitespace ctermbg=red guibg=gray40
"highlight TrailWhitespace ctermbg=red guibg=gray40
"match TrailWhitespace /\s\+$/
" ============================================================================
" Custom Functions
" ============================================================================
" Strip trailing whitespace (\ss)
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
" ============================================================================
" Keymaps
" ============================================================================
" command+c copy, requires terminal send escape sequence "Esc+c" on command+c
" source: https://github.com/neovim/neovim/issues/5052#issuecomment-232083842
vnoremap <M-0> "+y
" nvim's default Y is y$ (no line feed)
" https://www.reddit.com/r/neovim/comments/petq61/neovim_060_y_not_yanking_line_but_to_end_of_line/
map Y yy
" paste without overwritting register
" https://stackoverflow.com/q/290465/596206
xnoremap p pgvy
" Fix syntax highlighting
noremap <F5> <Esc>:syntax sync fromstart<CR>
inoremap <F5> <C-o>:syntax sync fromstart<CR>
"let mapleader = "\\"
let mapleader = " "
noremap <leader>ss :call StripWhitespace()<CR>
" Save a file as root (,W)
noremap <leader>W :w !sudo tee % > /dev/null<CR>
" easier navigation between split windows
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
map tn :tabnew<cr>
map tc :tabclose<cr>
map <C-n> :tabnext<cr>
map <C-p> :tabprevious<cr>
"nmap <Leader>n :tabn<CR>
"nmap <Leader>p :tabp<CR>
" recover from accidental Ctrl-U
inoremap <C-U> <C-G>u<C-U>
inoremap <c-w> <c-g>u<c-w>
" ============================================================================
" Commands
" ============================================================================
func! DisableAutoIndent()
setlocal noautoindent
setlocal nocindent
setlocal nosmartindent
setlocal indentexpr=
echo 'Auto indent is disabled by many ways'
endfu
com! DisableAutoIndent call DisableAutoIndent()
func! DisableInteractive()
setlocal norelativenumber
setlocal mouse-=a
echo 'Line number and mouse are disabled'
endfu
com! DisableInteractive call DisableInteractive()
func! SetTabstop(size)
let &l:tabstop=a:size
let &l:shiftwidth=a:size
let &l:softtabstop=a:size
endfu
com! -nargs=1 SetTabstop call SetTabstop(<f-args>)
" Get visual selected text in vim, the only useful answer on the Internet:
" https://stackoverflow.com/a/6271254/596206
function! GetVisualSelection()
" Why is this not a built-in Vim script function?!
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
" Spell check
" http://vimdoc.sourceforge.net/htmldoc/spell.html
" http://vim.wikia.com/wiki/Toggle_spellcheck_with_function_keys
func! ToggleSpell()
execute "setlocal spell! spelllang=en_us"
endfu
com! ToggleSpell call ToggleSpell()
func! Hello(who)
if a:who=='world'
echo "Hello ".a:who
endif
endfu
com! -nargs=1 Hello call Hello(<f-args>)
" Snippets (deprecated since using UltiSnips)
com! Noqa call setline('.', getline('.') . ' # NOQA')
"com! HeadUTF call append(line('.')-1, '# coding: utf-8')
"com! HeadPython call append(line('.')-1, '#!/usr/bin/env python')
"com! PythonMain call append(line('.'), "if __name__ == '__main__':")
" Edit configs
func! MyVimrc()
execute "edit $MYVIMRC"
endfu
com! MyVimrc call MyVimrc()
func! MyPlugs()
execute "edit $MYPLUGS"
endfu
com! MyPlugs call MyPlugs()
func! MyLua()
execute "edit $MYLUA"
endfu
com! MyLua call MyLua()