VonHeikemen / fine-cmdline.nvim

Enter ex-commands in a nice floating input.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allowing normal mode

jandamm opened this issue · comments

Is there a way to use this commandline in normal mode?

Would be nice to be able to use normal mode to modify the command. Pressing ESC twice would then close the prompt.

So the input uses a special type of buffer called "prompt buffer", in neovim 0.5 and 0.6 this is very buggy. I think they fixed in 0.7 or merge a patch to fix some bugs. So you might have some weird behavior when you go back to insert mode.

It could still be done by adding a keybinding.

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

      imap('<Esc>', function() vim.cmd('stopinsert') end)
      imap('<Esc><Esc>', fn.close)
    end
  }
})

Thanks, I'll try that.
It works for telescope - thought they'd use the prompt buffer as well 🤷‍♂️

Sorry, haven't been able to test this earlier.
It's working mostly fine. But I'm not able to close the prompt with <ESC> when I'm in normal mode.
It only works from insert mode since it's only a chord mapping in insert and not a normal mode mapping for <ESC> to close the prompt.

But it's fine if you don't want to support it at the current time. Maybe it works nicer with 0.7 and could then be an official feature 👍

I want to support normal mode when I see prompt buffers are fixed in a stable version.

Anyway, you can create your own mappings in normal mode, using the built-in function vim.api.nvim_buf_set_keymap. With this in the set_keymaps hook you can close the prompt from normal mode.

local nmap = function(...) vim.api.nvim_buf_set_keymap(0,'n', ...) end
local opts = {noremap = true, silent = true}
nmap('<Esc>', ":lua require('fine-cmdline').fn.close()<CR>", opts)