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

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

    For that purpose, I have defined the following commands and mappings:

    ":[range]Execute    Execute text lines as ex commands.
    "                   Handles |line-continuation|.
    " The same can be achieved via "zyy@z (or yy@" through the unnamed register);
    " but there, the ex command must be preceded by a colon (i.e. :ex)
    command! -bar -range Execute silent ,yank z | let @z = substitute(@z, '\n\s*\\', '', 'g') | @z
    
    " [count]e  Execute current [count] line(s) as ex commands, then
    " {Visual}e jump to the following line (to allow speedy sequential
    "                   execution of multiple lines).
    nnoremap  e :Executeexecute 'normal! ' . v:count1 . 'j'
    xnoremap  e :Executeexecute 'normal! ' . v:count1 . 'j'
    

提交回复
热议问题