So, I recently tried switching my keybinds over to using the Leader key, which I've decided to make the space key, but that doesn't matter that much.
I've adapted to it pretty much instantly and I liked it much more than my old keybinds that were using the Alt key, but this really soon showed its problems: the Leader key, whatever it is set to, is a key that corresponds to a typable character.
Why's that a problem? While it isn't in stuff like my keybinds to switch buffers, for example, it is a problem if such a keybinding is used in order to toggle something that accepts inputting text, like the FTerm plugin, which allows you to run a terminal inside a floating window:
vim.api.nvim_set_keymap('n', '<leader>t', ':lua require("FTerm").toggle()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('t', '<leader>t', '<C-\\><C-n>:lua require("FTerm").toggle()<CR>', { noremap = true, silent = true })
These sorts of keybinds aren't an issue if they're created with a modifier key since keybindings created like that don't result in something getting typed on the screen, but like this they create annoying edge cases like if you'd like to write some text that includes the Leader key in that terminal, it could actually turn on the keybind.
This isn't a technical problem. But since (N)Vim can't detect modifier key presses (being able to do stuff like :map <Alt>t action
), and detecting only modifier key combinations (like :map <A-t> action
), all Leader key keybindings are doomed to be normal mode-only keybinds. So, what I'm asking for is, how would you manage your keybindings for this, but still revolving around using the Leader key?
<space>
and translates it through the mapping?), but: in all the "input" contexts I get in regular vim (including:terminal
and terminals in vim's popups), normal-mode mappings don't apply.;
as your Leader key (which is a popular option) and then want to run your lastf
ort
command (which is done with the same key). Vim will take a 1 second delay for a Leader keybind to be pressed, and then press the actual key once that delay is over with no registered key.sudo<space>touch
will execute a<Leader>t
keybind). What I'm asking for is: I'm out of ideas, how would a person comfortably create a keybind that works well around this?