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

后端 未结 8 1563
渐次进展
渐次进展 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:29

    Executing the line under cursor as an Ex command:

    :execute getline(".")
    

    Convenient enough for 2 lines. (I'd figure out something for doing it with regions, but I'm not a vim user). And for currently selected region, the following seems to do the job:

    :execute getreg("*")
    

    As commented by Peter Rincker, this mapping can be used for executing the currently selected lines:

    :vnoremap  :exe join(getline("'<","'>"),'')
    

提交回复
热议问题