aboutsummaryrefslogtreecommitdiff
path: root/plugin/remappings.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/remappings.vim')
-rw-r--r--plugin/remappings.vim51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugin/remappings.vim b/plugin/remappings.vim
new file mode 100644
index 0000000..8b3133a
--- /dev/null
+++ b/plugin/remappings.vim
@@ -0,0 +1,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$