aboutsummaryrefslogtreecommitdiffstats
path: root/neovim/.config/nvim/lua/config/keymaps.lua
blob: f0bfbec872bea988ddb4daac0ec239dfc89898f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local map = vim.keymap.set

-- Switch windows with <C-[direction]>
map("n", "<C-j>", "<C-w>j")
map("n", "<C-k>", "<C-w>k")
map("n", "<C-h>", "<C-w>h")
map("n", "<C-l>", "<C-w>l")

-- Never use the arrow keys
for _, key in ipairs({ "<Up>", "<Down>", "<Left>", "<Right>" }) do
  map({ "n", "i" }, key, "<Nop>")
end

-- Disable ex mode
map("n", "Q", "<Nop>")

-- Expand :git to fugitive's :Git, but only as a whole command.
-- (No Lua-native abbreviation API exists, so this stays a thin vim.cmd call.)
vim.cmd([[cnoreabbrev <expr> git (getcmdtype() ==# ':' && getcmdline() ==# 'git') ? 'Git' : 'git']])

-- Note: the vimrc's `w!!` sudo-save abbreviation is deliberately NOT ported
-- here — its own comment says it doesn't work under Neovim (sudo can't
-- prompt for a password there).

-- Append modeline when pressing <leader>ml
local function append_modeline()
  local modeline = string.format(
    " vim: set ts=%d sw=%d tw=%d %set :",
    vim.bo.tabstop,
    vim.bo.shiftwidth,
    vim.bo.textwidth,
    vim.bo.expandtab and "" or "no"
  )
  modeline = vim.bo.commentstring:gsub("%%s", modeline)
  vim.api.nvim_buf_set_lines(0, -1, -1, false, { modeline })
end
map("n", "<leader>ml", append_modeline, { silent = true })