LazyVim / LazyVim

Neovim config for the lazy
https://lazyvim.github.io/
Apache License 2.0
17.71k stars 1.25k forks source link

feature: Unbind <c-l> in terminals to leave the default "clear" shortcut work #4509

Closed metal3d closed 1 month ago

metal3d commented 2 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

When I use the <c-\> keymap, it opens the terminal and that's perfect. But I often use "CTRL+L" to clear the terminal. Unfortunately, the <c-l> keymap makes the cursor going in the "right" widow.

Describe the solution you'd like

Simply add this somewhere:

vim.api.nvim_create_autocmd("TermOpen", {
  pattern = "*",
  callback = function()
    -- unbind <c-l> in terminal
    vim.api.nvim_buf_set_keymap(0, "t", "<C-l>", "<C-l>", { noremap = true, silent = true })
  end
})

Describe alternatives you've considered

No other alternative, I added it inside my keymap to fix the problem - but maybe it could be the default

Additional context

No response

dpetka2001 commented 2 months ago

From what I can guess, this was probably done in mind with also having edgy.nvim enabled. When you have edgy enabled, then the lazyterms are opened at the bottom of the screen and you can open more than one lazyterm next to each other. In that workflow it's quite useful to be able to move across the opened lazyterms with <c-l>/<c-h>.

Now I don't use that workflow and this was just a guess from my part regarding the <c-l> terminal mapping. The maintainer will give you a more definitive answer and if what you're proposing could be a default or belong to the user configuration after all.

metal3d commented 2 months ago

The main problem is that CTRL+L is a common shortcut for many terminals to refresh the view (to clear or redraw the TTY). Binding this shortcut is already an "issue" as we sometimes have some artifacts dues to some errors from plugins (for example).

I can fix it by scrolling, sometimes. But...

But, for floating terminal, it makes the cursor jumping behind, and we lose the focus - so we can break the buffer content that is hidden by the current terminal. And it's not that easy to gain focus again.

Really, C-l should never be binded by any plugin. It's a terminal shortcut, do not override it :)

metal3d commented 2 months ago

I mean: c-l is already necessary in Neovim, even if we don't open a floating terminal, to redraw the terminal where NeoVim is displayed.

dpetka2001 commented 2 months ago

Screencast_2024-10-01-18-41-48.webm

This is the workflow I'm talking about. Also here's a search for <c-l> throughout Github. Lots of people use it even as a terminal mapping. So, I don't believe anyone can say

Really, C-l should never be binded by any plugin. It's a terminal shortcut, do not override it :)

People can do what they want with their configs.

Now, I don't use that particular workflow myself, but I can't doubt that it can be a legit workflow for some people. Probably that was the reason it was added as a default. I don't know for sure, because I didn't choose it, but that would be my guess.

Anyway, the maintainer will see this and will decide.

hirotaka commented 2 months ago

I'm also facing this problem and would like to find a solution.

I like using LazyVim's default ctrl + l to move windows around, but I also want to use ctrl + l to clear the terminal.

Since I use fish, I could save some stress by abbreviating c as clear.

However, this solution is not perfect. I hope someone has a better idea.

dpetka2001 commented 2 months ago

Just disable the terminal mapping specifically then. It's not really a problem when users can change the mappings to their liking. Users can override defaults in their personal configuration. The defaults can't satisfy every single user. And for most defaults there exists also a legit workflow.

metal3d commented 2 months ago

I'm also facing this problem and would like to find a solution.

I like using LazyVim's default ctrl + l to move windows around, but I also want to use ctrl + l to clear the terminal.

Since I use fish, I could save some stress by abbreviating c as clear.

However, this solution is not perfect. I hope someone has a better idea.

My key map isn't working for you? It only disables c-l on terminals.

folke commented 1 month ago

Add the below to your autocmds.lua:

vim.api.nvim_create_autocmd("TermOpen", {
  callback = function(ev)
    vim.keymap.set("t", "<c-l>", "<c-l>", { buffer = ev.buf, nowait = true })
  end,
})
parisni commented 3 days ago

@metal3d @folke tried both proposed approach, and it turns out this partially works. On first terminal creation C-/ it works fine. Once I hide it C-/ and restore it C-/ then <C-l> has no effect anymore.

parisni commented 3 days ago

fixed above issue by replaceing TermOpen with TermEnter callback:

vim.api.nvim_create_autocmd("TermEnter", {
  callback = function(ev)
    vim.keymap.set("t", "<c-l>", "<c-l>", { buffer = ev.buf, nowait = true })
  end,
})