【问题标题】:How can one correctly reload a ftplugin after souring .vimrc?如何在 .vimrc 变酸后正确地重新加载 ftplugin?
【发布时间】:2014-02-20 21:59:59
【问题描述】:

如果我打开一个 c 文件并且我的缓冲区正在使用 "c.vim" ftplugin,那么打开/编辑/获取我的 .vimrc ,我失去了 "c.vim" ftplugin 的功能。

自动重新加载 ftplugin 的最佳方法是什么?

这是一个例子:

获取我的 .vimrc:

之前 c 文件的缓冲区状态
// This line has an existing comment.
// I used 'o' while on the above line to continue that comment.
// Awesome, after pressing return I am still commenting.

获取我的 .vimrc:

后 c 文件的缓冲区状态
// This line has an existing comment.
I used 'o' while on the above line to try and continue that comment.
After pressing return it is obvious the ftplugin for this filetype is not active.

这是我的 .vimrc,以防它以某种方式导致问题:

set nocompatible
set backspace=indent,eol,start
filetype plugin indent on
syntax on
set hls
nnoremap <leader>ev :split $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>

【问题讨论】:

  • 您不能手动或以编程方式获取 ftplugins:它们是由 Vim 在检测到相关文件类型时获取的。此外,您没有显示该 ftplugin 中的内容,甚至没有说明它应该涵盖的文件类型。请用更多信息替换您问题中的借口。
  • romainl 感谢您的回复,我应该更换什么借口?我可以添加文件类型是 c 代码。使用 vim 中包含的标准 c 文件类型...上次更改是 2007 年 9 月 25 日。这有帮助吗?
  • “我真诚地提前道歉”和朋友们。
  • 采购您的~/.vimrc 不应该让您处于这种情况。找到~/.vimrc 之后,:set syntax 的输出是什么?只是为了确定,真的是~/.vimrc吗?

标签: vim vim-plugin


【解决方案1】:

我在给出第一个答案时误读了您的问题,或者您的编辑彻底改变了问题。

简答:删除线

:set nocompatible

来自您的 vimrc 文件。

以下是来自:help 'compatible' 的一些相关行:

This is a special kind of option, because when it's set or reset,
other options are also changed as a side effect.  ...
When a |vimrc| or |gvimrc| file is found while Vim is starting up,
this option is switched off, and all options that have not been
modified will be set to the Vim defaults.  ...

这意味着在 vimrc 文件开头的 :set nocompatible 是多余的。此外,关于“所有未设置的选项”的部分仅适用于查找 vimrc 文件的自动效果,不适用于您设置或重置选项时。

正如我在之前的回答中所说,'formatoptions' 选项是困扰您的选项;这是受'compatible' 选项影响的众多选项之一。

【讨论】:

  • 从我的 vimrc 中删除它后它可以工作,采购我的 .vimrc 现在不会造成任何副作用。根据 romainl 的建议,我修改了问题以使其更具可读性。我还修改了问题以删除我的“潜在修复评论”
  • 正如 Jimmy Buffet 所说,“这可能是我的错。”也就是说,我可能第一次误读了这个问题。我以为您喜欢 vimrc 中的内容,这就是您通过 ftplugin 获取它的原因。
【解决方案2】:

你必须做两件事:

  1. 找到重要的选项。
  2. 覆盖 ftplugin。

我最近在 SuperUser 上就 #1 提出了建议:https://superuser.com/questions/719329/automatic-indentation-with-macvim/719411#719411 在您的情况下,您要更改的选项是 'formatoptions'(短格式 'fo')。

对于 #2,请参阅:help ftplugin-overrule。我建议使用那里描述的第三个选项。

【讨论】:

  • 我在再次查看之前和之后查看了该 ftplugin-overrule 似乎这将帮助我解决这个问题,而不是直接解决它。我不应该用我注释掉的行来获取 ftplugin。但是,查看这里的帮助文件确实让我更接近解决方案,我现在正在编辑我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-27
  • 1970-01-01
  • 2014-01-31
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
相关资源
最近更新 更多