如何在vim中修复损坏的自动缩进

did*_*bom 5 vim code-formatting indentation auto-indent

我试图使用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
Run Code Online (Sandbox Code Playgroud)

如果我使用"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
Run Code Online (Sandbox Code Playgroud)

如您所见,在此示例中,Vim在第一个"if"块之后错误地缩进代码.对于其他文件,我遇到类似的问题(虽然不一定在第一个if块上).

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

我尝试过使用autoindent,smartindent和cindent设置的不同组合.通过这些论坛后,我还确保将"语法","文件类型","文件类型缩进"和"文件类型插件缩进"设置为打开.不过,它不起作用.另外,如果我"设置语法?" 我为matlab文件获取"matlab",为vhdl文件获取"vhdl",这是正确的.如果我"设置indentexpr?" 我为matlab文件获取"GetMatlabIndent(v:lnum)",为vhdl文件获取"GetVHDLindent()".

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

有任何想法吗?

ako*_*sch 1

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

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