Insert predefined text on keyboard shortcut

后端 未结 6 950
悲&欢浪女
悲&欢浪女 2021-02-07 04:27

I often insert binding.pry to my ruby files when I debug them. As I use Vim I\'d love to automate it to avoid retyping it every time. How could I do it?

Th

6条回答
  •  无人共我
    2021-02-07 04:59

    Based on Fredrik's idea, you can define and store a macro in your .vimrc, say g:

    let @g = "Obinding.pry^["
    

    Note that to type the escape character you hit CTRL-V then ESC.

    You can then do @g to perform the macro.


    In general, if you want to save a macro, one easy way would be to record the macro, say in register q, then do "qp (where q is the macro name) to paste the macro. Then surround it with

    let @x = "..."
    

    where x is the macro name you want it to always have and put it in the .vimrc file.

提交回复
热议问题