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

Allow custom mappings in popup inputs #21

Open
jemag opened this issue Jan 8, 2022 · 5 comments
Open

Allow custom mappings in popup inputs #21

jemag opened this issue Jan 8, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@jemag
Copy link

jemag commented Jan 8, 2022

Currently Ctrl-w will go into Normal mode instead of deleting the previous word, which would be the usual Insert mode behavior.

I tried customizing the Filesystem mappings in the following way:

      mappings = {
        ["<2-LeftMouse>"] = "open",
        ["<cr>"] = "open",
        ["<C-x>"] = "open_split",
        ["<C-v>"] = "open_vsplit",
        ["<C-w>"] = function()
          vim.cmd([[normal! bcw]])
        end,
...

However I believe this does not work because this mapping is not available inside the "Enter Filter Pattern" popup. Although if it did work, it would also cause problems for when wanting to use Ctrl-w in NeoTreeFloat outside of the filter pattern situation.

Basically, is it possible to restore the normal Ctrl-w behavior inside "Enter Filter Pattern" or allow the user to properly customize the keybindings within that particular situation?

One potential avenue that Telescope is using, is to allow different mappings for different modes:

    mappings = {
      i = {
        -- To disable a keymap, put [map] = false
        -- So, to not map "<C-n>", just put
        -- ["<c-x>"] = false,
        ["<esc>"] = actions.close,
        ["<C-w>"] = function()
          vim.cmd([[normal! bcw]])
        end,
        -- Otherwise, just set the mapping to the function that you want it to be.
        -- ["<C-i>"] = actions.select_horizontal,

        -- Add up multiple actions
        -- ["<CR>"] = actions.select_default + actions.center

        -- You can perform as many actions in a row as you like
        -- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
      },
      n = {
        --[[ ["<C-j>"] = actions.move_selection_next,
        ["<C-k>"] = actions.move_selection_previous,
        ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist, ]]
        -- ["<C-i>"] = my_cool_custom_action,
      },
    },
  },
@cseickel
Copy link
Contributor

cseickel commented Jan 8, 2022

You are correct in that the mappings only apply to the main windows. Let me ask you this, why not make that a global shortcut for insert mode everywhere?

inoremap <c-w> <cmd>normal! bcw<cr>

Then it would apply to the filter input as well.

@jemag
Copy link
Author

jemag commented Jan 8, 2022

I can probably go the global shortcut route as suggested. Although there might be situations down the line where it would still make sense to allow this kind of "Telescope-like" customization of mappings, where you can specify distinct Normal and Insert mode mappings for the plugin only.

If you feel this kind of customization is not worth it, feel free to close the issue.

@cseickel
Copy link
Contributor

cseickel commented Jan 8, 2022

It's definitely worth having, although not the highest priority unless more people are looking for it. I'll leave it open but change the title to make it more generic.

@cseickel cseickel changed the title Ctrl-w to delete word in filter search Allow custom mappings in popup inputs Jan 8, 2022
@cseickel cseickel added the enhancement New feature or request label Jan 8, 2022
@sandangel
Copy link

hi @cseickel I just ran into this issue. I try to hit <esc> to close the popup inputs. The popup was closed, the window is still in insert mode. Is this a bug? or we need to add a custom keymap to also switch to normal mode?

@cseickel
Copy link
Contributor

@sandangel That's a bug that appears to be in the main / v2.x branches. I probably just added it. I'm going to move this to a separate issue.

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

No branches or pull requests

3 participants