From 77a792caa943495a31bef6eeb85fb72bd0af1f88 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Tue, 19 Nov 2024 21:03:55 +0000 Subject: New g/ command which searches within a text object. This is very useful for constraining searches to certain scopes such as searching for a variable within a function or body of code. --- plugin/gsearch.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 plugin/gsearch.vim (limited to 'plugin') 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 g/ set operatorfunc=search_withing@ +vnoremap g/ /\%V -- cgit