有没有办法执行 txt 文件中的 vim 命令和文本?

Is there a way to execute vim commands that are within txt file along with text?

我正处于 CTF 最后阶段,我有这个:

vim flag
iCourse{v3ry_g00d_fl4g}[ESC]13hs1[ESC]am_[ESC]9l2xli_[ESC]2li3[ESC]vypaks[ESC]:s/ry/15
:wq 

我对 Vim 不是很熟悉,所以我不知道如何 运行 这个脚本。我猜它一定是在做比用“15”替换“ry”更大的事情,因为我手动尝试过并且标志不正确。提前致谢!

是的,这是可能的。当使用 -s 命令行标志启动时,vim 将从输入文件中获取命令:

来自手册页:

-s {scriptin}
      The  script  file {scriptin} is read. The characters in the
      file are interpreted as if you had typed them. The same can
      be done with the command ":source! {scriptin}". If the end
      of the file is reached before the editor exits, further
      characters are read from the keyboard.

所以你需要做的就是使用像sed这样的工具将每个出现的[ESC]转换为转义字符,将结果存储在一个临时文件中,然后将其提供给vim:

s='iCourse{v3ry_g00d_fl4g}[ESC]13hs1[ESC]am_[ESC]9l2xli_[ESC]2li3[ESC]vypaks[ESC]:s/ry/15'
cmdfile=`mktemp`
echo -e `sed 's/\[ESC\]/\\x1B/g' <<<"$s"` >$cmdfile
vim -s $cmdfile