Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Show What Keys Neovim Thinks You Pressed

Use Ctrl v in Insert mode to see the Neovim code for the next key or key combo you press

Introduction

I use a moonlander keyboard. One reason I got it is the "layers" feature that lets me setup keys with additional functionality. For example, if I hold down the Enter and press g the keyboard sends Option + Shift + g instead. I have Neovim configured to open my Grimoire when it receives that combo.

My keyboard mappings are kind of all over the place. I can always go look at the configuration to find out what a particular key does on a specific layer. That's not necessary, though. Neovim has a built in feature that displays what's pressed. It looks like this :

The Steps

- Switch to insert mode with i if you aren't already there

- Press Ctrl + v which temporarily outputs a [TODO: Code shorthand span ] character

- Press a key or key combination to see Neovim's representation of what you pressed

The Output

When I hit Enter + g (and the keyboard sends Option + Shift + g ), Neovim displays :

<M-G>

Some things to note about that :

Usage

The reason I need to figure out the details of the keypresses is to set up hotkey triggers in my config. For example, if I wanted Enter + a to print "Hello, World" whenever I pressed it I'd used the techniqe above to fiugre out that Neovim sees it as :

<M-A>

I can use that to make the following to print out "Hello, World" whenever I hit the key in Normal mode.

~/.config/nvim/after/plugin/hello-world.lua

lua
vim.keymap.set('n', '<M-A>', function() 
  print("Hello, World")
end, { desc = "Prints Hello World" })

Wrapping Up

This is one of those small but nice reductions of friction. Since it's so easy to see what my key mappings are I'm a lot more likely to use them. And, I should point out, things aren't always so stright forward, I've got Enter + j mapped to Option + Shift + F11 to avoid conflicting with other mappings. Figuring out what's what quickly is, if you'll forgive the pun, key.

Footnotes And References

  • iTerm2 Set Option To Meta

    Under : iTerm - > Preferences - > Profiles - > Keys

    Switch "Left Option Key" to "Esc+"

    That's what lets Neovim see Option as Meta

  • Answer to: How can I see what keys vim thinks I'm hitting?

    This is where I learned the Neovim incantation to see what it sees when keys are pressed

  • My Moonlander Layout

    This is the current state of my moonlander

  • The Moonlander Keyboard

    And this is what the moonlander looks like if you haven't seen this particular space keyboard before