echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.54k stars 175 forks source link

Persistent abbreviations #721

Open wroyca opened 4 months ago

wroyca commented 4 months ago

Contributing guidelines

Module(s)

mini.abbrev

Description

Hello /

Often, while working in Vim, we make accidental typos. In such cases, we may create abbreviations to prevent future mistakes. This involves opening our configuration and creating said abbreviation by manually changing the text before and after, which can be really distracting:

vim.keymap.set([[!a]], [[flase]], [[false]])

The proposal would be the ability to create on-the-fly persistent abbreviations and (optionally) provide a way to manage them (remove, modify, and so on). The basic operation would be to select the word we wish to correct and then press <leader>... to prompt the user for corrections (by which an abbreviation is created and persisted on confirmation). Mini.pick can take over from there by listing our abbreviations while mapping some key to (delete, add, change).

e.g.

image

Let me know what you think!

echasnovski commented 4 months ago

Thanks for the suggestion!

I have thought about writing abbreviation related module, but did not find any reasonably distinctive way they can be useful beyond snippets. So I decided to wait until after 'mini.snippets' is a thing and reconsider.

As for the idea of making an "interactive abbreviations manager", I don't think that creating abbreviations is such a frequent task that opening config is a big deal for it. Initially my idea was to provide an already created abbreviations for common typos, but that would require maintaining a data base of those, which is not very appealing.

All in all, I'll have this in mind, thanks!

wroyca commented 4 months ago

Thanks for the feedback!

I don't think that creating abbreviations is such a frequent task...

Haha, I wish on so dearly. (:

...that opening config is a big deal for it.

I was looking at it through a writer's perspective - that is, writing multiple large documents and papers where it becomes more interesting to be able to manage abbrev on the fly. I'm interested to hear more on this from other users' perspective!

Initially my idea was to provide an already created abbreviations for common typos, but that would require maintaining a data base of those, which is not very appealing.

Agree, this is also not very flexible - typo tend to be very sporadic and to some extend, personal. It's simply not possible to handle each and every possibility - It's more convenient for users to individually build their own by adding mistakes as they make them.

All in all, I'll have this in mind, thanks!

:partying_face:

IndianBoy42 commented 1 month ago

I actually use luasnip autosnippets rather than abbreviations but similar principle. It has a command to open any snippet file for editing and it registers BufWritePost autocmds so that when I save it reloads all the snippets. You could extend that principle to anything else in your config. Have a file of abbreviations/keymaps/etc, add a user command to open that with a BufWritePost autocommand that sources it and voila. No need to use pickers and vim.ui.input or any other UI, just editing files so you can use all the power of your editor. and its code so you can add helper functions and loops and all. Maybe some helpful buffer local keymaps like getting the word you cursor was on in the original buffer so you can make an abbrev for it quickly