如何在vim函数中执行普通模式命令? [英] How to execute a normal mode command in a vim function?

查看:269
本文介绍了如何在vim函数中执行普通模式命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a vim function to insert some text in a c++ file, please see the following function:

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 ,将光标移动到第二个

In normal mode, I use == to re-indent one code line. My question is how to call == in the above function. Furthermore, how to execute the command such as 2f" which move the cursor to the second ".

推荐答案

要缩进,您可以使用

normal ==

要查找也可以使用

normal 2f"

甚至更短

norm <whatever you do in normal mode>

现在您可能会得到我想要说的话。

如果没有,请阅读文档:h normal

Now you might be getting what I'm trying to say.
If not, read documentation :h normal.

这篇关于如何在vim函数中执行普通模式命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆