-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmappings.vim
279 lines (216 loc) · 7.51 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
" ----------------------------------------
" Mappings
" ----------------------------------------
" Set leader to ,
" Note: This line MUST come before any <leader> mappings
let mapleader=','
let maplocalleader = ' '
" -----------------------
" Unmapped While Learning
" -----------------------
" " No-op ^ and $ while learning H and L
" noremap ^ <nop>
" noremap $ <nop>
nnoremap <leader>sc <nop>
" ---------------
" Regular Mappings
" ---------------
" Use ; for : in normal and visual mode, less keystrokes
" nnoremap ; :
" vnoremap ; :
" Yank entire buffer with gy
nnoremap gy :0,$ y<cr>
" Select entire buffer
nnoremap vy ggVG
" Make Y behave like other capital commands.
" Hat-tip http://vimbits.com/bits/11
nnoremap Y y$
" Just to beginning and end of lines easier. From http://vimbits.com/bits/16
noremap H ^
noremap L $
" Create newlines without entering insert mode
nnoremap go o<Esc>k
nnoremap gO O<Esc>j
" remap U to <C-r> for easier redo
" from http://vimbits.com/bits/356
nnoremap U <C-r>
" Swap implementations of ` and ' jump to markers
" By default, ' jumps to the marked line, ` jumps to the marked line and
" column, so swap them
nnoremap ' `
nnoremap ` '
" Don't move on *
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" ---------------
" Window Movement
" ---------------
nnoremap <silent> gh :wincmd h<CR>
" nnoremap <silent> <M-h> :wincmd h<CR>
nnoremap <silent> gj :wincmd j<CR>
nnoremap <silent> gk :wincmd k<CR>
" nnoremap <silent> <M-k> :wincmd k<CR>
nnoremap <silent> gl :wincmd l<CR>
" nnoremap <silent> <M-l> :wincmd l<CR>
" 4 Window Splits
"
" -----------------
" g1 | g2 | g3 | g4
" -----------------
nnoremap <silent> g1 :wincmd t<CR>
nnoremap <silent> g2 :wincmd t<bar>:wincmd l<CR>
nnoremap <silent> g3 :wincmd t<bar>:wincmd l<bar>
\:wincmd l<CR>
nnoremap <silent> g4 :wincmd b<CR>
if version > 702
" Equal Size Windows
nnoremap <silent> g= :wincmd =<CR>
" Swap Windows
nnoremap <silent> gx :wincmd x<CR>
endif
" ---------------
" Modifer Mappings
" ---------------
" Make line completion easier.
inoremap <C-l> <C-x><C-l>
" Scroll larger amounts with C-j / C-k
nnoremap gj 15gjzz
nnoremap gk 15gkzz
vnoremap gj 15gjzz
vnoremap gk 15gkzz
" ---------------
" Insert Mode Mappings
" ---------------
" Let's make escape better, together.
inoremap jk <Esc>
inoremap JK <Esc>
inoremap Jk <Esc>
inoremap jK <Esc>
" ---------------
" Leader Mappings
" ---------------
" Clear search
noremap <silent><leader>/ :nohls<CR>:call clearmatches()<cr>
" Highlight search word under cursor without jumping to next
nnoremap <leader>h *<C-O>
" Toggle spelling mode
nnoremap <silent> <leader>sp :set spell!<CR>
" Quickly switch to last buffer
nnoremap <leader>, :e#<CR>
" Underline the current line with '-'
nnoremap <silent> <leader>ul :t.\|s/./-/\|:nohls<cr>
" Underline the current line with '='
nnoremap <silent> <leader>uul :t.\|s/./=/\|:nohls<cr>
" Surround the commented line with lines.
"
" Example:
" # Test 123
" becomes
" # --------
" # Test 123
" # --------
nnoremap <silent> <leader>cul :normal "lyy"lpwvLr-^"lyyk"lP<cr>
" Format the entire file
nnoremap <leader>fef mx=ggG='x
" Format a json file with Underscore CLI
" Inspirited by https://github.com/spf13/spf13-vim/blob/3.0/.vimrc#L390
nnoremap <leader>fj <Esc>:%!underscore print<CR><Esc>:set filetype=json<CR>
" Split window vertically or horizontally *and* switch to the new split!
nnoremap <silent> <leader>hs :split<Bar>:wincmd j<CR>:wincmd =<CR>
nnoremap <silent> <leader>vs :vsplit<Bar>:wincmd l<CR>:wincmd =<CR>
" Close the current window
nnoremap <silent> <m-w> :close<CR>
" ---------------
" Typo Fixes
" ---------------
noremap <F1> <Esc>
inoremap <F1> <Esc>
cnoremap w' w<CR>
" Disable the ever-annoying Ex mode shortcut key. Type visual my ass. Instead,
" make Q repeat the last macro instead. *hat tip* http://vimbits.com/bits/263
nnoremap Q @@
" Removes doc lookup mapping because it's easy to fat finger and never useful.
" nnoremap K k
" vnoremap K k
" Toggle paste mode with F6
" nnoremap <silent> <F6> :set paste!<CR>
" Paste and select pasted
nnoremap <expr> gpp '`[' . strpart(getregtype(), 0, 1) . '`]'
" Insert date
iabbrev ddate <C-R>=strftime("%Y-%m-%d")<CR>
" Map f5 to change current buffers working directory to
" match the file being edited
nnoremap <F5> :lcd %:p:h<CR>:pwd<CR>
" Merging, accept remote
nnoremap <F8> :diffget RE<CR>n
" Jump to next error
nnoremap <F9> :cnext<CR>
"--------------------
" Function: Open tag under cursor in new tab
" Source: http://stackoverflow.com/questions/563616/vimctags-tips-and-tricks
"--------------------
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
" copy current file name (relative/absolute) to system clipboard
" from http://stackoverflow.com/a/17096082/22423
if has('mac') || has('gui_macvim') || has('gui_mac')
" relative path (src/foo.txt)
nnoremap <silent> <leader>yp :let @*=expand("%")<CR>
" absolute path (/something/src/foo.txt)
nnoremap <silent> <leader>yP :let @*=expand("%:p")<CR>
" filename (foo.txt)
nnoremap <silent> <leader>yf :let @*=expand("%:t")<CR>
" directory name (/something/src)
nnoremap <silent> <leader>yd :let @*=expand("%:p:h")<CR>
endif
" --------------
" Highlight Word
" --------------
"
" This mini-plugin provides a few mappings for highlighting words temporarily.
"
" Sometimes you're looking at a hairy piece of code and would like a certain
" word or two to stand out temporarily. You can search for it, but that only
" gives you one color of highlighting. Now you can use <leader>N where N is
" a number from 1-6 to highlight the current word in a specific color.
function! HiInterestingWord(n)
" Save our location.
normal! mz
" Yank the current word into the z register.
normal! "zyiw
" Calculate an arbitrary match ID. Hopefully nothing else is using it.
let mid = 86750 + a:n
" Clear existing matches, but don't worry if they don't exist.
silent! call matchdelete(mid)
" Construct a literal pattern that has to match at boundaries.
let pat = '\V\<' . escape(@z, '\') . '\>'
" Actually match the words.
call matchadd("InterestingWord" . a:n, pat, 1, mid)
" Move back to our original location.
normal! `z
endfunction
function! UnHiWords()
silent! call matchdelete(86751)
silent! call matchdelete(86752)
silent! call matchdelete(86753)
silent! call matchdelete(86754)
silent! call matchdelete(86755)
silent! call matchdelete(86756)
endfunction
" Mappings
nnoremap <silent> <leader>1 :call HiInterestingWord(1)<cr>
nnoremap <silent> <leader>2 :call HiInterestingWord(2)<cr>
nnoremap <silent> <leader>3 :call HiInterestingWord(3)<cr>
nnoremap <silent> <leader>4 :call HiInterestingWord(4)<cr>
nnoremap <silent> <leader>5 :call HiInterestingWord(5)<cr>
nnoremap <silent> <leader>6 :call HiInterestingWord(6)<cr>
" remove all word highlights
nnoremap <silent> <leader>0 :call UnHiWords()<cr>
" Default Highlights
hi def InterestingWord1 guifg=#000000 ctermfg=16 guibg=#6c71c4 ctermbg=214
hi def InterestingWord2 guifg=#000000 ctermfg=16 guibg=#268bd2 ctermbg=154
hi def InterestingWord3 guifg=#000000 ctermfg=16 guibg=#2aa198 ctermbg=121
hi def InterestingWord4 guifg=#000000 ctermfg=16 guibg=#859900 ctermbg=137
hi def InterestingWord5 guifg=#000000 ctermfg=16 guibg=#cb4b16 ctermbg=211
hi def InterestingWord6 guifg=#000000 ctermfg=16 guibg=#dc322f ctermbg=195
" mappings for opening/closing nerdtree
nnoremap <silent><leader>nn :NERDTreeToggle<CR>:wincmd =<CR>
nnoremap <silent><leader>nf :NERDTreeFind<CR>:wincmd =<CR>