aboutsummaryrefslogtreecommitdiff
path: root/plugin/remappings.vim
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2022-09-13 18:16:30 -0600
committerJosh Rahm <rahm@google.com>2022-09-13 18:16:30 -0600
commit2dd5ac29ec6cdaa4ee7a45314d29559d2294cac0 (patch)
tree24ef10b2f3dea8a6d5b2740b1b78831a15e89b55 /plugin/remappings.vim
parent79b37fdd282f616714876b97e484d8dcc8a488ab (diff)
downloadfieldmarshal.vim-stuff.tar.gz
fieldmarshal.vim-stuff.tar.bz2
fieldmarshal.vim-stuff.zip
assortment of stuffstuff
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$