在键盘快捷键上插入预定义的文本 [英] Insert predefined text on keyboard shortcut

查看:35
本文介绍了在键盘快捷键上插入预定义的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在调试时将 binding.pry 插入到我的 ruby​​ 文件中.当我使用 Vim 时,我很想将它自动化以避免每次都重新输入.我怎么能做到?

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?

我想映射的确切顺序是:

The exact sequence I'd like to map is:

  1. 插入新行.
  2. binding.pry 插入到新创建的行中.
  3. 返回正常模式.
  1. Insert new line.
  2. Insert binding.pry to the newly created line.
  3. Return to normal mode.

binding.pry 是我要粘贴的文本,而不是文件.

binding.pry is text I want to paste, not a file.

插入前:

a = 1
b = 2

插入后:

a = 1
binding.pry
b = 2

推荐答案

录制宏(未经测试)

qq               " record macro to register q 
o                " insert empty line below cursor
esc              " exit insert-mode
:r /path/to/binding.pry   " insert content of file
esc              " cmd-mode
q                " end recording

要执行宏,请执行

@q

或者将以下内容添加到您的 .vimrc 文件

Or add the following to your .vimrc file

更新

要插入字符串binding.pry,映射变为:

To insert the string binding.pry the mapping becomes:

map ,p obinding.pry<ESC>

这篇关于在键盘快捷键上插入预定义的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆