The no-operation ex-command

17 views
Skip to first unread message

Tony Mechelynck

unread,
Sep 2, 2019, 5:02:09 PM9/2/19
to vim_dev
I just noticed that hitting : without a command name is a valid
ex-command which does nothing (other than going to a range if there is
one). I propose to document it, see attached patch.

The range (if present) can IIUC be any valid range, not just an
absolute line number but also e.g. a relative line number or even a
search command. If there is not even a range, then no error is given
and nothing happens, just like when reading an empty line in a sourced
script.

I don't know of what use it would be to type : with neither a range
nor a command, but who knows? OTOH it "makes logical" what happens
when typing :1234 (go to line 1234) or even :1000;/sometext (go to the
first line containing "sometext" after line 1000); and IIUC the "Vim
philosophy" is that every feature should be documented, and to my mind
"this isn't a bug, it's a feature". ;-)

Best regards,
Tony.
help-excmds.diff

Bram Moolenaar

unread,
Sep 2, 2019, 5:16:49 PM9/2/19
to vim...@googlegroups.com, Tony Mechelynck
Using the range to jump to a line is documented at ":help :range".

Weirdly ":" does nothing, but ":|" prints the current line.

--
In Joseph Heller's novel "Catch-22", the main character tries to get out of a
war by proving he is crazy. But the mere fact he wants to get out of the war
only shows he isn't crazy -- creating the original "Catch-22".

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Tony Mechelynck

unread,
Sep 2, 2019, 6:03:48 PM9/2/19
to Bram Moolenaar, vim_dev
On Mon, Sep 2, 2019 at 11:16 PM Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Tony wrote:
>
> > I just noticed that hitting : without a command name is a valid
> > ex-command which does nothing (other than going to a range if there is
> > one). I propose to document it, see attached patch.
> >
> > The range (if present) can IIUC be any valid range, not just an
> > absolute line number but also e.g. a relative line number or even a
> > search command. If there is not even a range, then no error is given
> > and nothing happens, just like when reading an empty line in a sourced
> > script.
> >
> > I don't know of what use it would be to type : with neither a range
> > nor a command, but who knows? OTOH it "makes logical" what happens
> > when typing :1234 (go to line 1234) or even :1000;/sometext (go to the
> > first line containing "sometext" after line 1000); and IIUC the "Vim
> > philosophy" is that every feature should be documented, and to my mind
> > "this isn't a bug, it's a feature". ;-)
>
> Using the range to jump to a line is documented at ":help :range".
>
> Weirdly ":" does nothing, but ":|" prints the current line.

Actually, using a naked range is documented at "help :[range]" (with
brackets). The way I read it, ":help :range" (without brackets) seems
to imply that some unspecified command follows the range. And I don't
know where ":|" is documented; maybe it should be mentioned at ":help
:bar". And maybe also at ":help :print" since apparently it is a
shortcut for it.

Oh, found it: about one screen page or a little more after ":help
:bar", at cmdline.txt line 644; maybe it should have a help tag.
However, experiment shows that unlike what is said there, ":3|" goes
to line 3 even with a bar. Maybe it's "Improved" behaviour compared to
Vi, maybe it's a bug: you judge.

Oh, a use for the no-op ex-command is documented under another name,
at ":help :exe-comment" (the way I understand it now, the comment
after the bar implies that between the | and the " there is an empty
ex-command).

Seeing the empty ex-command as a no-op makes several things fit better
in my mind; I still think it should be documented somewhere, with a
mention there that just :| is (by exception) not two empty commands on
one line but an abbreviation for the :print command. Maybe put it,
with a helptag, just above what is now line 644 of cmdline.txt.

Best regards,
Tony.

sco...@ckhb.org

unread,
Sep 2, 2019, 6:25:47 PM9/2/19
to vim_dev
i do have a use case for this feature and do employ it.

after invoking a map, the sequence of operations in the map may leave
some output in the command line window and require hitting the enter
key to continue. adding a ':<cr>' to the map will clear the command
line and allow subsequent actions to continue without interactive input.

thank you, tony, for the documentation suggestion.


Reply all
Reply to author
Forward
0 new messages