-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathleadermap.vim
183 lines (169 loc) · 5.34 KB
/
leadermap.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
" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{,}} foldmethod=marker foldlevel=0:
let g:mapleader = ','
" basic {{
" Edit file in current file folder
nnoremap <leader>n :Lexplore<CR>
nnoremap <leader>q :silent! Bdelete!<CR>
nnoremap <leader>e :e <C-R>=substitute(expand('%:p:h').'/', getcwd().'/', '', '')<CR>
nnoremap <leader>v :vs <C-R>=substitute(expand('%:p:h').'/', getcwd().'/', '', '')<CR>
nnoremap <leader>t :tabe <C-R>=substitute(expand('%:p:h').'/', getcwd().'/', '', '')<CR>
nnoremap <leader>rm :Rm <C-R>=expand('%:p:h').'/'<CR>
nnoremap <leader>mk :Mkdir <C-R>=expand('%:p:h').'/'<CR>
" Replace all of current word
nnoremap <leader>s :%s/\<<C-r><C-w>\>//g<left><left>
" Reload vimrc file
nnoremap <leader>rl :source ~/.vimrc<CR>
" Search with grep
nnoremap <leader>/ :Rg<space>
" generate doc
nnoremap <silent> <leader>d :<C-u>call <SID>GenDoc()<CR>
" clean some dirty charactors
nnoremap <silent> <leader>cl :<C-u>call <SID>Clean()<CR>
" show vim highlight group under cursor
nnoremap <leader>hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
nnoremap <silent> <leader>pp "0p
nnoremap <silent> <leader>o :call <SID>Open()<CR>
" }}
" setting switch {{
nnoremap <leader>sc :setl spell!<CR>
nnoremap <leader>pt :set paste!<CR>
nnoremap <leader>nu :call <SID>NumberToggle()<CR>
nnoremap <leader>bg :call <SID>ToggleBackground()<CR>
" }}
" plugin {{
"session helper
nmap <leader>ss :call <SID>SessionSave()<CR>
nmap <leader>sl :<C-u>SessionLoad
nmap <leader>sr :call <SID>SessionReload()<CR>
" svg.vim not used very often
nmap <leader>se <Plug>SvgEdit
" coc.nvim
nmap <leader>x <Plug>(coc-cursors-operator)
nmap <leader>rn <Plug>(coc-rename)
nmap <leader>rf <Plug>(coc-refactor)
nmap <leader>ca <Plug>(coc-codelens-action)
xmap <leader>x <Plug>(coc-convert-snippet)
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>ac <Plug>(coc-codeaction-line)
nmap <leader>af <Plug>(coc-codeaction)
nmap <leader>di <Plug>(coc-diagnostic-info)
nmap <leader>qf <Plug>(coc-fix-current)
nmap <leader>te :call CocAction('runCommand', 'jest.singleTest')<CR>
nmap <leader>dr <Plug>(coc-diagnostic-related)
nmap <leader>ms <Plug>(coc-menu-show)
nmap <silent> <Leader>tr <Plug>(coc-translator-p)
" }}
" grep by motion {{
vnoremap <leader>g :<C-u>call <SID>GrepFromSelected(visualmode())<CR>
nnoremap <leader>g :<C-u>set operatorfunc=<SID>GrepFromSelected<CR>g@
function! s:GrepFromSelected(type)
let saved_unnamed_register = @@
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[v`]y
else
return
endif
let word = substitute(@@, '\n$', '', 'g')
let word = escape(word, '| ')
let @@ = saved_unnamed_register
execute 'CocList grep '.word
endfunction
" }}
" functions {{
function! s:SessionSave()
if !empty(v:this_session)
execute 'SessionSave'
else
call feedkeys(':SessionSave ')
endif
endfunction
function! s:ToggleBackground()
if &background ==# 'light'
set background=dark
else
set background=light
endif
call SetStatusLine()
endfunction
function! s:NumberToggle()
if(&number == 1) | set nu! | set rnu! | else | set rnu | set nu | endif
endfunction
function! s:SessionReload()
execute 'wa'
execute 'RestartVim'
endfunction
" Simple clean utility
function! s:Clean()
let view = winsaveview()
let ft = &filetype
" replace tab with 2 space
if index(['javascript', 'html', 'css', 'vim', 'php'], ft) != -1
silent! execute "%s/\<tab>/ /g"
endif
" replace tailing comma
if ft ==# 'javascript' || ft ==# 'typescript'
silent! execute '%s/;$//'
endif
" remove tailing white space
silent! execute '%s/\s\+$//'
" remove windows `\r`
call winrestview(view)
endfunction
function! s:GenDoc()
if &ft ==# 'javascript' || &ft ==# 'typescript'
exe "JsDoc"
elseif &ft ==# 'css'
let lines = ['/*', ' * ', ' */']
exe "normal! j?{$\<CR>:noh\<CR>"
let lnum = getpos('.')[1]
call append(lnum - 1, lines)
exe "normal! kk$"
startinsert!
elseif &ft ==# 'html'
let lnum = getpos('.')[1]
let ind = matchstr(getline('.'), '\v\s*')
call append(lnum - 1, ind . '<!-- -->')
exe "normal! k^Ell"
startinsert
elseif &filetype ==# 'vim'
let lnum = getpos('.')[1]
let ind = matchstr(getline('.'), '\v\s*')
call append(lnum - 1, ind . '" ')
exe "normal! k$"
startinsert!
else
let lnum = getpos('.')[1]
let ind = matchstr(getline('.'), '\v\s*')
call append(lnum - 1, ind. '# ')
exe "normal! k$"
startinsert!
endif
endfunction
function! s:Open()
let res = CocAction('openLink')
if res | return | endif
let line = getline('.')
" match url
let url = matchstr(line, '\vhttps?:\/\/[^)\]''" ]+')
if !empty(url)
let output = system('open '. url)
else
let mail = matchstr(line, '\v([A-Za-z0-9_\.-]+)\@([A-Za-z0-9_\.-]+)\.([a-z\.]+)')
if !empty(mail)
let output = system('open mailto:' . mail)
else
let output = system('open ' . expand('%:p:h'))
endif
endif
if v:shell_error && output !=# ""
echoerr output
endif
endfunction
" }}