Friday, December 27, 2013

Re: Why is `:f` abbrev of `:file` and not of (much more useful) `:find`?

On 27/12/13 15:22, Bruno Sutic wrote:
> On Friday, December 27, 2013 2:36:01 AM UTC+1, Tim Chase wrote:
>> On 2013-12-26 17:02, Bruno Sutic wrote:
>>
>>> Now to the question:
>>
>>> why is the `:f` an abbreviation to `:file`? Why not `:f` -> `:find`?
>>
>>
>>
>> Historical/backwards compatibility. The :file command (and ":f"
>>
>> shorthand) has existed for decades, including other vi clones.
>>
>>
>
> That's a bummer.
>
>>
>>> `:file` command does not seem that useful, at least not as useful
>>
>>> as `:find` in everyday work. And Ctrl-G does the same thing as
>>
>>> `:file`! I solved this in my vimrc with `cab f find` - but I'm more
>>
>>> interested in the root cause of this.
>>
>>
>>
>> That abbreviation would drive me nuts--it might be better to just
>>
>> make a ":command" to use "F" instead of intercepting every "f" typed
>>
>> on the command-line. Or at least make it an <expr> mapping
>>
>>
>>
>> :help :map-<expr>
>>
>>
>>
>> with some smarts to only expand when at the beginning of a command.
>>
>> I'd hate to try and type
>>
>>
>>
>> :%s/foo/bar/g
>>
>>
>>
>> and and up with
>>
>>
>>
>> :%s/findoo/bar/g
>>
>>
>
> Tim, the abbreviation (cab) is triggered only when typed as a standalone word.
> ":%s/foo/bar/g" - "f" in word "foo" is *not* expanded!
>
> Some other random examples:
> ":new f<space>" would be expanded to ":new find"
> ":new f<dot>" would be expanded to ":new find."
> ":new fff.fff<space>" *not* expanded
> ":new asdf<space>" *not* expanded
>
> Anyway, in practice I think `cab f find` works just fine.

If you wanted to make sure that it is only expanded at the start of the
command-line, see
:help getcmdtype()
:help getcmdpos()

For instance, I use the following to always open new help windows at the
bottom of the current tabpage:

if version < 700
cnoreabbrev h bot h
else
cnoreabbrev <expr> h ((getcmdtype() == ':' && getcmdpos() <= 2)?
'bot h' : 'h')
endif


Best regards,
Tony.
--
An old man is lying on his deathbed with all his children, grandchildren and
great-grandchildren gathered around, teary-eyed at the approaching finale of
a deeply loved family member. The old man is in a light coma, and the
doctors
have confirmed that the waiting will be over within the next twenty-four
hours. Suddenly, the old man opens his eyes whispers: "I must be dreaming
of heaven... I smell my daughter Lisle's strudel."
"No, no, grandfather, you are not dreaming", he is reassured.
"Grandmother is baking strudel right now."
A faint smile crosses the old man's face. "Go and get me a sliver of
strudel," he says, "she bakes the finest strudel in the world."
One of the grandchildren is immediately dispatched to honor the old
man's request, and, after what seems a long time, he returns empty-handed.
"Did you bring me some of Lisle's strudel?", the old man quavers.
"I'm... I'm very sorry, grandfather, but she says it's for the
funeral."

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: