Chris
@
Machine
Blog
Topics
Neovim Setting keymaps
Useful Keymaps
Create the keymaps file:
touch ~/.config/nvim/lua/user/keymaps.lua
Here are some useful keymappings I use:
local opts = { noremap = true, silent = true } local term_opts = { silent = true } -- Shorten function name local keymap = vim.api.nvim_set_keymap -- Modes -- normal_mode = "n", -- insert_mode = "i", -- visual_mode = "v", -- visual_block_mode = "x", -- term_mode = "t", -- command_mode = "c", -- Normal -- -- Better window navigation keymap("n", "
", "
h", opts) keymap("n", "
", "
j", opts) keymap("n", "
", "
k", opts) keymap("n", "
", "
l", opts) -- Resize with arrows keymap("n", "
", ":resize -2
", opts) keymap("n", "
", ":resize +2
", opts) keymap("n", "
", ":vertical resize -2
", opts) keymap("n", "
", ":vertical resize +2
", opts) -- Naviagate buffers keymap("n", "
", ":bnext
", opts) keymap("n", "
", ":bprevious
", opts) -- Move text up and down keymap("n", "
", "
:m .+1
==gi", opts) keymap("n", "
", "
:m .-2
==gi", opts) -- Insert -- -- Press jk fast to enter keymap("i", "jk", "
", opts) -- Visual -- -- Stay in indent mode keymap("v", "<", "
", ">gv", opts) -- Move text up and down keymap("v", "
", ":m .+1
==", opts) keymap("v", "
", ":m .-2
==", opts) -- Visual Block -- -- Move text up and down keymap("x", "J", ":move '>+1
gv-gv", opts) keymap("x", "K", ":move '<-2
gv-gv", opts) keymap("x", "
", ":move '>+1
gv-gv", opts) keymap("x", "
", ":move '<-2
gv-gv", opts) -- Terminal -- -- Better terminal navigation keymap("t", "
", "
h", term_opts) keymap("t", "
", "
j", term_opts) keymap("t", "
", "
k", term_opts) keymap("t", "
", "
l", term_opts) -- Command -- -- Menu navigation keymap("c", "
", 'pumvisible() ? "\\
" : "\\
"', { expr = true, noremap = true } ) keymap("c", "
", 'pumvisible() ? "\\
" : "\\
"', { expr = true, noremap = true } )
Require in
init.lua
require("user.keymaps")
Tagged in
neovim-s-2
Prev
Next