aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/gsearch.vim19
1 files changed, 19 insertions, 0 deletions
diff --git a/plugin/gsearch.vim b/plugin/gsearch.vim
new file mode 100644
index 0000000..bc820e1
--- /dev/null
+++ b/plugin/gsearch.vim
@@ -0,0 +1,19 @@
+" Search within a text object. Useful for finding variables scoped to a loop or
+" a function or something.
+
+function! s:search_within(t)
+ if a:t == "char"
+ let vtype = 'v'
+ elseif a:t == "block"
+ let vtype = ''
+ else
+ let vtype = 'V'
+ endif
+
+
+ call feedkeys('`[' .. vtype .. '`]/\%V', 'n')
+endfunction
+
+" g/ followed by a text object will start a search, but limit it to the lines
+noremap <silent> g/ <cmd>set operatorfunc=<sid>search_within<cr>g@
+vnoremap <silent> g/ <esc>/\%V