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

So holding keys is not supported? #67

Open
nyngwang opened this issue Dec 27, 2022 · 4 comments
Open

So holding keys is not supported? #67

nyngwang opened this issue Dec 27, 2022 · 4 comments

Comments

@nyngwang
Copy link

nyngwang commented Dec 27, 2022

Hi, first-time user here. If I press <C-w> with < or > being holding, while it did complete the job specified in function () ... end, it also removed/added indents(i.e. the behavior of << and >>) to the current line where my cursor is on. Is this a bug? The following is my config:

vim.keymap.set('n', '<<', '<nop>')
vim.keymap.set('n', '>>', '<nop>')
Hydra {
  -- hint = [[...]], -- multiline string
  name = "Window Resizing",
  mode = 'n',
  body = '<C-w>',
  heads = {
    -- If no `{exit=true}` head is specified, the <Esc> key will be set by default.
    { '<', function ()
      local org_win = vim.api.nvim_get_current_win()
      vim.cmd('wincmd h')
      if vim.api.nvim_get_current_win() ~= org_win then
        vim.cmd('wincmd <')
      end
      vim.api.nvim_set_current_win(org_win)
    end, { desc = '<-- left border', exit = false, nowait = true } },
    { '>', function ()
      local org_win = vim.api.nvim_get_current_win()
      vim.cmd('wincmd l')
      if vim.api.nvim_get_current_win() == org_win then
        return
      end
      vim.api.nvim_set_current_win(org_win)
      vim.cmd('wincmd >')
    end, { desc = 'right border -->', exit = false, nowait = true } },
  },
  config = {
    exit = false,
    timeout = false, -- manually cancel.
  },
}
@nyngwang nyngwang changed the title So holding key is not supported? So holding keys is not supported? Dec 27, 2022
@EtiamNullam
Copy link

I can reproduce. I've never noticed it before.

For now I'd suggest avoid mapping keys that modify your buffer in some way by default as actions that you want to repeat by holding.

@nyngwang
Copy link
Author

For now I'd suggest avoid mapping keys that modify your buffer in some way by default as actions that you want to repeat by holding.

Understood. But unfortunately this changing the width of the current window by <C-w> with <(or>) holding is the reason I wanted to try this repo. Temporarily leaving now but if you might accidentally find a way to fix it then feel free to tag me.

@EtiamNullam
Copy link

@nyngwang:
I've never managed to get used to <C-w>, so I've remapped it quite early in my vim journey. Also I don't like holding modifiers keys. In your case it's both Ctrl and Shift to resize.

For me it's <Space>wrj where j can be replaced with h, k or l depending on direction of resize. It has semantic meaning as window resize <direction>.

Instead of holding keys I've simply set the step to 10 as a default, so my desired size is always only a few presses away, like :vertical resize +10. Holding would work as well, because in worst case it would simply move cursor a bit.

Anyway the issue still stands and I hope it can be fixed on plugin's end. I would still recommend trying to think of better mappings than vim's defaults, as some of them are pretty bad.

@rsurasin
Copy link

rsurasin commented May 7, 2023

@nyngwang I haven't tried your config. However, here is my config for resizing a window:

local no_timeout = { timeout = false }

Hydra({
    name = 'Resize Windows',
    --hint = win_hint,
    config = {
        color = 'pink',
        buffer = bufnr,
        invoke_on_body = true,
        --hint = {
        --    border = 'rounded'
        --},
    },
    mode = 'n',
    body = '<C-W>',
    heads = {
        { '<', '<C-W>5<', { desc = 'Current window resize narrower' }, no_timeout },
        { '>', '<C-W>5>', { desc = 'Current window resize wider' }, no_timeout },
        { '|', '<C-W>|',  { desc = 'Window takes entire width' }, no_timeout },
        { '-', '<C-W>5-', { desc = 'Current window resize shorter' }, no_timeout },
        { '+', '<C-W>5+', { desc = 'Current window resize taller' }, no_timeout },
        { '_', '<C-W>_',  { desc = 'Window takes entire height' }, no_timeout  },
        { '=', '<C-W>=',  { desc = 'Windows same size' }, no_timeout },
        { 'v', '<C-W>v',  { desc = 'Vertical split' }, no_timeout },
        { 'x', '<C-W>s',  { desc = 'Horizontal split' }, no_timeout },
        { 's', '<C-W>x',  { desc = 'Switch current window w/ next' }, no_timeout },
        { 'q', '<C-W>q',  { desc = 'Close window' }, no_timeout },
        { '<Esc>', nil, { exit = true, nowait = true, desc = 'exit' } },
    },
})

The only bug that I have, which you can see with my commented out code, is that creating the hint table with _ as a head key leads to a runtime error. In my config, I can hold down > and resize the vertical window split to make it wider, and it doesn't do the operation of >>. Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants