text-case.nvim icon indicating copy to clipboard operation
text-case.nvim copied to clipboard

Custom case support

Open grimnight opened this issue 1 year ago • 6 comments

I noticed coerce.nvim today in awesome-neovim.

It has support for custom cases, would it be possible to get them in text-case.nvim?

grimnight avatar Jan 09 '24 23:01 grimnight

That's totally feasible. In fact, As Grzegorz, coerce's author, mentions in its readme coerce is based on text-case and the method for registering custom cases exists in both. It will be a matter of exposing it.

We will also need to un-hardcode this table

I'm curious, @grimnight, do you have any custom case in mind?

johmsalas avatar Jan 11 '24 02:01 johmsalas

I'm currently looking forward to path/case, perhaps some other ones in the future.

Will there be support for custom triggers as well? Or an ability to add new ones to existing methods?

grimnight avatar Jan 12 '24 03:01 grimnight

path/case is built-in. I hadn't noticed there were some cases with no matching triggers. That's a bug! at least we should make it explicit in the readme. But no worries, in the meantime, I'm going to explain below how to add it.

Triggers are regular key-maps. Some users just disable the default key mappings and create them using their own favorite keys. For example I've seen "-" for dash-case and "_" for snake_case. I prefer to keep using the d and s, that way I know their uppercase variants will trigger LSP renaming (ie: D, for dash case LSP rename).

Adding default keymaps depends on your current setup, but this is the most generic way, in the example, I'm using f as in files or folders, it adds 2 keymaps: gaf for path case conversion gaF for path case conversion using Language Server Protocol

vim.api.nvim_set_keymap('n', 'gaf', "<cmd>lua require('textcase').current_word('to_path_case')<CR>", { desc = "Convert to/path/case" })
vim.api.nvim_set_keymap('n', 'gaF', "<cmd>lua require('textcase').lsp_rename('to_path_case')<CR>", { desc = "LSP Rename to/path/case" })

path/case It is not one of my most used cases, happy to know your experience once you start using it. Please let me know if it fits your requirements!!

johmsalas avatar Jan 12 '24 04:01 johmsalas

By the way, keeping this issue open. Will add "Custom Case support" this weekend

johmsalas avatar Jan 12 '24 04:01 johmsalas

On a second thought, please correct me, there is no much sense on using LSP case change for path case. Perhaps ga/ is a good keybindings

johmsalas avatar Jan 12 '24 15:01 johmsalas

I'm still in early stages of trying out LSP so I don't know whether it would be useful or not.

When I looked into coerce.nvim and noticed path case support I thought that it would be nice to have. I do not know how I missed that it already existed in text-case.nvim.

grimnight avatar Jan 12 '24 20:01 grimnight