-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.vim
304 lines (266 loc) · 10.6 KB
/
init.vim
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
" NOTE:
" - syntax highlight will not work unless you put it in gvim.
" - No plugins are used to achieve portability with a single file (so there is a mix of scripts that should not be written here).
" Load last open buffer, if no vim args
if argc() == 0
" autocmd VimEnter to load the last buffer
autocmd VimEnter * nested :e #<1
" autocmd BufReadPost to change the working directory to the last buffer's directory
autocmd BufReadPost * execute "cd " expand("%:p:h")
endif
" References:
" [1] https://github.com/asvetliakov/vscode-neovim/issues/103
" [2] https://github.com/Microsoft/WSL/issues/892
if has('clipboard') || exists('g:vscode')
let s:clip = '/mnt/c/Windows/System32/clip.exe' " change this path according to your mount point [2]
if executable(s:clip)
augroup WSLYank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
augroup END
endif
endif
" ---Status Line Custom(https://gist.github.com/meskarune/57b613907ebd1df67eb7bdb83c6e6641)
" status bar colors
au InsertEnter * hi statusline guifg=black guibg=#d7afff ctermfg=black ctermbg=magenta
au InsertLeave * hi statusline guifg=black guibg=#8fbfdc ctermfg=black ctermbg=cyan
hi statusline guifg=black guibg=#8fbfdc ctermfg=black ctermbg=cyan
" Status line
" default: set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)
let g:currentmode={
\ 'n' : 'Normal',
\ 'no' : 'Normal·Operator Pending',
\ 'v' : 'Visual',
\ 'V' : 'V·Line',
\ '\<C-V>' : 'V·Block',
\ 's' : 'Select',
\ 'S' : 'S·Line',
\ '^S' : 'S·Block',
\ 'i' : 'Insert',
\ 'R' : 'Replace',
\ 'Rv' : 'V·Replace',
\ 'c' : 'Command',
\ 'cv' : 'Vim Ex',
\ 'ce' : 'Ex',
\ 'r' : 'Prompt',
\ 'rm' : 'More',
\ 'r?' : 'Confirm',
\ '!' : 'Shell',
\ 't' : 'Terminal'
\}
function! ModeCurrent() abort
let l:modecurrent = mode()
" use get() -> fails safely, since ^V doesn't seem to register
" 3rd arg is used when return of mode() == 0, which is case with ^V
" thus, ^V fails -> returns 0 -> replaced with 'V Block'
let l:modelist = toupper(get(g:currentmode, l:modecurrent, 'V·Block '))
let l:current_status_mode = l:modelist
return l:current_status_mode
endfunction
let ff_table = {'dos' : 'CRLF', 'unix' : 'LF', 'mac' : 'CR' }
function! FileSize(bytes)
let l:bytes = a:bytes | let l:sizes = ['B', 'KB', 'MB', 'GB'] | let l:i = 0
while l:bytes >= 1024 | let l:bytes = l:bytes / 1024.0 | let l:i += 1 | endwhile
return l:bytes > 0 ? printf(' %.1f%s ', l:bytes, l:sizes[l:i]) : ''
endfunction
set laststatus=2
set noshowmode
set statusline=
set statusline+=%0*\ %{ModeCurrent()}
set statusline+=%3*\ " Separator
set statusline+=%0*\ %n\ " Buffer number
set statusline+=%1*\ %<%F%m%r%h%w\ " File path, modified, readonly, helpfile, preview
set statusline+=%= " Right Side
set statusline+=%2*\ %Y " FileType
set statusline+=%3*│ " Separator
set statusline+=%2*\%{''.(&fenc!=''?&fenc:&enc).''} " Encoding
set statusline+=\(%{ff_table[&ff]}) " FileFormat (CRLF/LF/CR)
set statusline+=%3*│ " Separator
set statusline+=%1*\%01l/%L " Line number / total lines
set statusline+=%3*: " Separator
set statusline+=%2*\%v " Colomn number
set statusline+=%2*\(%p%%) " Percentage of document
set statusline+=%{FileSize(line2byte('$')+len(getline('$')))} " File size
" Got to GUI settings(when hover path, <Ctrl-w> + F): $HOME/.gvimrc
hi User1 ctermfg=007 ctermbg=239 guibg=#4e4e4e guifg=#adadad
hi User2 ctermfg=007 ctermbg=236 guibg=#303030 guifg=#adadad
hi User3 ctermfg=236 ctermbg=236 guibg=#303030 guifg=#303030
hi User4 ctermfg=239 ctermbg=239 guibg=#4e4e4e guifg=#4e4e4e
" --Neovide settings (neovim GUI written by Rust)
" Ref: https://github.com/neovide/neovide
if exists("g:neovide")
let g:neovide_transparency = 0.6
endif
" Display options
set autoread " - Reload files changed outside vim
au CursorHold * checktime
set backspace=indent,eol,start " - Press `backspace`(insert mode) => delete character
set belloff=all " - No sounds
set clipboard+=unnamed " - Yank action == clipboard
set encoding=utf-8
set expandtab
set fileencoding=utf-8
set fileformats=unix,dos,mac
set gcr=a:blinkon0 " - Disable cursor blink
set history=1000 " - Store lots of :cmdline history
set list
set listchars=extends:»,nbsp:%,precedes:«,space:·,tab:→\ ,trail:-
set mouse=a " - use mouse
set nobackup " - Do not create backup file
set noswapfile " - Disable swp file output
set noswapfile " - Do not create swap file
set noundofile " - undo file output disabled
set novisualbell " - No flash
set number " - Show line numbers
set ruler " - Show line and column number
set shortmess-=S " - Removing the S flag will show [number currently in focus/number of matches].
set showcmd " - Show incomplete cmds down the bottom
set showmode " - Show current mode down the bottom
set wildmenu " - Show completion list in Command Mode
colorscheme slate " slate|evening
scriptencoding utf-8
syntax enable
" GUI settings
autocmd GUIEnter * :set lines=45
autocmd GUIEnter * :set columns=200
" ----------------------------------------------------------------
" Key config
" ----------------------------------------------------------------
map <Space> <Leader>
map <Leader>q :quitall!<CR>
map <Leader>w :write<CR>
nmap <Leader>rv :so %<CR> " - Reload .vimrc
nmap <silent> <Leader>V :!start explorer /select,%:p<CR> " - Open current dir with exploer
nmap <silent> <Leader>c :bd<CR> " - Delete buffer
nmap <silent> <Leader>v :edit ~/.vimrc<CR>
nnoremap ; :
vnoremap ; :
" `jk`(insert) => normal mode
inoremap jj <Esc>
inoremap jk <Esc>
inoremap kj <Esc>
" - Move current line to up/down `Alt+j/k`
" Ref: https://vim.fandom.com/wiki/Moving_lines_up_or_down
nnoremap <silent> <A-j> :m .+1<CR>==
nnoremap <silent> <A-k> :m .-2<CR>==
inoremap <silent> <A-j> <Esc>:m .+1<CR>==gi
inoremap <silent> <A-k> <Esc>:m .-2<CR>==gi
vnoremap <silent> <A-j> :m '>+1<CR>gv=gv
vnoremap <silent> <A-k> :m '<-2<CR>gv=gv
" - Automatically close parentheses, etc.
inoremap { {}<LEFT>
inoremap [ []<LEFT>
inoremap ( ()<LEFT>
inoremap " ""<LEFT>
inoremap ' ''<LEFT>
" - Switch to alternate file
nnoremap <S-h> :bprevious<CR>
nnoremap <S-l> :bnext<CR>
" //////////////////////////////////////////////////////////////////////////////
" Explore
let g:netrw_altv = 1
let g:netrw_banner = 0
let g:netrw_browse_split = 3
let g:netrw_liststyle = 3
let g:netrw_winsize = 20
let g:NetrwIsOpen=0
function! ToggleNetrw()
if g:NetrwIsOpen
let i = bufnr("$")
while (i >= 1)
if (getbufvar(i, "&filetype") == "netrw")
silent exe "bwipeout " . i
endif
let i-=1
endwhile
let g:NetrwIsOpen=0
else
let g:NetrwIsOpen=1
silent Lexplore
endif
endfunction
augroup AutoStartExplore
autocmd!
autocmd TabNew * :call ToggleNetrw()
autocmd VimEnter * :call ToggleNetrw()
augroup END
noremap <silent> <Leader>e :call ToggleNetrw()<CR>
" //////////////////////////////////////////////////////////////////////////////
"Binary Edit (xxd) mode (invoked by invoking vim -b or opening the *.bin,*.hkx file)
augroup BinaryXXD
autocmd!
autocmd BufReadPre *.bin,*.exe,*.hkx let &binary =1
autocmd BufReadPost * if &binary | silent %!xxd -g 1
autocmd BufReadPost * set ft=xxd | endif
autocmd BufWritePre * if &binary | %!xxd -r | endif
autocmd BufWritePost * if &binary | silent %!xxd -g 1
autocmd BufWritePost * set nomod | endif
augroup END
" //////////////////////////////////////////////////////////////////////////////
" Better gx to open URLs.
" Ref: https://gist.github.com/habamax/0a6c1d2013ea68adcf2a52024468752e
func! BetterGx() abort
if exists("$WSLENV")
lcd /mnt/c
let cmd = ":silent !cmd.exe /C start"
elseif has("win32") || has("win32unix")
let cmd = ':silent !start'
elseif executable('xdg-open')
let cmd = ":silent !xdg-open"
elseif executable('open')
let cmd = ":silent !open"
else
echohl Error
echomsg "Can't find proper opener for an URL!"
echohl None
return
endif
" URL regexes
let rx_base = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S'
let rx_bare = rx_base . '\+'
let rx_embd = rx_base . '\{-}'
let URL = ""
" markdown URL [link text](http://ya.ru 'yandex search')
try
let save_view = winsaveview()
if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0
let URL = matchstr(getline('.')[col('.')-1:], '\[.\{-}\](\zs'.rx_embd.'\ze\(\s\+.\{-}\)\?)')
endif
finally
call winrestview(save_view)
endtry
" asciidoc URL http://yandex.ru[yandex search]
if empty(URL)
try
let save_view = winsaveview()
if searchpair(rx_bare . '\[', '', '\]\zs', 'cbW', '', line('.')) > 0
let URL = matchstr(getline('.')[col('.')-1:], '\S\{-}\ze[')
endif
finally
call winrestview(save_view)
endtry
endif
" HTML URL <a href='http://www.python.org'>Python is here</a>
" <a href="http://www.python.org"/>
if empty(URL)
try
let save_view = winsaveview()
if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0
let URL = matchstr(getline('.')[col('.')-1:], 'href=["'."'".']\?\zs\S\{-}\ze["'."'".']\?/\?>')
endif
finally
call winrestview(save_view)
endtry
endif
" barebone URL http://google.com
if empty(URL)
let URL = matchstr(expand("<cfile>"), rx_bare)
endif
if empty(URL)
return
endif
exe cmd . ' "' . escape(URL, '#%!') . '"'
if exists("$WSLENV") | lcd - | endif
endfunc
nnoremap <silent> gx :call BetterGx()<CR>
" //////////////////////////////////////////////////////////////////////////////