Tuesday, April 27, 2010

How to fix broken automatic indentation in vim

Hi,

I am trying to use vim 7.2 (on Windows XP) to automatically indent and
format some VHDL and Matlab code. To do so I am trying to use the "gg=G"
command. However this does not work properly. The code is not properly
indented at all.

To give you an example, I had the following source code, which was already
properly indented:

%%%%%%%%%%% BEGIN_OF_CODE %%%%%%%%%%%%
% 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
%%%%%%%%%%% END_OF_CODE %%%%%%%%%%%%

If I use the "gg=G" command I get:

%%%%%%%%%%% BEGIN_OF_CODE %%%%%%%%%%%%
% 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
%%%%%%%%%%% END_OF_CODE %%%%%%%%%%%%

As you can see, in this example Vim incorrectly indents the code after the
first "if" block. For other files I get similar problems (although not
necessarily on the first if block).

For VHDL files I get similar problems.

I have tried using different combinations of the autoindent, smartindent and
cindent settings. After going through these forums I have also made sure
that the "syntax", "filetype", "filetype indent" and "filetype plugin
indent" are set to on. Still, it does not work. Also, if I do "set syntax?"
I get "matlab" for matlab files and "vhdl" for vhdl files which is correct.
And if I do "set indentexpr?" I get "GetMatlabIndent(v:lnum)" for matlab
files and "GetVHDLindent()" for vhdl files.

To try to isolate the problem (and ensure that it is not due to one of the
vim plugins that I have installed) by doing a fresh install of VIM on a
different computer (in which VIM had never been installed before). On that
computer I get the same sort of problems (that is why I do not think that I
need to give you the .vimrc, but if you need it I can upload it here too).

Any ideas? Thank you in advance!

Didlybom

--
View this message in context: http://old.nabble.com/How-to-fix-broken-automatic-indentation-in-vim-tp28379120p28379120.html
Sent from the Vim - General mailing list archive at Nabble.com.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Subscription settings: http://groups.google.com/group/vim_use/subscribe?hl=en

No comments:

Post a Comment