【问题标题】:How to execute a normal mode command in a vim function?如何在 vim 函数中执行普通模式命令?
【发布时间】:2016-07-14 02:44:25
【问题描述】:

我正在编写一个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" 将光标移动到第二个"

【问题讨论】:

    标签: function vim command


    【解决方案1】:

    要缩进,你可以使用

    normal ==
    

    也可以使用

    normal 2f"
    

    甚至更短

    norm <whatever you do in normal mode>
    

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

    【讨论】:

      【解决方案2】:

      在你的函数中试试这个:

      execute 'normal 2f"'
      

      【讨论】:

        猜你喜欢
        • 2012-10-20
        • 1970-01-01
        • 1970-01-01
        • 2011-11-03
        • 2020-05-28
        • 2013-07-19
        • 2016-05-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多