Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert mode keybindings not working correctly for variable #86

Closed
andrewferrier opened this issue Mar 26, 2024 · 18 comments · Fixed by #136
Closed

Insert mode keybindings not working correctly for variable #86

andrewferrier opened this issue Mar 26, 2024 · 18 comments · Fixed by #136
Assignees
Labels
bug Something isn't working

Comments

@andrewferrier
Copy link
Owner

No description provided.

@andrewferrier andrewferrier added the enhancement New feature or request label Mar 26, 2024
@andrewferrier andrewferrier self-assigned this Mar 26, 2024
@andrewferrier
Copy link
Owner Author

Probably should do #44 first to avoid confusion.

@andrewferrier
Copy link
Owner Author

Closed; no practical need for this, and no-one's asking for it!

@kohane27
Copy link

kohane27 commented Nov 5, 2024

Oh no I was late:( I'm looking for Insert mode support and found this issue. My rationale is that this plugin inserts text to the buffer, so I think it's appropriate to do so while being in Insert mode.

Please allow me to demo with the following example:

async function fetchData() {
    const response = await fetch(API_URL);
    const data = await response.json();
    |
}

The | represents the cursor in Insert mode. Pressing C-g p is more convenient than leaving Insert mode and then press the keybinding in Normal mode.

Before discovering this plugin, I used the following luasnip snippet:

    local log_snippet = s({ trig = "log", wordTrig = true }, {
      f(function()
        local func_name = get_current_function_name()
        return string.format("console.log('%s %s: ', ", func_name)
      end),
      i(1),
      t({ ");" }),
    })

When I type log, I can select the log snippet to expand to console.log with the function name. So I think adding Insert mode support adds more versatility than just "adding debug statements" during debugging; it can actually helps development (i.e., quickly see the result during development, as shown in the example above).

But to be fair, it's rather minor and I'm satisfied with this plugin as-is. Regardless, thank you for developing this awesome plugin! There are valid use cases when adding debugging statements is more than enough over using a debugger.

Thank you again!

@andrewferrier
Copy link
Owner Author

Ok, well, I'm willing to reconsider :) If I added insert mode support I think it would only make sense to do it for 'plain' debug lines, as there's no meaningful way to select a variable (except perhaps with a prompt) would you agree?

@andrewferrier andrewferrier reopened this Nov 5, 2024
@andrewferrier
Copy link
Owner Author

Issue reopened for discussion. I think I could potentially support:

  • Plain lines for insert mode (Ctrl-G, p seems like a good combination)
  • Variable lines for insert mode (Ctrl-G, v)

The variable lines would have to prompt for a variable name I think, because there would have to be an assumption that wherever you were in insert mode you weren't on top of a variable, but instead a fresh line / white space.

@andrewferrier
Copy link
Owner Author

I've implemented this now in the main branch; it's not in a release yet. @kohane27 Please try it out and see how well it works for you :)

@kohane27
Copy link

kohane27 commented Nov 6, 2024

@andrewferrier

Wow! Thank you so much for such a quick response and implementation!

I updated and tried with the following config:

return {
  "andrewferrier/debugprint.nvim",
  opts = {
    keymaps = {
      insert = {
        plain = "<C-G>p",
        variable = "<C-G>v",
      }
    },
  },
}

plain works perfectly but variable is not quite working: After pressing <C-G>v, the cursor becomes a block cursor with no prompt to ask for variable. It is not responding to any keystroke until I pressed Esc:

cursor-block-upload.mp4

Thank you again!

@andrewferrier
Copy link
Owner Author

andrewferrier commented Nov 6, 2024

OK, thanks for the feedback, this is good to know. debugprint uses vim.fn.input() to get the name of that variable, I wonder if something's up with that. I suspect maybe it's conflicting with another plugin you have installed since the tests test it with 'plain' NeoVim, but it may a very commonly used one. Could you help me narrow this down with a few questions please?

  1. Would you mind trying the normal mode variable with prompt (which uses the same underlying mechanism)? Easiest way to do this is to bind something to the alwaysprompt key like this:
    keymaps = {                                
        normal = {                                        
            variable_below_alwaysprompt = "gabc",
        }
    }
  1. Could you try running the following as a command in the command line :lua vim.fn.input('PromptX: '). You should see a prompt and be able to type in a response.

  2. Do you know if you have any plugins which might override or change the standard NeoVim UI behaviour? Do you use a NeoVim distribution like LazyVim for example? If you're able to share a list of your plugins that would be very helpful.

@andrewferrier andrewferrier reopened this Nov 6, 2024
@andrewferrier andrewferrier changed the title Support insert mode keybindings Insert mode keybindings not working correctly Nov 6, 2024
@andrewferrier andrewferrier added bug Something isn't working and removed enhancement New feature or request labels Nov 6, 2024
@andrewferrier andrewferrier changed the title Insert mode keybindings not working correctly Insert mode keybindings not working correctly for variable Nov 6, 2024
@kohane27
Copy link

kohane27 commented Nov 6, 2024

@andrewferrier Sorry that I missed the following crucial info.

I actually have the following config:

return {
  "andrewferrier/debugprint.nvim",
  opts = {
    keymaps = {
      insert = {
        plain = "<C-G>p",
        variable = "<C-G>v",
      },
      normal = {
        plain_below = "<leader>pp",
        plain_above = "<leader>pP",
        variable_below = "<leader>pv",
        variable_above = "<leader>pV",
        variable_below_alwaysprompt = nil,
        variable_above_alwaysprompt = nil,
        textobj_below = nil,
        textobj_above = nil,
        toggle_comment_debug_prints = nil,
        delete_debug_prints = nil,
      },
      visual = {
        variable_below = nil,
        variable_above = nil,
      },
    },
  },
}
  • variable_below shows the prompt
  • variable_below_alwaysprompt = "gabc" also shows the prompt
  • lua vim.fn.input('PromptX: ') also works

Thank you again!

@andrewferrier
Copy link
Owner Author

OK, thanks for doing that further testing. So it seems it really is just that keybinding. I'm testing it with a plain NeoVim with no other plugins and it works, so I think it must be conflicting with something in your setup.

Do you know if you have any plugins which might override or change the standard NeoVim UI behaviour? Do you use a NeoVim distribution like LazyVim for example? If you're able to share a list of your plugins that would be very helpful.

@andrewferrier
Copy link
Owner Author

andrewferrier commented Nov 6, 2024

OK, I managed to recreate this problem the same symptoms by installing folke/noice.nvim; do you happen to use that by any chance?

@andrewferrier
Copy link
Owner Author

Further narrowing of the problem: it appears that with noice, neither vim.fn.input() (which we use today, and is sync) or vim.ui.input() (which is more modern, and async) seems to work in insert mode. They do work OK in normal mode.

@kohane27 it would be helpful to understand if you do use noice. This might be a noice problem but I have to investigate further.

@andrewferrier
Copy link
Owner Author

@kohane27 FYI - I've opened a noice issue as above. My educated guess would be that this is what is causing your issue, but even if not, I think the noice issue is valid standalone anyway.

@kohane27
Copy link

kohane27 commented Nov 8, 2024

@andrewferrier Hello and apologies for my late reply.

You're absolute correct: I'm using noice.nvim. After disabling it, C-g v works as expected: I see the prompt for variable at the EX mode.

One extra info is that, without disabling noice.nvim, Normal mode's variable_below works: the prompt is triggered in noice.nvim's UI.

I'll disable noice.nvim for now.

Regardless, thank you so much for following up and testing it for me; I really appreciate it:)

@andrewferrier
Copy link
Owner Author

Thanks for confirming. Yes, that's the behaviour I would expect; it seems to be only in insert mode that noice has this issue.

Right now I don't think I have a working apart from obviously not using that key or disabling noice. Let's see what happens with the issue I opened.

Thanks!

@andrewferrier
Copy link
Owner Author

@kohane27 I think I've fixed this now, even when noice is installed - I've switched to a different style of mapping which seems to be resilient to this problem. Please update to the latest on the main branch and re-test :)

@kohane27
Copy link

Hello @andrewferrier
I have tested on the latest main branch and debugprint.nvim is working flawlessly in Insert mode with noice.nvim! Even after inserting the debug line, debugprint.nvim is correctly staying in Insert mode. Thank you again and have a nice day!

@andrewferrier
Copy link
Owner Author

Excellent, that's great, thank you for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants