gpt4 book ai didi

function - 如何在 vim 函数中执行普通模式命令?

转载 作者:行者123 更新时间:2023-12-03 15:38:40 26 4
gpt4 key购买 nike

我正在编写一个 vim 函数来在 c++ 文件中插入一些文本,请参阅以下函数:

function! InsertDebugInfo()                                                                      
let i = line('.')
call append(i+1, '#ifdef DEBUG')
call append(i+2, 'std::cout << "" << std::endl;')
call append(i+3, '#endif')
call append(i+4, '')
call cursor(i+3, 0)
endfunction

在正常模式下,我使用 ==重新缩进一行代码。我的问题是
如何调用 ==在上述函数中。此外,如何执行
命令如 2f"将光标移动到第二个 " .

最佳答案

要缩进,你可以使用

normal ==

要查找也可以使用
normal 2f"

甚至更短
norm <whatever you do in normal mode>

现在你可能会明白我想说的话。
如果没有,请阅读文档 :h normal .

关于function - 如何在 vim 函数中执行普通模式命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38364675/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com