Vim:执行当前文件? [英] Vim: execute current file?

查看:31
本文介绍了Vim:执行当前文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在 Vim 中打开了一个带有 shebang 行的文件(例如 #!/bin/bash)并且该文件具有执行权限(即 chmod +x)我知道我可以在不离开编辑器的情况下输入它来执行它:

If I have a file with a shebang line (e.g. #!/bin/bash) open in Vim and the file has execute permissions (i.e. chmod +x) I know I can type this to execute it without leaving the editor:

:! %:p

  • : 用于命令模式
  • ! 运行 shell 命令
  • % 引用当前缓冲区中的文件
  • :p 使用当前文件的完整路径
    • : for command mode
    • ! to run a shell command
    • % to refer to the file in the current buffer
    • :p to use the full path of the current file
    • 这个频繁的任务有更短的捷径吗?

      Is there a shorter shortcut for this frequent task?

      例如:wq 等有一个 ZZ 快捷方式

      e.g. there is a ZZ shortcut for :wq, etc.

      推荐答案

      :!%:p
      

      ,没有空格,更短.

      如果您想要更短的快捷方式,可以创建自定义映射:

      If you want an even shorter shortcut, you can create a custom mapping:

      nnoremap <F9> :!%:p
      

      或者更助记":

      nnoremap <leader>r :!%:p
      

      这篇关于Vim:执行当前文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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