-
Notifications
You must be signed in to change notification settings - Fork 12
/
mappings.vim
221 lines (182 loc) · 5.36 KB
/
mappings.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
let mapleader=","
" Telescope {{{
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope git_files<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
nnoremap <leader>fr <cmd>Telescope live_grep<cr>
" }}}
" General {{{
" Window prefix
nnoremap [Window] <Nop>
nmap W [Window]
" Start an external command with a single bang
nnoremap ! :!
" Allow misspellings when :wq
cabbrev Wq :wq
cabbrev qw :wq
cabbrev Qa :qa
" When pressing <leader>cd switch to the directory of the open buffer
map <Leader>cd :cd %:p:h<CR>:pwd<CR>
" Fast saving
nnoremap <Leader>w :w<CR>
vnoremap <Leader>w <Esc>:w<CR>
nnoremap <C-s> :<C-u>w<CR>
vnoremap <C-s> :<C-u>w<CR>
cnoremap <C-s> <C-u>w<CR>
" https://github.com/Shougo/shougo-s-github
nnoremap <silent> [Window]p :<C-u>call <SID>split_nicely()<CR>
nnoremap <silent> [Window]v :<C-u>split<CR>
nnoremap <silent> [Window]g :<C-u>vsplit<CR>
nnoremap <silent> [Window]t :enew<CR>
nnoremap <silent> [Window]o :<C-u>only<CR>
nnoremap <silent> [Window]D :<C-u>call <SID>CustomBufferDelete()<CR>
nnoremap <silent> [Window]x :<C-u>call <SID>CustomBufferDeleteNew()<CR>
nnoremap <silent> [Window]q :close<CR>
nnoremap <silent> [Window]Q :bdelete<CR>
nnoremap <silent> [Window]\ :b#<CR>
nnoremap <silent> [Window]c :<C-u>call <SID>smart_close()<CR>
nnoremap <silent> <Tab> :BufferLineCycleNext<CR>
nnoremap <silent> <S-Tab> :BufferLineCyclePrev<CR>
" Split current buffer, go to previous window and previous buffer
nnoremap <Leader>sv :split<CR>:wincmd p<CR>:e#<CR>
nnoremap <Leader>sg :vsplit<CR>:wincmd p<CR>:e#<CR>
function! s:smart_close() "
if winnr('$') != 1
close
else
call s:alternate_buffer()
endif
endfunction "}}}
function! s:split_nicely() "
if winwidth(0) > 2 * &winwidth
vsplit
else
split
endif
wincmd p
endfunction "}}}
function! s:CustomBufferDelete() "
let l:current = bufnr('%')
call s:alternate_buffer()
silent! execute 'bdelete '.l:current
endfunction "}}}
function! s:CustomBufferDeleteNew() "
let l:current = bufnr('%')
if getbufvar(l:current, '&modified')
return
endif
enew
silent! execute 'bdelete '.l:current
endfunction "}}}
function! s:alternate_buffer() "
let l:listed_buffer_len = len(filter(range(1, bufnr('$')),
\ 's:buflisted(v:val) && getbufvar(v:val, "&filetype") !=# "unite"'))
if l:listed_buffer_len <= 1
enew
return
endif
let cnt = 0
let pos = 1
let current = 0
while pos <= bufnr('$')
if s:buflisted(pos)
if pos == bufnr('%')
let current = cnt
endif
let cnt += 1
endif
let pos += 1
endwhile
if current > cnt / 2
bprevious
else
bnext
endif
endfunction "}}}
function! s:buflisted(bufnr) "
return exists('t:unite_buffer_dictionary') ?
\ has_key(t:unite_buffer_dictionary, a:bufnr) && buflisted(a:bufnr) :
\ buflisted(a:bufnr)
endfunction
" Select last paste
nnoremap <expr> gp '`['.strpart(getregtype(), 0, 1).'`]'
" Disable EX mode
nnoremap Q <Nop>
nnoremap gQ <Nop>
" Select blocks after indenting
xnoremap < <gv
xnoremap > >gv|
" Use tab for indenting in visual mode
vnoremap <Tab> >gv|
vnoremap <S-Tab> <gv
nnoremap > >>_
nnoremap < <<_
"}}}
" GundoTree {{{
nnoremap <Leader>gu :GundoToggle<CR>
" }}}
" Coc {{{
nnoremap <leader>co <cmd>CocAction<cr>
vnoremap <leader>co <cmd>CocAction<cr>
" Navigate snippet placeholders using tab
let g:coc_snippet_next = '<Tab>'
let g:coc_snippet_prev = '<S-Tab>'
" list of the extensions to make sure are always installed
let g:coc_global_extensions = [
\'coc-yank',
\'coc-json',
\'coc-css',
\'coc-html',
\'coc-yaml',
\'coc-lists',
\'coc-snippets',
\'coc-pyright',
\'coc-clangd',
\'coc-xml',
\'coc-syntax',
\'coc-highlight',
\'coc-sh',
\]
" check if last inserted char is a backspace (used by coc pmenu)
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" show docs on things with K
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" use tab to navigate snippet placeholders
inoremap <silent><expr> <TAB>
\ pumvisible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump', ''])\<CR>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" Use enter to accept snippet expansion
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<CR>"
" coc completion popup
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif
" format with available file format formatter
command! -nargs=0 Format :call CocAction('format')
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" }}}
" ChooseWin {{{
nmap - <Plug>(choosewin)
" }}}
" OSC Yank {{{
vnoremap <leader>c :OSCYank<CR>
nmap <leader>o <Plug>OSCYank
" }}}