aboutsummaryrefslogtreecommitdiffhomepage
path: root/vimrc
blob: e8c6c3d62328445c7647e53f039d6d6641f670d5 (plain)
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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Custom Config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set cursorline
set number
set relativenumber
set showcmd
set nowrap
set nostartofline
set sidescroll=1
set sidescrolloff=999
set shell=/bin/bash
set shiftwidth=2
autocmd FileType vimwiki set shiftwidth=4
" set clipboard=unnamedplus

" general
function! Bye()
    if len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
        :quit
    else
        :bdelete
    endif
endfunction
nnoremap <silent> <C-C> :call Bye()<CR>
nnoremap <silent> <C-S-C> :q!<CR>
nnoremap <leader>, :.terminal ++noclose<CR>
vnoremap <leader>, :terminal<CR>
nnoremap Y viW:!tee >(xsel -ib)<CR>
vnoremap Y :!tee >(xsel -ib)<CR>
nnoremap <leader>< :%terminal ++noclose<CR>
nnoremap <leader>W :set wrap!<CR>
nnoremap <leader>T :vertical terminal<CR>
nnoremap <C-K> ddkP
nnoremap <C-J> ddp
nnoremap <leader>R :read !
nnoremap <leader>P :r !xsel -ob<CR>
set autoread
set nofoldenable " disable folding

" move
" nnoremap <Tab> }
" nnoremap <S-Tab> {
inoremap <C-L> <Right>
cnoremap <C-L> <Right>
cnoremap <C-H> <Left>
nmap H 0
nnoremap L $
nnoremap <C-L> 60l
nnoremap <C-H> 60h
nnoremap / ms/

" disable syntax
nnoremap <silent> <leader>s
             \ : if exists("syntax_on") <BAR>
             \    syntax off <BAR>
             \ else <BAR>
             \    syntax enable <BAR>
             \ endif<CR>
" show current syntax
nnoremap <leader>S :echo join(reverse(map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')),' ')<CR>

" Operator pending
onoremap p i(
onoremap ap a(
" next parenthesis
onoremap fp :<c-u>normal! f(vi(<cr> 
onoremap b i{
onoremap fb :<c-u>normal! f{vi{<cr> 
onoremap ab a{
" block
onoremap B /return<CR>

" Search
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>'")

" S&R
nnoremap <leader>; :%s:::g<Left><Left><Left>
vnoremap <leader>; :s:::g<Left><Left><Left>
cnoremap \\ \(\)<Left><Left>

" Fix paste bug triggered by inoremaps
set t_BE=

" surround with charactor
vnoremap ' <ESC>`<i'<ESC>`>la'<ESC>
vnoremap q <ESC>`<i"<ESC>`>la"<ESC>
vnoremap ( <ESC>`<i(<ESC>`>la)<ESC>
vnoremap { <ESC>`<i{<ESC>`>la}<ESC>
vnoremap [ <ESC>`<i[<ESC>`>la]<ESC>gvlol
inoremap [ []<C-O>h
vnoremap ` <ESC>`<i`<ESC>`>la`<ESC>
vnoremap , <ESC>`<i<<ESC>`>la><ESC>
vnoremap <space> <ESC>`<i<space><ESC>`>la<space><ESC>
vnoremap 8 <ESC>`<i*<ESC>`>la*<ESC>
vnoremap z <ESC>`<i「<ESC>`>la」<ESC>
vnoremap ~ <ESC>`<i~<ESC>`>la~<ESC>

" abbrev
iabbrev @@ typebrook@gmail.com

" vim_markdown
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_conceal = 0
vnoremap <C-K> <ESC>`<i[<ESC>`>la]()<ESC>i

" XML fold
let g:xml_syntax_folding=1
autocmd FileType xml setlocal foldmethod=syntax

" JSON fold
let g:json_syntax_folding=1
autocmd FileType json setlocal foldmethod=syntax

" Apply new SniptMat Parser
let g:snipMate = { 'snippet_version' : 1  }

" Set width of mutt as 72
au BufRead /tmp/mutt-* set tw=72

" Redirection with buffer
" Usage:
" 	:Redir hi ............. show the full output of command ':hi' in a scratch window
" 	:Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window
function! Redir(cmd)
	for win in range(1, winnr('$'))
		if getwinvar(win, 'scratch')
			execute win . 'windo close'
		endif
	endfor
	if a:cmd =~ '^!'
		let output = system(matchstr(a:cmd, '^!\zs.*'))
	else
		redir => output
		execute a:cmd
		redir END
	endif
	vnew
	let w:scratch = 1
	setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
	call setline(1, split(output, "\n"))
endfunction

command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Settings for Vimwiki
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

nnoremap <leader>tt :VimwikiTable<CR>
nnoremap <leader>wg :VimwikiGoto 
nnoremap <leader>wT :VimwikiSearchTags 
nnoremap <leader>i I- <esc>l
nnoremap <leader>I :s/^[ ]*- \(\[.\] \)*//<CR>
nmap <leader>D dd:VimwikiMakeDiaryNote<CR>Gp:w!<CR>:Bclose<CR>
vnoremap <leader>D d:VimwikiMakeDiaryNote<CR>Gp:w!<CR>
let g:vimwiki_list = [{
    \ 'path': '~/vimwiki/', 
    \ 'syntax': 'markdown', 
    \ 'ext': '.md',
    \ }]

" Git push quietly whenever leaving vim with VimWiki files
augroup vimwikiPush
  autocmd!
  autocmd VimLeave ~/vimwiki/* :!(cd ~/vimwiki && git add * && git commit -am Update && git push origin >/dev/null 2>&1 &)
augroup END

" Configuration fro vim-instant-markdown
let g:instant_markdown_autostart = 0
nnoremap <leader>md :InstantMarkdownPreview<CR>    

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Settings for Blog
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Generate static pages
augroup blogRebuild
  autocmd!
  autocmd BufWritePost ~/blog/*.md :!cd ~/blog && hugo >/dev/null
augroup END

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" =>  Redirect the output of a Vim or external command into a scratch buffer 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Copy from : https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7
" 
" Usage:
" 	:Redir hi ............. show the full output of command ':hi' in a scratch window
" 	:Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window

function! Redir(cmd)
	for win in range(1, winnr('$'))
		if getwinvar(win, 'scratch')
			execute win . 'windo close'
		endif
	endfor
	if a:cmd =~ '^!'
		let output = system(matchstr(a:cmd, '^!\zs.*'))
	else
		redir => output
		execute a:cmd
		redir END
	endif
	vnew
	let w:scratch = 1
	setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
	call setline(1, split(output, "\n"))
endfunction

command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
nnoremap <leader>r :Redir 


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Make Alt key works on Gnome terminal
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Solution is here: https://stackoverflow.com/questions/6778961

let c='a'
while c <= 'z'
  exec "set <A-".c.">=\e".c
  exec "imap \e".c." <A-".c.">"
  let c = nr2char(1+char2nr(c))
endw
set timeout ttimeoutlen=50
 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => vim-racer
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set hidden
let g:racer_cmd = "~/.cargo/bin/racer"
let g:racer_experimental_completer = 1

autocmd FileType rust nmap gd <Plug>(rust-def)
autocmd FileType rust nmap gs <Plug>(rust-def-split)
autocmd FileType rust nmap gx <Plug>(rust-def-vertical)
autocmd FileType rust nmap <leader>gd <Plug>(rust-doc)

 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => vim-plug
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" run :PlugInstall to install plugins

call plug#begin('~/.vim/plugged')

" Add indent line
Plug 'Yggdroot/indentLine'
Plug 'mileszs/ack.vim'
Plug 'tpope/vim-surround'
"Plug 'lifepillar/pgsql.vim'
Plug 'vimwiki/vimwiki'
"Plug 'iberianpig/tig-explorer.vim'
Plug 'rust-lang/rust.vim'
"Plug 'racer-rust/vim-racer'
"Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
Plug 'junegunn/fzf.vim'
Plug 'michal-h21/vim-zettel'
Plug 'rlue/vim-barbaric'
Plug 'nathangrigg/vim-beancount'

" Initialize plugin system
call plug#end()

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => lf
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use lf as file selector
function! LF()
    let temp = tempname()
    exec 'silent !lf -selection-path=' . shellescape(temp)
    if !filereadable(temp)
        redraw!
        return
    endif
    let names = readfile(temp)
    if empty(names)
        redraw!
        return
    endif
    exec 'edit ' . fnameescape(names[0])
    for name in names[1:]
        exec 'argadd ' . fnameescape(name)
    endfor
    redraw!
endfunction
command! -bar LF call LF()
" Override NERDTree comes with amix/vimrc
map <leader>nn :LF<cr>