diff options
author | Josh Rahm <rahm@google.com> | 2024-11-19 21:03:55 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2024-11-19 21:03:55 +0000 |
commit | 77a792caa943495a31bef6eeb85fb72bd0af1f88 (patch) | |
tree | 1a0dcba5db768a5b238ca604fe667d43403d1b2c | |
parent | 6cf1a0f7ba8183a0868b7d3f2a3f86795cc5c61a (diff) | |
download | fieldmarshal.vim-77a792caa943495a31bef6eeb85fb72bd0af1f88.tar.gz fieldmarshal.vim-77a792caa943495a31bef6eeb85fb72bd0af1f88.tar.bz2 fieldmarshal.vim-77a792caa943495a31bef6eeb85fb72bd0af1f88.zip |
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.
-rw-r--r-- | plugin/gsearch.vim | 19 |
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 |