comparison vimrc @ 183:fca0df810041

Add after-object plugin
author zegervdv <zegervdv@me.com>
date Wed, 05 Nov 2014 22:18:41 +0100
parents 3dc6a4eec6ac
children e3639166a8ab
comparison
equal deleted inserted replaced
182:3dc6a4eec6ac 183:fca0df810041
272 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) 272 let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
273 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' 273 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
274 endfunction " }}} 274 endfunction " }}}
275 set foldtext=MyFoldText() 275 set foldtext=MyFoldText()
276 276
277 " Next and Last {{{
278 "
279 " Motion for "next/last object". "Last" here means "previous", not "final".
280 " Unfortunately the "p" motion was already taken for paragraphs.
281 "
282 " Next acts on the next object of the given type, last acts on the previous
283 " object of the given type. These don't necessarily have to be in the current
284 " line.
285 "
286 " Currently works for (, [, {, and their shortcuts b, r, B.
287 "
288 " Next kind of works for ' and " as long as there are no escaped versions of
289 " them in the string (TODO: fix that). Last is currently broken for quotes
290 " (TODO: fix that).
291 "
292 " Some examples (C marks cursor positions, V means visually selected):
293 "
294 " din' -> delete in next single quotes foo = bar('spam')
295 " C
296 " foo = bar('')
297 " C
298 "
299 " canb -> change around next parens foo = bar('spam')
300 " C
301 " foo = bar
302 " C
303 "
304 " vin" -> select inside next double quotes print "hello ", name
305 " C
306 " print "hello ", name
307 " VVVVVV
308
309 onoremap an :<c-u>call <SID>NextTextObject('a', '/')<cr>
310 xnoremap an :<c-u>call <SID>NextTextObject('a', '/')<cr>
311 onoremap in :<c-u>call <SID>NextTextObject('i', '/')<cr>
312 xnoremap in :<c-u>call <SID>NextTextObject('i', '/')<cr>
313
314 onoremap al :<c-u>call <SID>NextTextObject('a', '?')<cr>
315 xnoremap al :<c-u>call <SID>NextTextObject('a', '?')<cr>
316 onoremap il :<c-u>call <SID>NextTextObject('i', '?')<cr>
317 xnoremap il :<c-u>call <SID>NextTextObject('i', '?')<cr>
318
319
320 function! s:NextTextObject(motion, dir)
321 let c = nr2char(getchar())
322 let d = ''
323
324 if c ==# "b" || c ==# "(" || c ==# ")"
325 let c = "("
326 elseif c ==# "B" || c ==# "{" || c ==# "}"
327 let c = "{"
328 elseif c ==# "r" || c ==# "[" || c ==# "]"
329 let c = "["
330 elseif c ==# "'"
331 let c = "'"
332 elseif c ==# '"'
333 let c = '"'
334 else
335 return
336 endif
337
338 " Find the next opening-whatever.
339 execute "normal! " . a:dir . c . "\<cr>"
340
341 if a:motion ==# 'a'
342 " If we're doing an 'around' method, we just need to select around it
343 " and we can bail out to Vim.
344 execute "normal! va" . c
345 else
346 " Otherwise we're looking at an 'inside' motion. Unfortunately these
347 " get tricky when you're dealing with an empty set of delimiters because
348 " Vim does the wrong thing when you say vi(.
349
350 let open = ''
351 let close = ''
352
353 if c ==# "("
354 let open = "("
355 let close = ")"
356 elseif c ==# "{"
357 let open = "{"
358 let close = "}"
359 elseif c ==# "["
360 let open = "\\["
361 let close = "\\]"
362 elseif c ==# "'"
363 let open = "'"
364 let close = "'"
365 elseif c ==# '"'
366 let open = '"'
367 let close = '"'
368 endif
369
370 " We'll start at the current delimiter.
371 let start_pos = getpos('.')
372 let start_l = start_pos[1]
373 let start_c = start_pos[2]
374
375 " Then we'll find it's matching end delimiter.
376 if c ==# "'" || c ==# '"'
377 " searchpairpos() doesn't work for quotes, because fuck me.
378 let end_pos = searchpos(open)
379 else
380 let end_pos = searchpairpos(open, '', close)
381 endif
382
383 let end_l = end_pos[0]
384 let end_c = end_pos[1]
385
386 call setpos('.', start_pos)
387
388 if start_l == end_l && start_c == (end_c - 1)
389 " We're in an empty set of delimiters. We'll append an "x"
390 " character and select that so most Vim commands will do something
391 " sane. v is gonna be weird, and so is y. Oh well.
392 execute "normal! ax\<esc>\<left>"
393 execute "normal! vi" . c
394 elseif start_l == end_l && start_c == (end_c - 2)
395 " We're on a set of delimiters that contain a single, non-newline
396 " character. We can just select that and we're done.
397 execute "normal! vi" . c
398 else
399 " Otherwise these delimiters contain something. But we're still not
400 " sure Vim's gonna work, because if they contain nothing but
401 " newlines Vim still does the wrong thing. So we'll manually select
402 " the guts ourselves.
403 let whichwrap = &whichwrap
404 set whichwrap+=h,l
405
406 execute "normal! va" . c . "hol"
407
408 let &whichwrap = whichwrap
409 endif
410 endif
411 endfunction
412
413 " }}}
414
415 " VHDL ctags 277 " VHDL ctags
416 let g:tlist_vhdl_settings = 'vhdl;d:package declarations;b:package bodies;e:entities;a:architecture specifications;t:type declarations;p:processes;f:functions;r:procedures' 278 let g:tlist_vhdl_settings = 'vhdl;d:package declarations;b:package bodies;e:entities;a:architecture specifications;t:type declarations;p:processes;f:functions;r:procedures'
417 " }}} 279 " }}}
418 " Latex {{{ 280 " Latex {{{
419 " Compile using rubber 281 " Compile using rubber
621 autocmd FileType c nnoremap <buffer> <silent><leader>s :w<CR>:call VimuxRunCommand('make')<CR> 483 autocmd FileType c nnoremap <buffer> <silent><leader>s :w<CR>:call VimuxRunCommand('make')<CR>
622 " }}} 484 " }}}
623 " Tmuxline {{{ 485 " Tmuxline {{{
624 let g:tmuxline_powerline_separators=0 486 let g:tmuxline_powerline_separators=0
625 " }}} 487 " }}}
488 " After-objects {{{
489 autocmd VimEnter * call after_object#enable('=', ':', '-', '#', ' ')
490 " }}}
626 491
627 " Load local vimrc 492 " Load local vimrc
628 if filereadable($HOME . "/.vimrc.local") 493 if filereadable($HOME . "/.vimrc.local")
629 source ~/.vimrc.local 494 source ~/.vimrc.local
630 endif 495 endif