-
Notifications
You must be signed in to change notification settings - Fork 0
/
mappings.vim
261 lines (218 loc) · 7.29 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
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
set winaltkeys=no " Do not allow Alt keys to open menues
" Don't map the <Leader> directly to <Space> like this:
" let mapleader = "\<Space>"
" nnoremap \ <Leader>
" Doing it the following way it shows the Backslash in the showcmd corner
map <Space> \
" Move through wrapped lines
silent! nnoremap <up> gk
silent! nnoremap <down> gj
nnoremap j gj
nnoremap k gk
nnoremap <home> g^
nnoremap <end> g$
nnoremap gl g$
nnoremap gh g^
" Identify the syntax highlighting group used at the cursor
nnoremap <Leader>p :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<cr>
" Use Y like C and D
nnoremap Y y$
nnoremap ci2 ci"
nnoremap ca2 ca"
nnoremap di2 di"
nnoremap da2 da"
nnoremap yi2 yi"
nnoremap ya2 ya"
" Visually select current line without line ending
nnoremap _ ^vg_
" Search and replace selected text
vnoremap <leader>R "ay:%s/<C-R>a//g<Left><Left>
" Tabs
nnoremap <Leader>tt <esc>:tabnew<cr>
nnoremap <Leader>j <esc>gt
nnoremap <Leader>k <esc>gT
nnoremap gr gT
nnoremap <M-1> 1gt
nnoremap <M-2> 2gt
nnoremap <M-3> 3gt
nnoremap <M-4> 4gt
nnoremap <M-5> 5gt
nnoremap <M-6> 6gt
nnoremap <M-7> 7gt
nnoremap <M-8> 8gt
nnoremap <M-9> 9gt
nnoremap <M-0> 10gt
" Omni completion
inoremap <C-Space> <C-X><C-O>
"
" Toggle hlsearch
nnoremap <silent> <Leader>h <esc>:set hlsearch!<cr>
" Toggle relativenumber
nnoremap <silent> <Leader>r <esc>:set relativenumber!<cr>
" Toggle wrapping
nnoremap <Leader>w <esc>:set wrap! wrap?<cr>
" Toggle invisibles
noremap <Leader>i :set list!<cr>
" sudo save
command W w !sudo tee % > /dev/null
" spell
command SpellEnglish set spell spelllang=en
command SpellGerman set spell spelllang=de
command SpellOff set nospell
" Change size of windows
noremap <Leader>> 20<C-w>>
noremap <Leader>< 20<C-w><
noremap <Leader>+ 5<C-w>+
noremap <Leader>- 5<C-w>-
" Center search matches
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
noremap <C-O> <C-O>zz
noremap <C-I> <C-I>zz
" Easy navigation in Quickfix window
function! ToggleQuickFix()
if empty(filter(getwininfo(), 'v:val.quickfix'))
botright copen 15
else
cclose
endif
endfunction
nnoremap <silent> <F2> :call ToggleQuickFix()<cr>
nnoremap <silent> <C-F3> :call ToggleQuickFix()<cr>
nnoremap <F3> :cnext<cr>
if has("gui_running")
nnoremap <S-F3> :cprevious<cr>
else
nnoremap <F15> :cprevious<cr>
endif
" Easy navigation in Location List
nnoremap <F4> :lnext<cr>zz
nnoremap <C-F4> :botright lopen 15<cr>
if has("gui_running")
nnoremap <S-F4> :lprevious<cr>zz
else
nnoremap <F16> :lprevious<cr>zz
endif
" Run last macro
nnoremap Q @@
" Double the number of leading spaces
nnoremap <Leader>ds :%s/^\s*/&&<cr>
vnoremap <Leader>ds :s/^\s*/&&<cr>
" Execute macros over visual range
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<cr>
function! ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction
" Picon
command! Picon exe 'normal m`' | silent! undojoin | exe '%!picon -a' | exe 'normal ``'
nnoremap <Leader>o <esc>:Picon<cr><cr>
" Navigate with +/= and - between changes and center change on screen
" Catch the transition to diff mode
au FilterWritePre * if &diff | exe 'noremap = ]cz.' | exe 'noremap + ]cz.' | exe 'noremap - [cz.' | exe 'noremap U :diffupdate<cr>' | endif
au FilterWritePre * if &diff | exe 'execute "normal zR"' | endif
" au FilterWritePre * if &diff | exe 'set diffopt=filler,context:1000' | exe 'execute "normal \<c-w>\<c-w>"' | endif
" Silent grep
function! Grp(args)
execute "silent! :botright :grep " . a:args
endfunction
command! -nargs=* -complete=file Grep call Grp(<q-args>)
command! -nargs=* -complete=file Ag call Grp(<q-args>)
command! -nargs=* -complete=file AG call Grp(<q-args>)
command! -nargs=* -complete=file Rg call Grp(<q-args>)
if has('win32')
nnoremap <silent> <C-h> <C-w>h
nnoremap <silent> <C-j> <C-w>j
nnoremap <silent> <C-k> <C-w>k
nnoremap <silent> <C-l> <C-w>l
nnoremap <silent> <M-h> <C-w>h
nnoremap <silent> <M-j> <C-w>j
nnoremap <silent> <M-k> <C-w>k
nnoremap <silent> <M-l> <C-w>l
else
nnoremap <silent> <M-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <M-j> :TmuxNavigateDown<cr>
nnoremap <silent> <M-k> :TmuxNavigateUp<cr>
nnoremap <silent> <M-l> :TmuxNavigateRight<cr>
nnoremap <silent> <M-\> :TmuxNavigatePrevious<cr>
endif
" Neovim
if has('nvim')
" Make escape work in the Neovim terminal.
tnoremap <Esc> <C-\><C-n>
" CONFLICTS with fzf
" Make navigation into and out of Neovim terminal splits nicer.
if has('unix')
tnoremap <C-h> <C-\><C-n><C-w>h
endif
tnoremap <C-j> <C-\><C-n><C-w>j
tnoremap <C-k> <C-\><C-n><C-w>k
tnoremap <C-l> <C-\><C-n><C-w>l
tnoremap <M-h> <C-\><C-n><C-w>h
tnoremap <M-j> <C-\><C-n><C-w>j
tnoremap <M-k> <C-\><C-n><C-w>k
tnoremap <M-l> <C-\><C-n><C-w>l
nnoremap <Leader>v :vsplit<bar>terminal<cr>
nnoremap <Leader>s :split<bar>terminal<cr>
nnoremap <Leader>x :terminal<cr>
" Open terminal and run ptpython
nmap <Leader>py <C-w>v:terminal<cr>ptpython<cr><C-\><C-n><C-w>p
" Evaluate anything from the visual mode in the next window
vmap <buffer> <Leader>e y<C-w>wpi<cr><C-\><C-n><C-w>p
" Evaluate outer most form
nmap <buffer> <Leader>e ^v%y<C-w>wpi<cr><C-\><C-n><C-w>p
" Evaluate buffer"
nmap <buffer> <Leader>b ggVGy<C-w>wpi<cr><C-\><C-n><C-w>p
endif
" Format json
command Jsonify %!python3 -m json.tool
command Tidy !tidy -mi -html -wrap 0 %
" UndoTree
noremap <F5> :UndotreeToggle<cr>
" signify
noremap <silent> <F6> <Esc>:SignifyToggle<cr>
" Rainbow Paranthesis
noremap <silent> <F7> :RainbowToggle<cr>
" Nerd Tree
noremap <silent> <F8> :NERDTreeToggle<cr>
" BufExplorer
noremap <silent> <F9> :BufExplorer<cr>
" TagBar
noremap <silent> <F10> <Esc>:TagbarToggle<cr>
" FZF
":
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', 'cat {}']}, <bang>0)
command! -bang -nargs=? -complete=dir GitFiles
\ call fzf#vim#gitfiles(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', 'cat {}']}, <bang>0)
nnoremap <silent> <M-r> <Esc>:FZRg<cr>
nnoremap <silent> <M-c> <Esc>:FZCommit<cr>
nnoremap <silent> <M-t> <Esc>:FZTags<cr>
nnoremap <silent> <M-p> <Esc>:FZFiles<cr>
nnoremap <silent> <M-b> <Esc>:FZBuffers<cr>
nnoremap <silent> <C-p> <Esc>:GitFiles<cr>
" Git: fugitive / git-messenger
nmap <silent> <Leader>gs <Esc>:Git<cr>gg<C-n>
noremap <silent> <Leader>gp <Esc>:Gpush<cr>
noremap <silent> <Leader>gb <Esc>:Gblame<cr>
noremap <silent> <Leader>gd <Esc>:Gvdiff<cr>
noremap <silent> <Leader>gm <Esc><Plug>(git-messenger)
" NERDCommenter
nnoremap gm :call nerdcommenter#Comment("n", "Comment")<cr>
vnoremap gm :call nerdcommenter#Comment("v", "Comment")<cr>
nnoremap gs :call nerdcommenter#Comment("n", "Invert")<cr>
vnoremap gs :call nerdcommenter#Comment("v", "Invert")<cr>
" '<C-_>', -- <C-_> means <c-/> -- see :help :map-special-keys
nnoremap <C-_> :call nerdcommenter#Comment("n", "Invert")<cr>
vnoremap <C-_> :call nerdcommenter#Comment("v", "Invert")<cr>
"" FOR WSL ONLY
if has('wsl')
augroup WSLYank
autocmd!
autocmd TextYankPost * :call system('clip.exe ',@")
augroup END
end