How to use Ctrl+Shift+F keybinding in Neovim?
Hello,
This post is a reference on how to generate `Ctrl+Shift+<key>` keybindings for Neovim. As you know, Vim (apparently) doesn’t support this since some terminal emulators do not pass key combinations.
Theory
What we’ll be doing instead is asking the terminal emulator (in my case Alacritty) to send a different character (
char) when `Ctrl+Shift+<key>` is pressed.So, when the key combination is pressed, a different character will be sent to Neovim.
At Neovim end, we will bind the required Neovim action to this character instead of
C<-S-f>or something.
For my usage, I will be triggering Snacks.picker.grep() whenever I press Ctrl+Shift+F on my keyboard.
I use this particular keyboard shortcut very often in VSCode and so trying to retain the pattern in nvim (for muscle memory’s sake) if possible :)
Implementation
The steps are intended for Alacritty terminal emulator. If you’re using something else, please note, the instructions might be slightly different but you’ll be achieving the same goal here.
Open Alacritty config at
$USER/.config/alacritty/alacritty.tomlAdd the following code snippet below:
# Global search in nvim
# I am using the `https://www.compart.com/en/unicode/U+058D` character as the replacement.
[keyboard]
bindings = [
{ key = "F", mods = "Control|Shift", chars = "֍" },
]
- Now, let’s go to nvim config file at
$HOME/.config/nvim/lua/config/keymaps.lua
-- Global search
map("n", "֍", function() Snacks.picker.grep() end, {desc="Global search", remap = true })
- Save all changes and test. You should see the “Grep” window open inside nvim when you press
Ctrl+Shift+F
Conclusion
This post was quickly put together for reference purposes. Sorry if it didn’t include your specific terminal emulator.
Thanks for reading!
Bye for now :)