f



A VIM question: Is there a better way to do this?

In a (sh/bash) shell script, I want to load a file into GVIM and then
automatically resize the window based on the number of lines in the file.
I want the window size to be 3 more than the number of lines in the file.

I currently do:

    gvim theFile.txt -c ':exe '"'"'set lines='"'"'.(line('"'"'$'"'"')+3)'

This gets the job done, but is a little ugly with all the quoting.

Is there any better/cleaner way?

-- 
To my knowledge, Jacob Navia is not a Christian.

    - Rick C Hodgin -

0
gazelle
12/16/2016 10:59:08 AM
comp.editors 4871 articles. 0 followers. Post Follow

5 Replies
250 Views

Similar Articles

[PageSpeed] 36

Kenny McCormack wrote:

> In a (sh/bash) shell script, I want to load a file into GVIM and then
> automatically resize the window based on the number of lines in the file.
> I want the window size to be 3 more than the number of lines in the file.
> 
> I currently do:
> 
>     gvim theFile.txt -c ':exe '"'"'set lines='"'"'.(line('"'"'$'"'"')+3)'
> 
> This gets the job done, but is a little ugly with all the quoting.
> 
> Is there any better/cleaner way?

Treating it as a shell quoting question rather than a vim question,
I'd suggest this, which will pass the same argument to gvim but has
simpler quoting:

gvim theFile.txt -c ":exe 'set lines='.(line('\$')+3)"

-- 
Geoff Clare <netnews@gclare.org.uk>
0
Geoff
12/16/2016 1:23:16 PM
In article <4f6did-14t.ln1@ID-313840.user.individual.net>,
Geoff Clare  <netnews@gclare.org.uk> wrote:
>Kenny McCormack wrote:
>
>> In a (sh/bash) shell script, I want to load a file into GVIM and then
>> automatically resize the window based on the number of lines in the file.
>> I want the window size to be 3 more than the number of lines in the file.
>> 
>> I currently do:
>> 
>>     gvim theFile.txt -c ':exe '"'"'set lines='"'"'.(line('"'"'$'"'"')+3)'
>> 
>> This gets the job done, but is a little ugly with all the quoting.
>> 
>> Is there any better/cleaner way?
>
>Treating it as a shell quoting question rather than a vim question,
>I'd suggest this, which will pass the same argument to gvim but has
>simpler quoting:
>
>gvim theFile.txt -c ":exe 'set lines='.(line('\$')+3)"

That alternative had occurred to me.  It works in this case, because
there's only one "funny" character in the command that needs to be escaped.

But I generally avoid these kinds of solutions that involve using " instead
of '.  Generally, down that road lies chaos.

So, I'm still hoping for something better.  I'd like to know if there is
some other way to get VIM to do what's needed, without the need for so many
' marks.

-- 
The plural of "anecdote" is _not_ "data".
0
gazelle
12/16/2016 3:00:42 PM
with <o30viq$503$1@news.xmission.com> Kenny McCormack wrote:
> In article <4f6did-14t.ln1@ID-313840.user.individual.net>,
> Geoff Clare  <netnews@gclare.org.uk> wrote:
>>Kenny McCormack wrote:

*SKIP*
>>>     gvim theFile.txt -c
>>>     ':exe '"'"'set lines='"'"'.(line('"'"'$'"'"')+3)'
*SKIP*
>>gvim theFile.txt -c ":exe 'set lines='.(line('\$')+3)"
*SKIP*
> So, I'm still hoping for something better.  I'd like to know if there
> is some other way to get VIM to do what's needed, without the need for
> so many ' marks.
>

Disclaimer:  I gave everyone 24h, so here I come...

Consider this approach.  I see it as a routine task, thus you collect
all the code that does heavy-lifting of escaping characters in vim's
function.  Place declaration in .vimrc (or .gvimrc, or .exrc, or
filetype plugin (maybe?);  should be considered separately).  And then
do it this way:

	gvim theFile.txt -c 'call FunnyNamedFunction()'

See?  No escapes at all!  Also, '-c' is already in ex-mode, why colon?

Also-disclaimer:  Don't ask how to do vim-,..  vim-basic (maybe?) -- too
many modes for me.  I insist on my way of doing things with vim-perl
(yet another mode) and loot my... my mode-files (maybe?) for ways to
loot state out of various modes of vim and then inject state into
various modes of vim.

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
0
Eric
12/18/2016 2:17:35 PM
In article <slrno5d6jv.j8b.whynot@orphan.zombinet>,
Eric Pozharski  <whynot@pozharski.name> wrote:
....
>	gvim theFile.txt -c 'call FunnyNamedFunction()'
>
>See?  No escapes at all!  Also, '-c' is already in ex-mode, why colon?

Yes, I had considered that as well.  That is, putting everything in the
..vimrc and then just calling it.  Of course, that assumes that you're going
to want to do this a lot and that it makes sense to dedicate the resources
to writing a function for it.  But you can tell from the way I'm phrasing
this, that I don't believe that to be the case here.

Another, similar, idea would be to write out what you want to do to a file
(presumably with fewer quoting issues), then "source" that file in your
"gvim -c" line.

>Also-disclaimer:  Don't ask how to do vim-,..  vim-basic (maybe?) -- too
>many modes for me.  I insist on my way of doing things with vim-perl
>(yet another mode) and loot my... my mode-files (maybe?) for ways to
>loot state out of various modes of vim and then inject state into
>various modes of vim.

I don't understand this paragraph.  Is English your first language?

P.S.  Yeah, I know the colon isn't needed in "gvim -c", but it is force of
habit to put it in, and note that the docs explicitly say that it is OK
(and will be silently ignored).

-- 
The randomly chosen signature file that would have appeared here is more than 4
lines long.  As such, it violates one or more Usenet RFCs.  In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
	http://user.xmission.com/~gazelle/Sigs/Rorschach
0
gazelle
12/19/2016 4:06:56 PM
with <o390j0$k6h$1@news.xmission.com> Kenny McCormack wrote:
> In article <slrno5d6jv.j8b.whynot@orphan.zombinet>,
> Eric Pozharski  <whynot@pozharski.name> wrote:

>>	gvim theFile.txt -c 'call FunnyNamedFunction()'
>>See?  No escapes at all!  Also, '-c' is already in ex-mode, why colon?
> Yes, I had considered that as well.  That is, putting everything in
> the .vimrc and then just calling it.  Of course, that assumes that
> you're going to want to do this a lot and that it makes sense to
> dedicate the resources to writing a function for it.  But you can tell
> from the way I'm phrasing this, that I don't believe that to be the
> case here.

Well, looks like your a-lot is way bigger then my a-lot.  Go figure.

> Another, similar, idea would be to write out what you want to do to a
> file (presumably with fewer quoting issues), then "source" that file
> in your "gvim -c" line.

IMHO, that's what filetype plugins are for.

*SKIP*
> I don't understand this paragraph.  Is English your first language?

Not even second.

> P.S.  Yeah, I know the colon isn't needed in "gvim -c", but it is
> force of habit to put it in, and note that the docs explicitly say
> that it is OK (and will be silently ignored).

Well, completely different approach to about-being-ignored constructs.
Go figure.

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
0
Eric
12/20/2016 7:49:59 AM
Reply: