aboutsummaryrefslogtreecommitdiff
path: root/plugin/remappings.vim
blob: 8b3133a4b3e3cec6c1c64c33261bc237597fd826 (plain) (blame)
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

" Remap i{",',`} and a{",',`} to search for the next string. This is more like how objects like i( and i{ work.
"
" The behavior inside the quotes should remain unchanged.
onoremap <silent> i" <cmd>call <sid>find_quote('i', '"')<cr>
onoremap <silent> a" <cmd>call <sid>find_quote('a', '"')<cr>

onoremap <silent> i' <cmd>call <sid>find_quote('i', "'")<cr>
onoremap <silent> a' <cmd>call <sid>find_quote('a', "'")<cr>

onoremap <silent> i` <cmd>call <sid>find_quote('i', '`')<cr>
onoremap <silent> a` <cmd>call <sid>find_quote('a', '`')<cr>

vnoremap <silent> i" <cmd>call <sid>find_quote('i', '"')<cr>
vnoremap <silent> a" <cmd>call <sid>find_quote('a', '"')<cr>

vnoremap <silent> i' <cmd>call <sid>find_quote('i', "'")<cr>
vnoremap <silent> a' <cmd>call <sid>find_quote('a', "'")<cr>

vnoremap <silent> i` <cmd>call <sid>find_quote('i', '`')<cr>
vnoremap <silent> a` <cmd>call <sid>find_quote('a', '`')<cr>

function! s:find_quote(ai, q) abort
  let l = getline('.')[:col('.') - 2]

  let cnt = 0
  let skip = 0
  for c in l
    if c ==# a:q && !skip
      let cnt = !cnt
    endif

    if c ==# '\'
      let skip = 1
    else
      let skip = 0
    endif
  endfor

  let flags = 'W'
  if cnt == 1
    let flags .= 'b'
  endif

  exec "normal! \<esc>"
  call search(a:q . '\zs.', flags)
  exec "normal! v" . a:ai . a:q
endfunction

" Fix silly yank behavior.
nnoremap Y y$