aboutsummaryrefslogtreecommitdiff
path: root/plugin/remappings.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/remappings.vim')
-rw-r--r--plugin/remappings.vim60
1 files changed, 24 insertions, 36 deletions
diff --git a/plugin/remappings.vim b/plugin/remappings.vim
index f29f0a4..90d12e0 100644
--- a/plugin/remappings.vim
+++ b/plugin/remappings.vim
@@ -2,43 +2,31 @@
" 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'
+onoremap <silent> in" <cmd>call <sid>find_next_quote('i', '"')<cr>
+onoremap <silent> an" <cmd>call <sid>find_next_quote('a', '"')<cr>
+onoremap <silent> in' <cmd>call <sid>find_next_quote('i', "'")<cr>
+onoremap <silent> an' <cmd>call <sid>find_next_quote('a', "'")<cr>
+onoremap <silent> in` <cmd>call <sid>find_next_quote('i', '`')<cr>
+onoremap <silent> an` <cmd>call <sid>find_next_quote('a', '`')<cr>
+vnoremap <silent> in" <cmd>call <sid>find_next_quote('i', '"')<cr>
+vnoremap <silent> an" <cmd>call <sid>find_next_quote('a', '"')<cr>
+vnoremap <silent> in' <cmd>call <sid>find_next_quote('i', "'")<cr>
+vnoremap <silent> an' <cmd>call <sid>find_next_quote('a', "'")<cr>
+vnoremap <silent> in` <cmd>call <sid>find_next_quote('i', '`')<cr>
+vnoremap <silent> an` <cmd>call <sid>find_next_quote('a', '`')<cr>
+
+function! s:find_next_quote(ai, q) abort
+ call search(a:q, '')
+ call search(a:q, '')
+
+ let l = getline(line('.'))
+ let c = col('.') - 1
+
+ if l[c] == a:q && l[c - 1] == a:q
+ exec "normal! i "
+ elseif l[c] == a:q && l[c + 1] == a:q
+ exec "normal! a l"
endif
-
- exec "normal! \<esc>"
- call search(a:q . '\zs.', flags)
exec "normal! v" . a:ai . a:q
endfunction