简体   繁体   English

从Rakefile打开Vim?

[英]Open Vim from a Rakefile?

I am creating a journal application for personal notes and have the following in my Rakefile : 我正在为个人笔记创建日记应用程序,并在我的Rakefile有以下Rakefile

task :new do
  entry_name = "Entries/#{Time.now.to_s.gsub(/[-\ :]+/, '.').gsub(/.0500+/,'')}.md"
  `touch #{entry_name}`
  `echo "# $(date)" >> #{entry_name}`
end

The last part I would like to include is the opening of the Vim text editor but I am unable to figure out how to open it as if I called it directly from the bash terminal. 我想要包括的最后一部分是Vim文本编辑器的打开,但是我无法弄清楚如何打开它,就像我直接从bash终端调用它一样。

I have tried: 我试过了:

vim #{entry_name}

but unfortunately I think both of those open it as a background process. 但不幸的是,我认为这两者都将其作为后台进程打开。

I have been referencing " 6 Ways to Run Shell Commands in Ruby ". 我一直在引用“ 在Ruby中运行Shell命令的6种方法 ”。

As in the article you referenced , ` s run the command in a subshell within the current process, but the real problem is that it's trying to take the output from the command run as well, which doesn't play nice with Vim. 正如你引用文章所述` s在当前进程的子shell中运行命令,但真正的问题是它试图从命令运行中获取输出,这对Vim不起作用。

You can either: 你可以:

  • Use exec to replace the current process with the new one (note that the Ruby/Rake process will end once you've called exec , and nothing after it will run). 使用exec用新的(注意了Ruby /耙过程将结束,一旦你打电话来取代当前进程exec ,并没有什么它将运行后)。

  • Use system to create a subshell like ` s, but avoids the problem of trying to grab Vim's stdout. 使用system营造出宛如一个子shell ` S,但避免了试图抓住Vim的标准输出的问题。 Unlike exec , after Vim terminates, Ruby will continue. exec不同,在Vim终止后,Ruby将继续。

you need to pass the tty as standard input for backspaces etc. to work well in vim: 你需要传递tty作为退格等的标准输入才能在vim中正常工作:

exec("</dev/tty vim a b")

obviously the backtick ( ` ) didn't work but I was having issues with system / exec from a script. 很明显,反引号( ` )不起作用,但我遇到了来自脚本的system / exec问题。

first I get Vim: Warning: Input is not from a terminal , and then I see ^? 首先我得到Vim: Warning: Input is not from a terminal ,然后我看到^? when I use backspace. 当我使用退格键时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM