“查找下一个”在维姆中

发布于 2024-11-19 00:18:51 字数 124 浏览 1 评论 0原文

要在 Vim 中向前搜索 cake,我会输入 /cake,但当我按回车键时,光标会跳转到第一个匹配项。 是否有类似于“查找下一个”的 Vim 命令?

To search forward in Vim for cake, I'd type /cake, but the cursor jumps to the first match when I press return. Is there a Vim command analogous to "find next"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

栖竹 2024-11-26 00:18:51

下一个是 n,上一个是 N

如果您使用 ?(例如 ?cake)而不是 / 进行反向搜索,则情况相反。

如果您的系统上安装了它,您应该尝试从终端运行 vimtutor 命令,这将启动基本 Vim 命令的教程。

Rob Wells 关于 *# 的建议也非常中肯。

It is n for next and N for previous.

And if you use reverse search with ? (for example, ?cake) instead of /, it is the other way round.

If it is installed on your system, you should try to run vimtutor command from your terminal, which will start a tutorial of the basic Vim commands.

Rob Wells advice about * and # is also very pertinent.

绅刃 2024-11-26 00:18:51

恕我直言,Vim 中最有用的快捷键是 * 键。

将光标放在一个单词上并点击 * 键,您将跳转到该单词的下一个实例。

# 键的作用相同,但它跳转到该单词的上一个实例。

这确实节省了时间。

The most useful shortcut in Vim, IMHO, is the * key.

Put the cursor on a word and hit the * key and you will jump to the next instance of that word.

The # key does the same, but it jumps to the previous instance of the word.

It is truly a time saver.

烟酒忠诚 2024-11-26 00:18:51

当我开始时,我需要观看演示

如何在 Vim 中搜索

  1. 类型 /
  2. 类型搜索词 例如“var”
  3. 输入
  4. 对于下一个实例,请按n(对于上一个N

When I was beginning I needed to watch a demo.

How to search in Vim

  1. type /
  2. type search term e.g. "var"
  3. press enter
  4. for next instance press n (for previous N)
七秒鱼° 2024-11-26 00:18:51

您可能正在寻找 n 键。

You may be looking for the n key.

爱*していゐ 2024-11-26 00:18:51

输入 n 将转到下一场比赛。

Typing n will go to the next match.

樱娆 2024-11-26 00:18:51

正如所讨论的,有多种搜索方式:

/pattern
?pattern
* (and g*, which I sometimes use in macros)
# (and g#)

另外,使用 Nn 导航上一个/下一个。

您还可以通过使用 / 拉出搜索提示,然后使用 Cp/Cn 循环来编辑/调用搜索历史记录。更有用的是 q/,它会将您带到一个可以导航搜索历史记录的窗口。

还需要考虑的是非常重要的 'hlsearch'(输入 :hls 启用)。这使得查找模式的多个实例变得更加容易。您甚至可能想让您的匹配项变得更加明亮,例如:

hi Search ctermfg=yellow ctermbg=red guifg=...

但是您可能会因为屏幕上不断出现黄色匹配项而发疯。因此,您会经常发现自己使用 :noh。这种情况很常见,因此映射是有序的:

nmap <leader>z :noh<CR>

我很容易记住这个映射为 z,因为我过去经常键入 /zz (这是一种快速输入) -键入不常见的情况)以清除我的突出显示。但 :noh 映射要好得多。

As discussed, there are several ways to search:

/pattern
?pattern
* (and g*, which I sometimes use in macros)
# (and g#)

plus, navigating prev/next with N and n.

You can also edit/recall your search history by pulling up the search prompt with / and then cycle with C-p/C-n. Even more useful is q/, which takes you to a window where you can navigate the search history.

Also for consideration is the all-important 'hlsearch' (type :hls to enable). This makes it much easier to find multiple instances of your pattern. You might even want make your matches extra bright with something like:

hi Search ctermfg=yellow ctermbg=red guifg=...

But then you might go crazy with constant yellow matches all over your screen. So you’ll often find yourself using :noh. This is so common that a mapping is in order:

nmap <leader>z :noh<CR>

I easily remember this one as z since I used to constantly type /zz<CR> (which is a fast-to-type uncommon occurrence) to clear my highlighting. But the :noh mapping is way better.

×眷恋的温暖 2024-11-26 00:18:51

如果在按“/wordforsearch”之类的内容后按Ctrl + Enter,则可以在当前行中找到单词“wordforsearch”。然后按n进行下一场比赛;按N查看上一场比赛。

If you press Ctrl + Enter after you press something like "/wordforsearch", then you can find the word "wordforsearch" in the current line. Then press n for the next match; press N for previous match.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文