【问题标题】:How to jump to a string in vim ex mode using a bash script如何使用 bash 脚本在 vim ex 模式下跳转到字符串
【发布时间】:2021-04-23 06:59:26
【问题描述】:

我想移动到文本文件“file1”中的“内部”一词,并从 bash 脚本中删除从那里到文件末尾的所有内容。这是我的 vim 命令序列:

/internal
execute "normal !dG"
w

当我将其保存在文本文件中并以 ex 模式从命令行将其传递给 vim 时,一切正常。但是当我尝试从 vim 外部的终端命令提示符执行此操作时:

echo "/internal | execute "normal! dG" | w" | vim -e file1

它不起作用。我找出file1,发现它没有改变。文本文件 file1 如下所示:

one 
one 
one 
one 
one 

internal

two
two
two
two
two

尝试从终端命令提示符处工作时我做错了什么?

【问题讨论】:

  • 确实如此。谢谢。

标签: bash vim terminal ex ex-mode


【解决方案1】:

对于/internal | exec(...,所有字符串都将由/ 解释。你可以在自己的行上写/internal。像这样:

[STEP 101] $ cat file
1
2
foo
3
4
[STEP 102] $ printf 'norm gg\n/foo\n.,$p|q\n' | vim -e file
foo
3
4
[STEP 103] $

或者使用search()函数:

[STEP 104] $ echo 'exec("norm gg") | call search("foo") | .,$p | q' | vim -e file
foo
3
4
[STEP 105] $

【讨论】:

    猜你喜欢
    • 2011-01-25
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 2012-09-17
    • 2020-11-12
    • 2016-01-14
    • 1970-01-01
    相关资源
    最近更新 更多