If you have following in a vim buffer, file named, say, foo.awk

/some test/ {
if (foo != "bar") {
if (baz != ""){
array1[xyz] = N
if (N > max_N) max_N = N
}
xyz = temp[1]
# Create
print "," > "something.sql"
split(description,temp,parse_descriptions[file])
print "\t-- "temp[1] > "something.sql"
printf "\t%s %s", xyz, pg_type > "something.sql"
# Load
insert = insert",\n\t"xyz
fields[M]=xyz
M++
N = 1
}
field_to_XX_field[xyz,N] = field
N++
}

position the cursor on the '{' that ends the first line. Then do =%. You get

/some test/ {
        if (foo != "bar") {
                if (baz != ""){
                        array1[xyz] = N
                        if (N > max_N) max_N = N
                }
                xyz = temp[1]
                # Create
                print "," > "something.sql"
                split(description,temp,parse_descriptions[file])
                print "\t-- "temp[1] > "something.sql"
                printf "\t%s %s", xyz, pg_type > "something.sql"
                # Load
                insert = insert",\n\t"xyz
                fields[M]=xyz
                M++
                 N = 1
        }
        field_to_XX_field[xyz,N] = field
        N++
         }


The line 'N = 1' is indented by an extra space, incorrectly, and the
closing '}' is also incorrectly indented. Don't focus on the code
itself or its correctness. I modified it to make it simpler for the
purpose of this example and also for privacy. The point is that it is
syntactically correct awk and the behavior I'm showing you here is
identical to the indentation I get with the unmodified, semantically
correct code.

This is one of a number of problems I've had with indentation. Looking
on the web for the usual discussions of emacs vs. vim, it's not hard
to find the observation that one of emacs' advantages is more accurate
indentation (emacs indents this code snippet correctly).
Unfortunately, my own experience is confirming this. I prefer vim in a
lot of ways, but when programming, indentation is a critical tool and,
for me, if I can't trust the editor to do it correctly, it's not of
much use to me. In the work I'm currently doing, I've been forced to
use emacs in viper mode because of this issue.

I'm not trying to start an editor religious war here. I'm simply
making an observation about something that I think is an important
area where vim seems somewhat weak. vim and awk have been around for a
long time. it ought to be able to indent awk code correctly and I
would suggest that fixing indentation problems should take priority
over adding new features.

(By the way, you get the above behavior with no ~/.vimrc and all
options set to their defaults. The behavior remains the same when you
turn on autoindent or cindent. This is with a vim built from source
up-to-date via git as of last night. Version is 7.3.315 running on a
Slackware 13.37 64-bit system.)

/Don

-- 
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui