Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

indent existing file in vim

78 views
Skip to first unread message

রুদ্র ব্যাণার্জী

unread,
Sep 19, 2012, 6:27:49 AM9/19/12
to
Its more a vim question then fortran.
When I write a new file, text get indented nicely. But that's not true,
if I paste a code snippet from existing file which is not
indented(obviously that takes the space etc. it has copied as well).
I am thinking of any possibility of applying indention in existing
fortran file.
Any help?
In my vim, I have fortran_codecomplete, where I have put:
setlocal tabstop=2
setlocal shiftwidth=2

in my vimrc i have fortran specific:
let fortran_more_precise=1
let fortran_free_source=1



Paul Anton Letnes

unread,
Sep 20, 2012, 11:47:07 AM9/20/12
to
Ask in a vim forum. You're sure to get better answers there.

I'm a vim user and I'm not even sure that I understand the question. If
you're pasting non-indented text, you're stuck indenting it after
pasting, afaik.

Paul

glen herrmannsfeldt

unread,
Sep 20, 2012, 1:21:12 PM9/20/12
to
Paul Anton Letnes <paul.ant...@nospam.gmail.kthxbai.com> wrote:
> On 19.09.12 12:27, ??????????????? ?????????????????????????????? wrote:
>> Its more a vim question then fortran.
>> When I write a new file, text get indented nicely. But that's not true,
>> if I paste a code snippet from existing file which is not
>> indented(obviously that takes the space etc. it has copied as well).
>> I am thinking of any possibility of applying indention in existing
>> fortran file.

If by paste, you mean using the cut and paste feature of your
windowing system, then yes it normally gets indented.

If you :r read from a file, then it doesn't.

I have noticed that mine applies fixed form Fortran indenting
even to files with the .f90 extension. I haven't tried to find
out where it does that.

(snip)
>> In my vim, I have fortran_codecomplete, where I have put:
>> setlocal tabstop=2
>> setlocal shiftwidth=2

>> in my vimrc i have fortran specific:
>> let fortran_more_precise=1
>> let fortran_free_source=1

> Ask in a vim forum. You're sure to get better answers there.

> I'm a vim user and I'm not even sure that I understand the question. If
> you're pasting non-indented text, you're stuck indenting it after
> pasting, afaik.

If you do cut and paste with a window system, it goes in just
like it was typed by the user, though a little faster.

There is a mode where, in addition to the six character indent
for fixed-form it also remembers the extra indent from the
previous line. If you cut/paste that way you get recursive
(ever increasing) indentation.

-- glen

blmblm.m...@gmail.com

unread,
Sep 22, 2012, 11:59:40 AM9/22/12
to
In article <k3fja8$rm7$1...@speranza.aioe.org>,
glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
> Paul Anton Letnes <paul.ant...@nospam.gmail.kthxbai.com> wrote:
> > On 19.09.12 12:27, ??????????????? ?????????????????????????????? wrote:
> >> Its more a vim question then fortran.
> >> When I write a new file, text get indented nicely. But that's not true,
> >> if I paste a code snippet from existing file which is not
> >> indented(obviously that takes the space etc. it has copied as well).
> >> I am thinking of any possibility of applying indention in existing
> >> fortran file.
>
> If by paste, you mean using the cut and paste feature of your
> windowing system, then yes it normally gets indented.
>
> If you :r read from a file, then it doesn't.
>
> I have noticed that mine applies fixed form Fortran indenting
> even to files with the .f90 extension. I haven't tried to find
> out where it does that.
>
> (snip)
> >> In my vim, I have fortran_codecomplete, where I have put:
> >> setlocal tabstop=2
> >> setlocal shiftwidth=2
>
> >> in my vimrc i have fortran specific:
> >> let fortran_more_precise=1
> >> let fortran_free_source=1
>
> > Ask in a vim forum. You're sure to get better answers there.


comp.editors might be a good place -- there seem to be some vim experts
who hang out there.


> > I'm a vim user and I'm not even sure that I understand the question. If
> > you're pasting non-indented text, you're stuck indenting it after
> > pasting, afaik.
>
> If you do cut and paste with a window system, it goes in just
> like it was typed by the user, though a little faster.
>
> There is a mode where, in addition to the six character indent
> for fixed-form it also remembers the extra indent from the
> previous line. If you cut/paste that way you get recursive
> (ever increasing) indentation.


That's the behavior I usually get when I paste into a vim session from
my windowing system (under Linux). That's usually not what I want,
but a ":set paste" first makes it not happen.

If what you want is to reindent the pasted-in text, the "=" command
may be helpful:

If things are set up right [1], "=" reindents in accordance with
whatever rules are in effect [2]: "==" to indent a single line, "gg=G"
to reindent the whole file. ":help =" will tell you a little more.

[1] FSVO "right".

[2] I'm not remembering, and am too lazy to check right now, exactly
how all of this works. If it's not clear from vim's help (which it
well may not be :-)? ), try comp.editors?

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.

wve...@gmail.com

unread,
Apr 22, 2017, 7:30:05 AM4/22/17
to
Try https://sourceforge.net/projects/findent/

You find there a reliable fortran indenter (findent) and a few files to
put in ~/.vim

Regards,

Willem

0 new messages