Vim Macro on Every Line of Visual Selection

后端 未结 3 1661
时光说笑
时光说笑 2021-01-29 19:28

I\'d like to run a macro on every line in a selection, rather than totalling up the number of lines in my head. For instance, I might write a macro to transform:



        
3条回答
  •  无人共我
    2021-01-29 19:48

    You can add the function below to your ~/.vimrc or simply copy it on your browser and running :@+

    fun! RunMacroOverSelection(macroname)
        execute "'<,'>normal @". a:macroname
    endfun
    com -nargs=1 Rover :call RunMacroOverSelection()
    nnoremap r :Rover
    

    The advantage is that you can apply any macro on the visual selection. You need to give the macro letter as argument, like:

    :Rover a
    

提交回复
热议问题