5

我正在尝试使用 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,但如果你需要它我也可以在这里上传)。

有任何想法吗?

4

1 回答 1

1

See this wiki page for explanations of the different methods for automatic indentation in vim.

On this page you can find an indent file for matlab which you can use with filetype based indenting. Here is a similar one for VHDL.

于 2010-09-27T00:51:59.210 回答