1

The title says it all. I'm trying to map <Equal> to gq behavior in Neovim both when in Normal mode (in that case do gqq) and in Visual mode (in that case do gq) but somehow this is not working.

I've tried:

local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<Equal>', 'gqq', opts)
vim.keymap.set('v', '<Equal>', 'gq', opts)

but that's not it, I'm still missing something, can anyone help me?

New contributor
Rom is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

0

The key <Equal> simply does not exist. The characters will be taken literally and the mappings would work fine if you pressed <Shift-EQUAL> but that's not what anybody wants.

Instead of using a non-existing key code, use the actual key you want to map: =

All codes for special (usually non-printing) keys are found in :help key-codes. There's no <Equal> for regular =. Why would there? = prints just fine.

By the way, to keep in line with other Normal mode commands, I'd suggest == to work on the current line and =<motion> to work on <motion>:

local opts = { noremap = true, silent = true }
vim.keymap.set('n', '==', 'gqq', opts)
vim.keymap.set({'n', 'v'}, '=', 'gq', opts)

As mentioned in the comments, this will shadow the default = functionality. You should probably enable these mappings only for certain filetypes. Usually, gq and related commands are useful to format natural language texts while = is better for formalized languages (read: code).

Personally, I use = a lot (more often than gq) and would not want to miss it.

2
  • Thank you so much, that solved it :)
    – Rom
    Commented yesterday
  • 1
    Ah! Then you lose the = functionality :) Commented yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.