简体   繁体   English

使用 rails.vim,当活动缓冲区为空或不是 rails 项目的文件时,为什么命令不起作用?

[英]With rails.vim, why don't commands work when the active buffer is empty or not a file that's part of a rails project?

If I don't have a file open from the rails project I'm working on, I can't use any rails.vim commands such as :Rcontroller , :Rmodel , :Rview (I get the error: Not an editor command).如果我没有从我正在处理的 rails 项目打开文件,我将无法使用任何 rails.vim 命令,例如:Rcontroller Rcontroller 、 :Rmodel:Rview (我收到错误:不是编辑器命令) .

Additionally, if i try to use :Rconfig or :Rroutes when I don't have a rails file open, I get the error: Not an editor command: :Rfind application.yml.此外,如果我在没有打开 rails 文件时尝试使用:Rconfig:Rroutes ,我会收到错误消息:不是编辑器命令::Rfind application.yml。

I'm using a pre-fab vim config so I am guessing I need to hunt down an issue in there?我正在使用预制 vim 配置,所以我猜我需要在那里寻找问题? Or is this just the way rails.vim is meant to work?或者这只是 rails.vim 的工作方式吗?

The short answer is that this is the way rails.vim works.简短的回答是,这就是rails.vim的工作方式。

rails.vim tries to detect the Rails project using the path of the current buffer. rails.vim尝试使用当前缓冲区的路径检测 Rails 项目。 In general this makes sense because a number of the commands provided by rails.vim are specific to the current file.一般来说,这是有道理的,因为rails.vim提供的许多命令特定于当前文件。 Also, it is very possible to open files from several Rails projects in the same Vim session, so even commands that only reference the project as a whole need to be tied to the current context.此外,很可能从同一个 Vim session 中的多个 Rails 项目中打开文件,因此即使是仅引用整个项目的命令也需要与当前上下文相关联。

It would be nice if the project-level commands like you describe could be available when you're in a new buffer by falling back to getcwd() and detect that the current working directory is a Rails application.如果您描述的项目级命令可以通过回退到getcwd()并检测到当前工作目录是 Rails 应用程序而在新缓冲区中可用,那将是很好的。 But from a cursory examination of the source, I think it would require some significant restructuring of the plugin.但是从对源的粗略检查来看,我认为这需要对插件进行一些重大的重组。

I wrote a plugin called Open that opens up a project using NERDTree and project the README as a default view.我编写了一个名为Open的插件,它使用NERDTree打开一个项目并将README项目作为默认视图。 One of the advantages of this is that by having a file open by default, you can use any of the Rails commands immediately.这样做的好处之一是,通过默认打开文件,您可以立即使用任何 Rails 命令。

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

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