johmsalas / text-case.nvim

An all in one plugin for converting text case in Neovim
458 stars 18 forks source link

`to_snake_case` is not working? #3

Closed yutkat closed 2 years ago

yutkat commented 2 years ago

I set up the following mapping. nmap gas <Cmd>lua require('textcase').current_word('to_snake_case')<CR>

error occurs

E5108: Error executing lua ...packer/opt/text-case.nvim/lua/textcase/plugin/plugin.lua:183: attempt to index local 'method' (a nil value)
stack traceback:
        ...packer/opt/text-case.nvim/lua/textcase/plugin/plugin.lua:183: in function <...packer/opt/text-case.nvim/lua/textcase/plugin/plugin.lua:181>
johmsalas commented 2 years ago

I haven't explored custom mapping. Can you try using the regular setup? It is to call

require("text case").setup()

There is an example in the readme using Packer. I should probably add examples using other package managers

My guess is the setup method is not registering the methods. If that's the case, once they are registered, I think custom mappings should work out of the box. But the setup itself also initializes mappings with ga as prefix, therefore there is no need to add them by yourself

yutkat commented 2 years ago

I tried to add the gas (snake case) myself because the wiki mentioned it but did not seem to provide the mapping.

https://github.com/johmsalas/text-case.nvim/blob/main/lua/textcase/plugin/presets.lua https://github.com/johmsalas/text-case.nvim/wiki/String-Case-functions

johmsalas commented 2 years ago

Good catch. I added a note in the string case functions page. Let me know if it still fails after calling the setup method (even let me know if it works!)

By the way, I can still make a fix out of this issue. I can change the module so that it register the methods without calling the setup function. And the setup function would be only for registering the keybindings

yutkat commented 2 years ago

I still can't find the command to_snake_case in my environment...

:nmap ga

n  gal         * <Cmd>lua require('textcase').current_word('to_lower_case')<CR>
n  gaL         * <Cmd>lua require('textcase').lsp_rename('to_lower_case')<CR>
n  gaol        * <Cmd>lua require('textcase').operator('to_lower_case')<CR>
n  gau         * <Cmd>lua require('textcase').current_word('to_upper_case')<CR>
n  gaU         * <Cmd>lua require('textcase').lsp_rename('to_upper_case')<CR>
n  gaou        * <Cmd>lua require('textcase').operator('to_upper_case')<CR>
n  gap         * <Cmd>lua require('textcase').current_word('to_pascal_case')<CR>
n  gaP         * <Cmd>lua require('textcase').lsp_rename('to_pascal_case')<CR>
n  gaop        * <Cmd>lua require('textcase').operator('to_pascal_case')<CR>
n  gad         * <Cmd>lua require('textcase').current_word('to_dash_case')<CR>
n  gaD         * <Cmd>lua require('textcase').lsp_rename('to_dash_case')<CR>
n  gaod        * <Cmd>lua require('textcase').operator('to_dash_case')<CR>
n  gac         * <Cmd>lua require('textcase').current_word('to_camel_case')<CR>
n  gaC         * <Cmd>lua require('textcase').lsp_rename('to_camel_case')<CR>
n  gaoc        * <Cmd>lua require('textcase').operator('to_camel_case')<CR>
n  gan         * <Cmd>lua require('textcase').current_word('to_constant_case')<CR>
n  gaN         * <Cmd>lua require('textcase').lsp_rename('to_constant_case')<CR>
n  gaon        * <Cmd>lua require('textcase').operator('to_constant_case')<CR>
use({
    "johmsalas/text-case.nvim",
    event = "VimEnter",
    config = function()
        require("textcase").setup()
    end,
})
johmsalas commented 2 years ago

Hi!

Calling .setup() is not anymore a requirement. setup sets keybinding by default. But if you want to add custom key mappings then setup isn't enforced anymore

When you say. you can't find the command. What does it mean?

Is it using Telescope? If that's the case, just merged a PR providing better description It requires calling setup()

image

Is it calling directly the functions? They are under the api namespace. By the way, it was broken but the last PR fixes it

https://github.com/johmsalas/text-case.nvim/wiki/String-Case-functions

local textcase = require('textcase')
local result = textcase.api.to_dash_case('Dash case')

I haven't setup a template for issues, a good question would be, what are the reproduction steps?

Thanks for your help making better this plugin!

yutkat commented 2 years ago

With the latest version, to_snake_case is not mapped to s by default, but if I map it myself, it's works. Thank you. nmap gas <Cmd>lua require('textcase').current_word('to_snake_case')<CR>

kevintraver commented 1 year ago

This could be updated in the wiki, as it still shows as a default keymap (trigger)