如何在搜索模式下启动 nvim? (我不想执行搜索,只是为了让 nvim 准备好接受搜索字符串)

问题描述 投票:0回答:2

我想打开一个文件,并在文件打开后让 nvim 自动进入搜索模式。

我需要找到正确的命令来使用,可能是 nvim -c

Command
file.txt

的形式

为了澄清,我想启动 nvim 并能够通过输入搜索字符串来开始搜索,而无需先按“/”进入搜索模式。

运行 nvim -c '/searchString' 立即执行搜索,这不是我想要的

我的用例是我使用 nvim 作为 kitty 的回滚寻呼机。

# kitty passes text to nvim via stdinput which i write to a tmp file in /tmp/kitty_scrollback_buffer
# I then open this file with the nvim terminal by catting the file
# is there anyway to then automatically enter command search mode so that nvim is ready to search when i enter a search string (I do not want to type /, i want to be able to search immediately)
exec nvim \
    -u NONE \
    -c "silent! write! /tmp/kitty_scrollback_buffer | terminal cat /tmp/kitty_scrollback_buffer - " \
neovim
2个回答
0
投票

是的,你就在那里。如果您想在

foo
中搜索
file.txt
,请运行以下命令:

nvim -c "/foo" file.txt

0
投票

命令

nvim -c <cmd>
在配置后执行,当与文件一起使用时,例如在
nvim -c '/foo' file.txt
中,它会立即执行搜索,这在这种情况下没有用。

要模拟向 nvim 发送击键,以下命令效果很好:

nvim -c ‘call feedkeys(”/”)’

如果您使用的是kitty-scrollback.nvim,您可以在

~/.config/kitty/kity.conf
中进行配置,如下所示:

map ctrl+shift+h kitty_scrollback_nvim –nvim-args -c ‘call feedkeys(”?”)’

使用

?
作为按键意味着开始向后搜索。

希望有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.