【问题标题】:How to fix broken automatic indentation in vim如何修复vim中损坏的自动缩进
【发布时间】:2011-02-12 21:09:15
【问题描述】:

我正在尝试使用 vim 7.2(在 Windows XP 上)自动缩进和格式化一些 VHDL 和 Matlab 代码。为此,我尝试使用“gg=G”命令。但是,这不能正常工作。代码根本没有正确缩进。

举个例子,我有以下源代码,已经正确缩进:

% This function is based on the code_g_generator() function
function [v_code] = get_code(n_code_number)
% There is no need to clear the persistent variables in this function
mlock 
%% Initialize the internal variables
persistent n_fifo_top;
if isempty(n_fifo_top)
    n_fifo_top = 1;
end

N_MEMORY_SIZE = 4;
if n_code_number > 4
    c_saved_code_fifo = {-1*ones(1, N_MEMORY_SIZE)};
end

如果我使用“gg=G”命令,我会得到:

% This function is based on the code_g_generator() function
function [v_code] = get_code(n_code_number)
% There is no need to clear the persistent variables in this function
mlock 
%% Initialize the internal variables
persistent n_fifo_top;
if isempty(n_fifo_top)
        n_fifo_top = 1;
    end

    N_MEMORY_SIZE = 4;
    if n_code_number > 4
        c_saved_code_fifo = {-1*ones(1, N_MEMORY_SIZE)};
    end

如你所见,在这个例子中,Vim 错误地在第一个 "if" 块之后缩进了代码。对于其他文件,我会遇到类似的问题(尽管不一定在第一个 if 块上)。

对于 VHDL 文件,我遇到了类似的问题。

我尝试过使用 autoindent、smartindent 和 cindent 设置的不同组合。在浏览了这些论坛之后,我还确保将“syntax”、“filetype”、“filetype indent”和“filetype plugin indent”设置为打开。尽管如此,它还是行不通。另外,如果我做“设置语法?”我得到 matlab 文件的“matlab”和 vhdl 文件的“vhdl”,这是正确的。如果我“设置 indentexpr?”我得到 matlab 文件的“GetMatlabIndent(v:lnum)”和 vhdl 文件的“GetVHDLindent()”。

通过在另一台计算机(以前从未安装过 VIM)上重新安装 VIM 来尝试隔离问题(并确保它不是由于我安装的 vim 插件之一)。在那台计算机上我遇到了同样的问题(这就是为什么我认为我不需要给你.vimrc,但如果你需要它我也可以在这里上传)。

有什么想法吗?

【问题讨论】:

    标签: vim code-formatting indentation auto-indent


    【解决方案1】:

    请参阅this wiki 页面,了解有关 vim 中自动缩进的不同方法的说明。

    this 页面上,您可以找到一个用于 matlab 的缩进文件,您可以将其与基于文件类型的缩进一起使用。 Here 与 VHDL 类似。

    【讨论】:

      猜你喜欢
      • 2011-06-03
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      相关资源
      最近更新 更多