lean.nvim icon indicating copy to clipboard operation
lean.nvim copied to clipboard

Figure out what to do about abbreviations in modes other than insert mode

Open Julian opened this issue 2 years ago • 6 comments

It's quite annoying to search for non-ASCII characters via /, for instance, because you have to have yanked the character you're looking for ahead of time.

Possibly there's some solution we can think of that'd allow abbreviations in more places. Nothing has occurred to me so far the past few months, but it may be there are things we can try.

Julian avatar Nov 18 '21 21:11 Julian

If you're looking for a quick partial solution, you could try digraphs (ctrl-K a * for example). Perhaps we can find some way to map abbreviations to digraphs?

rish987 avatar Nov 18 '21 21:11 rish987

Another option is finding a way to enable abbreviations in the q/buffer

rish987 avatar Nov 18 '21 21:11 rish987

What I want to try here as a first pass is via https://github.com/hrsh7th/cmp-cmdline -- specifically after #140, it should be possible to expand abbreviations in cmdline or search mode by just enabling that (which seems to work well for other cmp sources).

Julian avatar Dec 04 '21 14:12 Julian

What nvim-cmp does (cmp-cmdline seems to be only configuration) is hook into CmdlineChanged and insert the completion via nvim_feedkeys, we could adopt that for the built-in expander as well.

gebner avatar Dec 04 '21 15:12 gebner

Yep I saw that, probably a good idea too.

Julian avatar Dec 04 '21 15:12 Julian

I've taken a strong interest in this recently. I was thinking that abbreviations are a more lightweight kind of snippet, but of course there isn't a one-to-one correspondence -- for example snippet completion is triggered on command while abbreviation completion is automatic, and there's no notion of reverse-lookup for snippets.

The builtin :iabbrev command mentioned in #117 can be used to a very similar effect to what we have, it can be buffer-specific and :abbrev already works in the command line, however it will be more difficult to extend than something that lives in a Lua plugin.

Overall, I feel like the correct approach is to extend a plugin like LuaSnip for our purposes, then we could get other goodies like abbreviation autocompletion in the command line and search. And it has the "autotrigger" option we can use. But there's the question of how to get reverse-lookup to work in that context, which may not make sense for general snippets, but perhaps COULD if we were to generalize it to searching for a regex match to a visual selection (with snippet placeholders replaced by appropriate patterns, and optimized with a simple map for the plain string case).

So, I think that going in this direction could eventually get this and #117 working, but let me know if you had something else in mind.

rish987 avatar Aug 15 '22 03:08 rish987