VonHeikemen/fine-cmdline.nvim

Navigation with `<C-n>`, `<C-p>` instead of `<Up>`, `<Down>`(arrow keys)

nyngwang opened this issue · 8 comments

As title.

You can do it in your config, call the .setup function with a set_keymaps hook.

require('fine-cmdline').setup({
  hooks = {
    set_keymaps = function(imap, feedkeys)
      local fn = require('fine-cmdline').fn

      imap('<C-n>', fn.up_search_history)
      imap('<C-p>', fn.down_search_history)
    end
  }
})

If you prefer the "simple" history navigation replace up_search_history with up_history, and down_search_history with down_history.

You can do it in your config, call the .setup function with a set_keymaps hook.

This is not what I meant. When the completion list is shown, I want to use <C-n>, <C-p> to change selection.

That's weird. I don't remap <C-n> or <C-p> inside the plugin, they should work. Maybe you have some conflicting keymap in your config.

If you try ctrl + o then use the command :verbose imap <C-p> it should tell you what you have bound in that key.

Yes I use nvim-cmp but I cannot delete it because that is an important plugin. Sorry I have to delete this one.

You don't have to delete anything. I use nvim-cmp, and for me it works fine.

Can you share your config?

The config to your plugin, while already deleted, is similar to your first comment in this thread, I just added something to change its position. The following is a part of nvim-cmp config:

and notice that I didn't set anything related to <C-n>, <C-p>.

use {
  'hrsh7th/nvim-cmp',
  requires = {
    'neovim/nvim-lspconfig',
    'hrsh7th/cmp-buffer',
    'hrsh7th/cmp-path',
    'hrsh7th/cmp-nvim-lua',
    'hrsh7th/cmp-nvim-lsp',
    'hrsh7th/cmp-vsnip',
    'hrsh7th/vim-vsnip'
  },
  config = function()
    local cmp = require'cmp'
    cmp.setup {
      snippet = {
        expand = function(args)
          vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
          -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
          -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
          -- require'snippy'.expand_snippet(args.body) -- For `snippy` users.
        end,
      },
      mapping = {
        -- <option-shift-P/N>
        ['∏'] = cmp.mapping.scroll_docs(-4),
        ['˜'] = cmp.mapping.scroll_docs(4),
        ['<C-o>'] = cmp.mapping.complete(),
        ['<C-c>'] = cmp.mapping.close(),
        ['<C-y>'] = cmp.mapping.confirm({
          behavior = cmp.ConfirmBehavior.Replace,
          select = true
        }),
        -- Tab Completion.
        ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
        ['<S-Tab>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 's' })
      },

So it's not nvim-cmp. It must be something else.

There is a way to unmap them.

require('fine-cmdline').setup({
  hooks = {
    after_mount = function(input)
      vim.api.nvim_buf_del_keymap(input.bufnr, 'i', '<C-p>')
      vim.api.nvim_buf_del_keymap(input.bufnr, 'i', '<C-n>')
    end
  }
})

There is also the vimscript alternative.

-- Use inside the after_mount hook
vim.cmd([[
  iunmap <buffer> <C-n>
  iunmap <buffer> <C-p>
]])

I think one of those should restore the default behavior of those keymaps.

So... I guess that's it. I have no idea what's causing the issue. No way to reproduce it. I'm closing this for now.