aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-09-15 12:44:54 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-09-15 12:44:54 -0600
commit445bdd5b7c8794b7961926dbe660970ff5df5373 (patch)
tree1dd493fc8bcde6947ab09e7e12f56b42d5412a02
parentae428bff031abe75779515101dd1665b2c542c7c (diff)
downloadfieldmarshal.vim-445bdd5b7c8794b7961926dbe660970ff5df5373.tar.gz
fieldmarshal.vim-445bdd5b7c8794b7961926dbe660970ff5df5373.tar.bz2
fieldmarshal.vim-445bdd5b7c8794b7961926dbe660970ff5df5373.zip
remappings.vim: common remappings
remap the text objects for ", ' and ` to go to the next string even if the next string is not on the same line. also add nnoremap Y y$ for good measure.
-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$