> ~ biozz / Blog

Not so obvious NeoVim key mappings 2023-07-21

Mapping Enter, Tab and Backspace in NeoVim

Reading time: 2m (221 words)

One of the new hot posts on Reddit caught my attention recently: Your favorite mappings for CR, BS, TAB in normal mode?

Here is what I had in my config at that time:

  • <CR> - nothing
  • <BS> - nothing
  • <TAB> - cycle through buffers (in normal mode)

The first suggestion in the thread was about ciw, but that seemed not usable at all. Then I remembered a screencast from some time ago (I can’t find the source) but the guy used some key combination to visually select the body of the function. At first I thought it was a convenience mapping involving jumping to opened/closed parens. But it turned out, that you can use incremental_selection from nvim-treesitter to acheive that. And I also found another simillar discussion about that.

I figured I might as well map incremental_selection to <CR>, since I don’t use Enter in normal mode.

Here is a snippet of my nvim-treesitter config:

incremental_selection = {
	enable = true,
	keymaps = {
		init_selection = "<CR>",
		scope_incremental = "<CR>",
		node_incremental = "<TAB>",
		node_decremental = "<S-TAB>",
	},
},

I am still getting used to this new mapping and, to be honest, I am not using it as much as I would expect. Most of the time I am hitting Enter accidentally and reallize I have this new amazing feature. Oh, well.