在 Vim 中同时保存和运行 [英] Save and run at the same time in Vim

查看:26
本文介绍了在 Vim 中同时保存和运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多 Python 快速模拟的东西,我不断地保存 (:w) 然后运行 ​​(:!!).有没有办法组合这些动作?

I do a lot of Python quick simulation stuff and I'm constantly saving (:w) and then running (:!!). Is there a way to combine these actions?

也许是保存并运行"命令.

Maybe a "save and run" command.

推荐答案

选项 1:

编写一个与此类似的函数并将其放在您的启动设置中:

Write a function similar to this and place it in your startup settings:

function myex()
   execute ':w'
   execute ':!!'
endfunction

您甚至可以将组合键映射到它——查看文档.

You could even map a key combination to it -- look at the documentation.

选项 2(更好):

查看重新映射击键的文档 - 您可以通过简单的键重新映射来完成它.以下工作,但有filename.py"硬编码.也许您可以深入研究并找出如何用当前文件替换它?

Look at the documentation for remapping keystrokes - you may be able to accomplish it through a simple key remap. The following works, but has "filename.py" hardcoded. Perhaps you can dig in and figure out how to replace that with the current file?

:map <F2> <Esc>:w<CR>:!filename.py<CR>

映射后,您可以在命令模式下按 F2.

After mapping that, you can just press F2 in command mode.

imap、vmap 等...是不同模式下的映射.以上仅适用于命令模式.以下内容也应在插入模式下工作:

imap, vmap, etc... are mappings in different modes. The above only applies to command mode. The following should work in insert mode also:

:imap <F2> <Esc>:w<CR>:!filename.py<CR>a

Vim 手册的第 40.1 节非常有帮助.

Section 40.1 of the Vim manual is very helpful.

这篇关于在 Vim 中同时保存和运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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