-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmapping.vim
More file actions
336 lines (271 loc) · 9.78 KB
/
mapping.vim
File metadata and controls
336 lines (271 loc) · 9.78 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
" vim: set foldmarker={{{,}}} foldlevel=0 foldmethod=marker tabstop=4 shiftwidth=4:
" Deactivate the help dialoge {{{
imap <F1> <ESC>
nmap <F1> <ESC>
vmap <F1> <ESC>
" }}}
"---------------------------------------------------------
" Useful mappings
"---------------------------------------------------------
" Don't use Ex mode, use Q for formatting
map Q gq
" Remember the cursor position while formating paragraph
nmap ,Q mzQap'z
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" Wrapped lines goes down/up to next row, rather than next line in file.
nnoremap j gj
nnoremap k gk
" Better mark jumping (line + col)
nnoremap ' `
" Note: You have to set in your bash_profile
" bind -r '\C-s'
" stty -ixon
map <C-s> <esc>:update<cr>
nnoremap Y y$
" visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
nnoremap / /\v
noremap S :%s//g<left><left>
nmap <expr> M ':%s/' . @/ . '//g<LEFT><LEFT>'
noremap <leader>s :s/
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
" Switch normal visual with visual-block mode
" nnoremap v <C-V>
" nnoremap <C-V> v
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
nnoremap <c-o> <c-o>zz
" Same when jumping between empty lines
nnoremap } }zz
nnoremap { {zz
" Indent without cursor position change
nnoremap <leader>i mzgg=G'z
" Easier to type, and I never use the default behavior.
noremap H ^
noremap L $
vnoremap L g_
" gi already moves to "last place you exited insert mode", so we'll map gI to
" something similar: move to last change
nnoremap gI `.
" Fold all regions except the visually selected one:
vnoremap <leader>h :<c-u>1,'<lt>-fold<bar>'>+,$fold<CR>
" You are too fast and keep pressing `shift' if you type :w, try following
":command! -bang W w<bang>
command! -bang -bar -nargs=? -complete=file -range=% W <line1>,<line2>w<bang> <args>
command! -bang Wq wq<bang>
command! -bang Q q<bang>
" disallow opening the commandline window which by default is bound to
" q: (I tend to usually mean :q)
" The commandline window is still accessible using q/ or q?
"noremap q: :q
" In help files, map Enter to follow tags
au filetype help set nonumber " no line numbers when viewing help
au filetype help nnoremap <buffer><cr> <c-]> " Enter selects subject
au filetype help nnoremap <buffer><bs> <c-T> " Backspace to go back
" toggle spelling with F12 key:
map <F12> :set spell!<CR><Bar>:echo "Spell Check: " . strpart("OffOn", 3 * &spell, 3)<CR>
" WINDOWS {{{
" Maps to make handling windows a bit easier
"
noremap <silent> <C-h> :wincmd h<CR>
noremap <silent> <C-j> :wincmd j<CR>
noremap <silent> <C-k> :wincmd k<CR>
noremap <silent> <C-l> :wincmd l<CR>
noremap <silent> <leader>= :wincmd =<CR>
noremap <silent> <C-F9> :vertical resize -5<CR>
noremap <silent> <C-F10> :resize -5<CR>
noremap <silent> <C-F11> :resize +5<CR>
noremap <silent> <C-F12> :vertical resize +5<CR>
noremap <silent> <leader>s8 :vertical resize 83<CR>
noremap <silent> <leader>cj :wincmd j<CR>:close<CR>
noremap <silent> <leader>ck :wincmd k<CR>:close<CR>
noremap <silent> <leader>ch :wincmd h<CR>:close<CR>
noremap <silent> <leader>cl :wincmd l<CR>:close<CR>
noremap <silent> <leader>cw :close<CR>
"noremap <silent> <leader>ml <C-W>L
"noremap <silent> <leader>mk <C-W>K
"noremap <silent> <leader>mh <C-W>H " same in ShowMarks
"noremap <silent> <leader>mj <C-W>J
" ,q to toggle quickfix window (where you have stuff like GitGrep)
" ,oq to open it back up (rare)
nmap <silent> <leader>qc :cclose<CR>
nmap <silent> <leader>qo :copen<CR>
" Create window splits easier. The default
" way is Ctrl-w,v and Ctrl-w,s. I remap
" this to vv and ss
nnoremap <silent> vv <C-w>v
nnoremap <silent> ss <C-w>s
nnoremap <silent> <leader>wo :ZoomWin<CR>
" }}}
" TABS {{{
" Maps to make handling windows a bit easier
"
nnoremap <C-t> <esc>:tabnew<CR>
nmap ]w :tabnext<cr>
nmap [w :tabprev<cr>
nmap ]b :bn<cr>
nmap [b :bp<cr>
nmap ,tc :tabclose<cr>
" }}}
" VIMRC {{{
" Edit the vimrc file
nnoremap <silent> <leader>ev :vsp ~/.vim/vimrc<CR>
nnoremap <silent> <leader>sv :so ~/.vim/vimrc<CR>
nmap <leader>em :e ~/.vim/mapping.vim<CR>
nnoremap <leader>ek :tabnew ~/.vim/memories<CR>
" }}}
" Copy & Paste {{{
fun! Copy()
normal "+ygv"*y
endf
vnoremap <C-c> :call Copy()<CR>
" Toggle paste mode
nnoremap <silent> <leader>p :set invpaste<CR>:set paste?<CR>
nnoremap <silent> <C-p> :set paste<cr>o<esc>"+]P:set nopaste<cr>"
" Copy line and comment out copied line
nnoremap yd yypkk:put =b:NERDCommenterDelims['left']<CR>==Jjb
" }}}
" Conversion {{{
" source: https://github.com/begriffs/dotfiles/blob/master/.vimrc
" Convert symbol to string
"nnoremap <silent> <leader>2s F:r"Ea"<ESC>
" Convert string to symbol
"nnoremap <silent> <leader>2y F"r:,x
" Convert name to snake_case
nmap <leader>2_ cr_
" Convert name to camelCase
nmap <leader>2c crc
" Convert name to MixedCase
nmap <leader>2m crm
" Convert name to SNAKE_UPPERCASE
nmap <leader>2u cru
" Convert name to dash-case
nmap <leader>2- cr-
" }}}
" Folding {{{
"nmap <leader>f0 :set foldlevel=0<CR>
"nmap <leader>f1 :set foldlevel=1<CR>
"nmap <leader>f2 :set foldlevel=2<CR>
"nmap <leader>f3 :set foldlevel=3<CR>
"nmap <leader>f4 :set foldlevel=4<CR>
nnoremap <space> za
" }}}
" Fix page up and down
map <PageUp> <C-U>
map <PageDown> <C-D>
imap <PageUp> <C-O><C-U>
imap <PageDown> <C-O><C-D>
" Duplicate a selection
" Visual mode: D
vmap D y'>p
"---------------------------------------------------------
" From Derek
"---------------------------------------------------------
" cd to the directory containing the file in the buffer
" nnoremap <silent> <leader>cd :lcd %:h<CR>:pwd<CR>
" nnoremap <silent> <leader>mkd :!mkdir -p %:p:h<CR>:pwd<CR>
" Turn off that stupid highlight search
nmap <silent> <leader>n :set invhls<CR>:set hls?<CR>
" set text wrapping toggles
nmap <silent> <leader>w :set invwrap<CR>:set wrap?<CR>
"set hardwrapping
" nmap <leader>wh set fo=at
"set softwrapping
" nmap <leader>ws set fo=
" Buffer commands
" Deletes buffer and leave window intact
noremap <silent> <leader>bd :BD<CR>
" Make horizontal scrolling easier
nmap <silent> <C-o> 10zl
nmap <silent> <C-i> 10zh
" Shortcut to rapidly toggle `set list`
nmap <leader>l :set list!<CR>:set list?<CR>
" Highlight all instances of the current word under the cursor
"nmap <silent> ^ :setl hls<CR>:let @/="<C-r><C-w>"<CR>
" Search the current file for what's currently in the search {{{
" register and display matches
nmap <silent> <leader>gs
\ :vimgrep /<C-r>// %<CR>:ccl<CR>:cwin<CR><C-W>J:set nohls<CR>
" Search the current file for the word under the cursor and display matches
"nmap <silent> <leader>gw
"\ :vimgrep /<C-r><C-w>/ %<CR>:ccl<CR>:cwin<CR><C-W>J:set nohls<CR>
nmap <silent> <leader>gw :Ag! <C-r><C-w><CR>
" Search the current file for the WORD under the cursor and display matches
nmap <silent> <leader>gW
\ :vimgrep /<C-r><C-a>/ %<CR>:ccl<CR>:cwin<CR><C-W>J:set nohls<CR>
" Search the current file for ruby method
au FileType ruby nmap m/ /^\s*\(def \\| def self\.\)
" }}}
" Swap two words
nmap <silent> sw "xdiwdwep"xp
nmap <silent> sW "xdiWdwEp"xp
" Delete all buffers
nmap <silent> <leader>da :exec "1," . bufnr('$') . "bd"<cr>
" better undo {{{
inoremap <C-U> <C-G>u<C-U>
inoremap <C-W> <C-G>u<C-W>
inoremap <BS> <C-G>u<BS>
inoremap <Del> <C-G>u<Del>
" }}}
" Visually select the text that was last edited/pasted
nmap gV `[v`]
"fold a method/function
nmap <leader>zm /}<CR>zf%<ESC>:nohlsearch<CR>
"change text in "" to the copied text
"nmap <leader>c" vi"d"+P
" Split line (opposite to S-J joining line)
" Pressing `Enter' inserts a new line
" only if buffer is modifiable (e.g. not in help or quickfix window)
if (&ma)
" nmap <buffer> <CR> i<CR><ESC>
nnoremap <leader><CR> gEa<CR><ESC>ew
endif
" Join lines and restore cursor location (J)
"nnoremap J mjJ`j
" AutoClose
"au Filetype markdown,octopress nmap <leader>iuw i[xepa("+P
"au Filetype markdown,octopress nmap <leader>iuW i[xEpa("+P
"au Filetype markdown,octopress vmap <leader>iu s[lxhf]hxa("+Pl
" DelimitMate
au Filetype markdown,octopress nmap <leader>iuw ysw]ela(<C-R>+<ESC>
au Filetype markdown,octopress nmap <leader>iuW ysW]Ea(<ESC>"+p
au Filetype markdown,octopress vmap <leader>iu s]f]a(<C-R>+<ESC>
au Filetype markdown,octopress nmap <leader>up O**Update vom <ESC>:r!getDateVersion -d<CR>kJA:** **<ESC>i
nnoremap ze zMzo
nnoremap zE zMzO
" Stamping {{{
" replace the current word with the last yanked text
"nnoremap S diw"0P
" replace visually selected text with the last yanked text
"vnoremap S "_d"0P
" replace the current word with the last yanked or deleted text
" nnoremap S "_diwP
" replace visually selected text with the last yanked or deleted text
" vnoremap S "_dP
" }}}
nnoremap ]d ]czz " next diff and set screen to center of curser
nnoremap [d [czz " previous diff and set screen to center of curser
nnoremap <leader>d :diffthis<CR>
" Source
vnoremap <c-x> y:execute @@<cr>:echo 'Sourced selection.'<cr>
nnoremap <c-x> ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
" Run the command that was just yanked
nmap <silent> <leader>rc :@"<cr>
" Don't move on *
nnoremap * *<c-o>:set hlsearch<cr>
nmap <Leader>r) ds)i <esc>
nmap <Leader>r( eF r(A)<esc>
vmap <Leader>r" S"vi"S#
" http://vimcasts.org/e/14
cnoremap %p <C-R>=expand('%:h').'/'<cr>
cnoremap %f <C-R>=expand('%:p:t:h')<cr>
"vnoremap <leader>rh :s/></>\r</g | gv | =
" Add space before and after character
nmap g<space> i <esc>la <esc>h
cmap Bd bd