aboutsummaryrefslogtreecommitdiffstats
path: root/neovim/.config/nvim/lua/config/keymaps.lua
diff options
context:
space:
mode:
Diffstat (limited to 'neovim/.config/nvim/lua/config/keymaps.lua')
-rw-r--r--neovim/.config/nvim/lua/config/keymaps.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/neovim/.config/nvim/lua/config/keymaps.lua b/neovim/.config/nvim/lua/config/keymaps.lua
new file mode 100644
index 0000000..f0bfbec
--- /dev/null
+++ b/neovim/.config/nvim/lua/config/keymaps.lua
@@ -0,0 +1,37 @@
1local map = vim.keymap.set
2
3-- Switch windows with <C-[direction]>
4map("n", "<C-j>", "<C-w>j")
5map("n", "<C-k>", "<C-w>k")
6map("n", "<C-h>", "<C-w>h")
7map("n", "<C-l>", "<C-w>l")
8
9-- Never use the arrow keys
10for _, key in ipairs({ "<Up>", "<Down>", "<Left>", "<Right>" }) do
11 map({ "n", "i" }, key, "<Nop>")
12end
13
14-- Disable ex mode
15map("n", "Q", "<Nop>")
16
17-- Expand :git to fugitive's :Git, but only as a whole command.
18-- (No Lua-native abbreviation API exists, so this stays a thin vim.cmd call.)
19vim.cmd([[cnoreabbrev <expr> git (getcmdtype() ==# ':' && getcmdline() ==# 'git') ? 'Git' : 'git']])
20
21-- Note: the vimrc's `w!!` sudo-save abbreviation is deliberately NOT ported
22-- here — its own comment says it doesn't work under Neovim (sudo can't
23-- prompt for a password there).
24
25-- Append modeline when pressing <leader>ml
26local function append_modeline()
27 local modeline = string.format(
28 " vim: set ts=%d sw=%d tw=%d %set :",
29 vim.bo.tabstop,
30 vim.bo.shiftwidth,
31 vim.bo.textwidth,
32 vim.bo.expandtab and "" or "no"
33 )
34 modeline = vim.bo.commentstring:gsub("%%s", modeline)
35 vim.api.nvim_buf_set_lines(0, -1, -1, false, { modeline })
36end
37map("n", "<leader>ml", append_modeline, { silent = true })