-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremaps.vim
More file actions
257 lines (212 loc) · 7.67 KB
/
Copy pathremaps.vim
File metadata and controls
257 lines (212 loc) · 7.67 KB
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
" ++++++++++++++++++++++++************************
" Remap leader key
" ++++++++++++++++++++++++************************
nnoremap <SPACE> <Nop>
let mapleader = " "
let maplocalleader = "-"
" ++++++++++++++++++++++++************************
" ctags mappings
" ++++++++++++++++++++++++************************
" nnoremap <leader>l <C-]>
" nnoremap <leader>h <C-t>
" nnoremap <silent><leader>t :e #<CR>
" nnoremap <silent><Leader>L :cs find s <C-R>=expand("<cword>")<CR><CR>
" ++++++++++++++++++++++++************************
" Browser search mappings
" ++++++++++++++++++++++++************************
nmap <silent> <Leader>w <Plug>SearchNormal<CR>
vmap <silent> <Leader>w <Plug>SearchVisual<CR>
" ++++++++++++++++++++++++************************
" Terminal mappings
" ++++++++++++++++++++++++************************
" function! SwitchToTerminalBuffer()
" " Get list of all open buffers
" let buffers = range(1, bufnr('$'))
" let terminal_buffers = []
" " Collect only terminal buffers
" for buf in buffers
" if getbufvar(buf, "&buftype") == "terminal"
" call add(terminal_buffers, buf)
" endif
" endfor
" " If no terminal buffer is found, show a message and return
" if empty(terminal_buffers)
" terminal
" return
" endif
" " Cycle through windows and find the first terminal buffer
" let startwin = winnr()
" while 1
" wincmd w
" if index(terminal_buffers, bufnr('%')) >= 0
" break
" endif
" if winnr() == startwin
" echom "No terminal buffer found"
" break
" endif
" endwhile
" endfunction
" if has('nvim')
" tnoremap <esc> <C-\><C-n>
" nmap <leader>tt :sp <CR> :term<CR> :set nonu<CR> :set nornu<CR> i
" else
" nnoremap <silent><Leader>tt :call SwitchToTerminalBuffer()<CR>
" endif
if has('nvim')
tnoremap <esc> <C-\><C-n>
nmap <leader>tt :sp <CR> :term<CR> :set nonu<CR> :set nornu<CR> i
else
nnoremap <silent><Leader>tt :ter<CR>
endif
" Map it to <Leader>t
" ++++++++++++++++++++++++************************
" Build mappings
" ++++++++++++++++++++++++************************
au FileType c nnoremap <leader>cm :CMake<CR>
au FileType cpp nnoremap <leader>cm :CMake<CR>
au FileType c nnoremap <leader>ma :Make<CR>
au FileType cpp nnoremap <leader>ma :Make<CR>
au FileType rust nnoremap <leader>ru :RustRun <CR>
nnoremap <leader>as :Disassemble
" ++++++++++++++++++++++++************************
" Diff mappings
" ++++++++++++++++++++++++************************
nnoremap <leader>dt :windo diffthis <CR>
nnoremap <leader>do :windo diffoff <CR>
au FileType diff nnoremap <leader>ct :ConflictTake<CR>
" ++++++++++++++++++++++++************************
" Man mappings
" ++++++++++++++++++++++++************************
func! GetSelectedText()
normal gv"xy
let result = getreg("x")
normal gv
return result
endfunc
nnoremap <leader>m <Plug>(Man)
nnoremap <leader>v <Plug>(Vman)
vnoremap <leader>m :call man#get_page('horizontal', GetSelectedText())<CR>
" ++++++++++++++++++++++++************************
" Learn vimscript the hard way mappings
" ++++++++++++++++++++++++************************
" Easily delete LINES IN INSERT MODE
inoremap <c-d> <esc>ddi
" Quick editing of config files
nnoremap <leader>ec :vsplit $VIMHOME/commands.vim<cr>
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>er :vsplit $VIMHOME/remaps.vim<cr>
nnoremap <leader>em :vsplit $VIMHOME/miscellaneous.vim<cr>
nnoremap <leader>ep :vsplit $VIMHOME/pluginlist.vim<cr>
nnoremap <leader>et :vsplit $VIMHOME/themeconfig.vim<cr>
nnoremap <leader>ec :vsplit $VIMHOME/commands.vim<cr>
nnoremap <leader>ea :vsplit $VIMHOME/autocommands.vim<cr>
nnoremap <leader>ef :vsplit $VIMHOME/fernrc.vim<cr>
nnoremap <leader>ey :vsplit $VIMHOME/ycmrc.vim<cr>
nnoremap <leader>ed :vsplit $VIMHOME/vimspectorrc.vim<cr>
nnoremap <leader>el :vsplit $VIMHOME/lsp.vim<cr>
nnoremap <leader>elp :vsplit $VIMHOME/lsp<cr>
nnoremap <leader>es :vsplit $VIMHOME/cSpell.json<cr>
" Swap lines beautifully
function! s:swap_lines(n1, n2)
let line1 = getline(a:n1)
let line2 = getline(a:n2)
call setline(a:n1, line2)
call setline(a:n2, line1)
endfunction
function! s:swap_up()
let n = line('.')
if n == 1
return
endif
call s:swap_lines(n, n - 1)
exec n - 1
endfunction
function! s:swap_down()
let n = line('.')
if n == line('$')
return
endif
call s:swap_lines(n, n + 1)
exec n + 1
endfunction
function ActivateBlockNavigation()
" Don't activate in these filetypes
if &ft =~ 'git|qf'
return
endif
nnoremap <silent> <C-k> :call <SID>swap_up()<CR>
nnoremap <silent> <C-j> :call <SID>swap_down()<CR>
nnoremap <silent> <C-h> <<
nnoremap <silent> <C-l> >>
" Move visual blocks in all directions
vnoremap <silent> <C-j> :m '>+1<CR>gv
vnoremap <silent> <C-k> :m '<-2<CR>gv
vnoremap <silent> <C-h> <gv
vnoremap <silent> <C-l> >gv
endfun
autocmd filetype * call ActivateBlockNavigation()
" Use same mapping as navigation in the quickfix list
if has_key(plugs, 'vim-unimpaired')
autocmd filetype git nnoremap <buffer> <silent> <C-j> :cnext<CR>
autocmd filetype git nnoremap <buffer> <silent> <C-k> :cprevious<CR>
autocmd filetype qf nnoremap <buffer> <silent> <C-j> :cnext<CR>
autocmd filetype qf nnoremap <buffer> <silent> <C-k> :cprevious<CR>
endif
"Easily add quotes
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
" ++++++++++++++++++++++++************************
" Miscellaneous mappings
" ++++++++++++++++++++++++************************
nnoremap <leader>rt :RainbowToggle<CR>
nnoremap <leader>ab :tabe $VIMHOME/after/plugin/abolish.vim <CR>
nnoremap <leader>nn :set rnu! <CR>
nnoremap <leader>ll :set list! <CR>
nnoremap <leader>rb :RainbowToggle <CR>
nnoremap <leader>fi :Files<CR>
nnoremap <F2> :call CurtineIncSw()<CR>
nnoremap <Leader>pp :H2cppxAuto<CR>
" Change word under cursor to random number
nnoremap <leader>rnd ciw<c-r>=system('perl -e "printf(qq[%02d], int(rand(60 - 0)))"')<CR><esc>
" ++++++++++++++++++++++++************************
" Quick editing of config files
" ++++++++++++++++++++++++************************
nnoremap <leader>ea :vsplit $VIMHOME/autocommands.vim<CR>
nnoremap <leader>ec :vsplit $VIMHOME/commands.vim<CR>
nnoremap <leader>ed :vsplit $VIMHOME/vimspectorrc.vim<CR>
nnoremap <leader>ef :vsplit $VIMHOME/fernrc.vim<CR>
nnoremap <leader>elc :vsplit $VIMHOME/lsp.vim<CR>
nnoremap <leader>elp :vsplit $VIMHOME/lsp<CR>
nnoremap <leader>em :vsplit $VIMHOME/miscellaneous.vim<CR>
nnoremap <leader>ep :vsplit $VIMHOME/pluginlist.vim<CR>
nnoremap <leader>er :vsplit $VIMHOME/remaps.vim<CR>
nnoremap <leader>et :vsplit $VIMHOME/themeconfig.vim<CR>
nnoremap <leader>ev :vsplit $MYVIMRC<CR>
nnoremap <leader>ey :vsplit $VIMHOME/ycmrc.vim<CR>
ino <C-A> <C-O>yiW<End>=<C-R>=<C-R>0<CR>
function! ScrollPopup(nlines)
let winids = popup_list()
if len(winids) == 0
return
endif
" Ignore hidden popups
let prop = popup_getpos(winids[0])
if prop.visible != 1
return
endif
let firstline = prop.firstline + a:nlines
let buf_lastline = str2nr(trim(win_execute(winids[0], "echo line('$')")))
if firstline < 1
let firstline = 1
elseif prop.lastline + a:nlines > buf_lastline
let firstline = buf_lastline + prop.firstline - prop.lastline
endif
call popup_setoptions(winids[0], {'firstline': firstline})
endfunction
nnoremap <silent> ö :call ScrollPopup(3)<CR>
nnoremap <silent> ü :call ScrollPopup(-3)<CR>
if has_key(plugs, 'tabular')
nnoremap <Leader>tc :Tabularize /\/\*<CR>
vnoremap <Leader>tc :Tabularize /\/\*<CR>
endif