f



Changing AWK indent behavior in VIM 7.

I recently upgraded to VIM 7.  It was a "voluntary" upgrade and there
are some nice features that attracted me.  However, one thing that is
annoying is the way it handles autoindent when writing AWK code.
Previously, it "just worked".  What I think happened is that TPTB
decided to take the cindent conventions and extend them to other non-C,
but C-like languages (e.g., AWK).  Now, in one sense, this could be a
good thing, but my conventions for writing code are different that what
TPTB think is standard.  I've never liked the way VIM does C indenting,
but since I rarely write C, it hasn't been a problem.  But now, they've
gone and screwed up the way it does AWK.  Obviously, I'm looking for a
way to turn off the behavior/get things back to normal.

The problem is that it doesn't indent correctly.  Or, to put it another
way, it is *too* familiar with the syntax of the language.  Sometimes it
gets it right, but mostly, it gets it wrong.  For example, if my cursor
is on:

	if (...)

and hit o, I want the cursor to go to beneath the "i" in if.  Now, it
moves me in a tab stop.  This is relatively innocuous, but the next one
is a real PIA:  Suppose I have:

BEGIN	{
	line1ThatStartsWithaTab
	line2ThatStartsWithaTab

with my cursor on "line 1".  I hit O to open a line above it and it puts
the cursor below the N in BEGIN.  Clearly, hosed.  Clearly, simple rules
of autoindent say that it should fill the line with a tab and leave the
cursor just above line1.

Now, I know that some of this is a function of my vimrc settings,
specifically, sw and ts.  And I know my settings will not meet with
universal appeal, but that's not the point.  The point is, it used to
work fine, and I'm pretty sure there is some setting I can tweak to make
it work normally again.  Can anyone tell me what that setting is?

0
gazelle
4/15/2007 6:29:26 PM
comp.editors 4871 articles. 0 followers. Post Follow

5 Replies
244 Views

Similar Articles

[PageSpeed] 55

* Kenny McCormack [2007.04.15 18:29]:
> I recently upgraded to VIM 7. 
> [...]
> What I think happened is that TPTB decided to take the
> cindent conventions and extend them to other non-C, but
> C-like languages (e.g., AWK).  

I see no evidence that $VIM/indent/awk.vim changed for a
very long time, though you don't say what version you
upgraded from.

> For example, if my cursor
> is on:
>
> 	if (...)
>
> and hit o, I want the cursor to go to beneath the "i" in if.

I get that with:

vim -u NONE
filetype indent on
set ft=awk

So clearly it's from the awk indent script. Wonder how you
ever had it working. Did you perhaps have:

filetype indent off

and used cruder methods like 'autoindent' or 'smartindent'?

> BEGIN	{
> 	line1ThatStartsWithaTab
> 	line2ThatStartsWithaTab
>
> with my cursor on "line 1".  I hit O to open a line above
> it and it puts the cursor below the N in BEGIN.  

Sounds like you have sw=4 and ts=8.

-- 
JR
0
Jean
4/16/2007 12:28:55 AM
In article <q62dnXozm-PaXr_bnZ2dnUVZ_judnZ2d@magma.ca>,
Jean-Rene David  <jrdavid@magma.ca> wrote:
>* Kenny McCormack [2007.04.15 18:29]:
>> I recently upgraded to VIM 7. 
>> [...]
>> What I think happened is that TPTB decided to take the
>> cindent conventions and extend them to other non-C, but
>> C-like languages (e.g., AWK).  
>
>I see no evidence that $VIM/indent/awk.vim changed for a
>very long time, though you don't say what version you
>upgraded from.

From 6.1

>> For example, if my cursor
>> is on:
>>
>> 	if (...)
>>
>> and hit o, I want the cursor to go to beneath the "i" in if.
>
>I get that with:
>
>vim -u NONE
>filetype indent on
>set ft=awk
>
>So clearly it's from the awk indent script. Wonder how you
>ever had it working. Did you perhaps have:
>
>filetype indent off

Nope.

>and used cruder methods like 'autoindent' or 'smartindent'?

I use autoindent, never heard of smartindent.

>> BEGIN	{
>> 	line1ThatStartsWithaTab
>> 	line2ThatStartsWithaTab
>>
>> with my cursor on "line 1".  I hit O to open a line above
>> it and it puts the cursor below the N in BEGIN.  
>
>Sounds like you have sw=4 and ts=8.

Here's my .vimrc:

set shell=/bin/sh ai sm wm=4 sw=4 uc=0 wh=999 ls=2 ru hls guioptions-=a is vb hi=100 viminfo=

So, yes, ts is at the default 8.
And, most importantly, I didn't change anything (in .vimrc) when I upgraded.

Note: Platform is Win32 - and I know that under Win32, there's more of a
"system" defined structure of vimrc files than under Unix, so I suspect
something changed there.

0
gazelle
4/16/2007 12:47:02 AM
* Kenny McCormack [2007.04.16 00:47]:
> In article <q62dnXozm-PaXr_bnZ2dnUVZ_judnZ2d@magma.ca>,
> Jean-Rene David  <jrdavid@magma.ca> wrote:
> > though you don't say what version you
> > upgraded from.
>
> From 6.1

Ah, there it is. Vim 6.1 didn't have an indent file for awk;
Vim 7 does.

Try:

filetype indent off

to ignore the indent file and see if you get your desired
behavior back. This will turn off indenting scripts for all
filetypes so you might ultimately want to do that
selectively with an autocommand.

-- 
JR
0
Jean
4/16/2007 1:57:21 AM
In article <OOqdnQgvxeOcRb_bnZ2dnUVZ_qGjnZ2d@magma.ca>,
Jean-Rene David  <jrdavid@magma.ca> wrote:
>* Kenny McCormack [2007.04.16 00:47]:
>> In article <q62dnXozm-PaXr_bnZ2dnUVZ_judnZ2d@magma.ca>,
>> Jean-Rene David  <jrdavid@magma.ca> wrote:
>> > though you don't say what version you
>> > upgraded from.
>>
>> From 6.1
>
>Ah, there it is. Vim 6.1 didn't have an indent file for awk;
>Vim 7 does.
>
>Try:
>
>filetype indent off

Thanks.  Sounds good.

>to ignore the indent file and see if you get your desired
>behavior back. This will turn off indenting scripts for all
>filetypes so you might ultimately want to do that
>selectively with an autocommand.

Or could I just remove the indent file?  Where is it stored?

0
gazelle
4/16/2007 2:05:10 AM
Kenny McCormack <gazelle@xmission.xmission.com> wrote:
> In article <OOqdnQgvxeOcRb_bnZ2dnUVZ_qGjnZ2d@magma.ca>,
> Jean-Rene David  <jrdavid@magma.ca> wrote:
>>* Kenny McCormack [2007.04.16 00:47]:
>>> In article <q62dnXozm-PaXr_bnZ2dnUVZ_judnZ2d@magma.ca>,
>>> Jean-Rene David  <jrdavid@magma.ca> wrote:
>>> > though you don't say what version you
>>> > upgraded from.
>>>
>>> From 6.1
>>
>>Ah, there it is. Vim 6.1 didn't have an indent file for awk;
>>Vim 7 does.
>>
>>Try:
>>
>>filetype indent off
> 
> Thanks.  Sounds good.
> 
>>to ignore the indent file and see if you get your desired
>>behavior back. This will turn off indenting scripts for all
>>filetypes so you might ultimately want to do that
>>selectively with an autocommand.
> 
> Or could I just remove the indent file?  Where is it stored?

The file is $VIMRUNTIME/indent/awk.vim.

Rather than remove it, though, you might consider creating a file 
named awk.vim in ~/.vim/indent or C:\Program 
Files\Vim\vimfiles\indent and put just this line in it:

    let b:did_indent = 1

That should disable indenting for awk files without disturbing your 
installation and, unlike removing the "official" awk.vim, will 
continue to work even if you upgrade vim again.  See

    :help 30.3

HTH,
Gary
0
Gary
4/16/2007 4:49:13 AM
Reply: