hydra.nvim icon indicating copy to clipboard operation
hydra.nvim copied to clipboard

So holding keys is not supported?

Open nyngwang opened this issue 3 years ago • 4 comments

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 avatar Dec 27 '22 17:12 nyngwang

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.

EtiamNullam avatar Jan 14 '23 17:01 EtiamNullam

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.

nyngwang avatar Jan 15 '23 21:01 nyngwang

@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.

EtiamNullam avatar Jan 15 '23 22:01 EtiamNullam

@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!

rsurasin avatar May 07 '23 16:05 rsurasin