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

Hua*_*Wei 2 vim command function

我正在编写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    
Run Code Online (Sandbox Code Playgroud)

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

sud*_*ang 5

要缩进,您可以使用

normal ==
Run Code Online (Sandbox Code Playgroud)

要找到也可以使用

normal 2f"
Run Code Online (Sandbox Code Playgroud)

甚至更短

norm <whatever you do in normal mode>
Run Code Online (Sandbox Code Playgroud)

现在,您可能会明白我的意思。
如果不是,请阅读文档:h normal