How can I execute the current line as Vim EX commands?

后端 未结 8 1568
渐次进展
渐次进展 2021-02-02 11:17

Say I\'m editing my _vimrc file and I\'ve just added a couple of lines, for instance a new key mapping. I don\'t want to reload the whole file (:so %

8条回答
  •  清歌不尽
    2021-02-02 11:28

    The accepted answer doesn't handle continuation sections. Also, surprisingly, the bar isn't needed, newlines are fine. This will work, first yanking the text into register x:

    vno  "xy:exe substitute(@x,"\n\\",'','g')
    

    As someone has already mentioned, the only exception are commands that "eat up" newlines. Eg, executing the above mapping on:

    :sign define piet text=>> texthl=Search 
    :exe ":sign place 2 line=23 name=piet file=" . expand("%:p")
    

    will cause vim to to think that the user is trying to define textl as "Search\n:exe ":sign place... etc.

提交回复
热议问题