On 2021-01-25, Chaoren Lin wrote: > cabbrev s ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'MyS' : 's') > > Isn't cabbrev command line mode only? Why do you need to check getcmdtype()?
Because command-line mode includes entering search patterns and filter commands as well as ex commands. See ":help Command-line-mode". > There could be an optional range in front of the command. getcmdpos() <= 2 > would exclude that. I may have been wrong about how easy this would be. None of my applications of :cabbrev use ranges. To get this solution to work may require getcmdline() instead of getcmdpos() and parsing the result to see if the s is preceded by a range. Ick. > What's wrong with cabbrev s MyS? The potential problem is that the s would be expanded to MyS anywhere in the command line that a single s appears. > In general I just find it super jarring when whatever I'm typing gets changed > automatically from under my cursor. Agreed. I usually use command-line abbreviations that are the lower-case spelling of the command name so that only the first letter changes. I would have called your function S, but that command name is used by the vis plugin and my thought was to change the name of your command to MyS. > That's why I prefers not use imaps and cabbrevs. Since this is > a single character command, it could feel different. I'll try it > for a while to see if I end up hating it. I'd still prefer an > option though. I see your points. I don't think your proposed option is going to fly for the reasons I gave before, though. The chances of encountering a problem with a plugin are small, but they're not zero. To your proposal of having the option apply only to the command line: I can't think of any option that does that. It would be confusing (to others) if \n worked only on the command line. That's why it would be nice if you could customize :s for just yourself without having to write a whole lot of vimscript, or be jarred by the abbreviation expansion. Regards, Gary -- -- You received this message from the "vim_dev" 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_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/20210126012839.GC5133%40phoenix.
