Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vim 向前搜索在视觉模式下所选文本的第[count]次出现_Vim - Fatal编程技术网

Vim 向前搜索在视觉模式下所选文本的第[count]次出现

Vim 向前搜索在视觉模式下所选文本的第[count]次出现,vim,Vim,我想像使用*命令一样,搜索我在视觉模式下选择的模式 我知道视觉模式yanking(默认情况下填充寄存器0)以及通过/然后Ctrl-R检索寄存器0的内容Ctrl-R,0以粘贴模式作为搜索的可能性 问题是,我不想先猛拉,我已经猛拉了一些东西,我只想现在在视觉模式下搜索所选的内容 请问我该怎么做?我能在不使用不同的yank来注册N个技巧的情况下做到这一点吗?如果您使用gvim或console vim,并使用X支持构建,请检查“GUI选项”是否可用,以及“GUI选项”中是否存在a,然后您可以从*regi

我想像使用*命令一样,搜索我在视觉模式下选择的模式

我知道视觉模式yanking(默认情况下填充寄存器0)以及通过/然后Ctrl-R检索寄存器0的内容Ctrl-R,0以粘贴模式作为搜索的可能性

问题是,我不想先猛拉,我已经猛拉了一些东西,我只想现在在视觉模式下搜索所选的内容


请问我该怎么做?我能在不使用不同的yank来注册N个技巧的情况下做到这一点吗?

如果您使用gvim或console vim,并使用X支持构建,请检查“GUI选项”是否可用,以及“GUI选项”中是否存在a,然后您可以从*register获得当前选择。否则,如果不编写VimL函数,恐怕没有简单的方法可以实现这一点,VimL函数将根据标记值提取选择。然后,该函数可以与搜索提示中的CTRL-R=一起使用。

为什么不将您概述的所有步骤合并成一个映射?唯一缺少的是保存和恢复未命名的寄存器,以及一点转义

" Atom \V sets following pattern to "very nomagic", i.e. only the backslash has special meaning.
" As a search pattern we insert an expression (= register) that
" calls the 'escape()' function on the unnamed register content '@@',
" and escapes the backslash and the character that still has a special
" meaning in the search command (/|?, respectively).
" This works well even with <Tab> (no need to change ^I into \t),
" but not with a linebreak, which must be changed from ^M to \n.
" This is done with the substitute() function.
" gV avoids automatic reselection of the Visual area in select mode.

vnoremap <silent> * :<C-U>let save_unnamedregister=@@<CR>gvy/\V<C-R><C-R>=substitute(escape(@@,'/\'),"\n",'\\n','ge')<CR><CR>:let @@=save_unnamedregister<Bar>unlet save_unnamedregister<CR>gV

下面是一个解决方案,它可以让*在视觉模式下与[count]一起工作:

vnoremap * :call <SID>VisualSearch()<cr>:set hls<cr>
fun! s:VisualSearch() range
   let unnamed = @"
   let repeat = v:count
   exe 'norm gv"zy' | let @/ = @z
   for x in range(repeat)
      call search(@/, 'ws')
   endfor
   let @" = unnamed
endfun

您可以将第五行的zs更改为您从未使用过的任何寄存器。

您是指在视觉模式下突出显示的文本还是选定的文本?看起来您想使用选择,但写了突出显示的单词。我大多数时间都没有在GUI模式下使用Vim。@Robottinosino检查您是否可以在控制台Vim中设置“GUI选项”,这取决于构建。如果这个选项可用,那么这个技巧在控制台vim中也适用。不幸的是,猛拉到一个命名寄存器仍然会重击未命名寄存器。正确。。。您可以设置并替换它。更新。