summaryrefslogtreecommitdiff
path: root/lua/user/keymaps.lua
blob: 12f8ddb983322c394b6efbda5910ab758c83137a (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local opts = { noremap = true, silent = true }

local term_opts = { silent = true }

-- Shorten function name
local keymap = vim.api.nvim_set_keymap

--Remap space as leader key
keymap("", "<Space>", "<Nop>", opts)
vim.g.mapleader = " "
vim.g.maplocalleader = " "

-- Modes
--   normal_mode = "n",
--   insert_mode = "i",
--   visual_mode = "v",
--   visual_block_mode = "x",
--   term_mode = "t",
--   command_mode = "c",

-- Normal --
-- Better window navigation (both hjkl and arrow keys)
keymap("n", "<C-h>", "<C-w>h", opts)
keymap("n", "<C-j>", "<C-w>j", opts)
keymap("n", "<C-k>", "<C-w>k", opts)
keymap("n", "<C-l>", "<C-w>l", opts)
keymap("n", "<C-Left>", "<C-w>h", opts)
keymap("n", "<C-Down>", "<C-w>j", opts)
keymap("n", "<C-Up>", "<C-w>k", opts)
keymap("n", "<C-Right>", "<C-w>l", opts)

-- Better tab navigation (both hjkl and arrow keys)
keymap("n", "<S-h>", "gT", opts)
keymap("n", "<S-l>", "gt", opts)
keymap("n", "<S-Left>", "gT", opts)
keymap("n", "<S-Right>", "gt", opts)

-- Navigate buffers
keymap("n", "<S-Down>", ":bnext<CR>", opts)
keymap("n", "<S-Up>", ":bprevious<CR>", opts)

-- Open Lexplorer
--keymap("n", "<leader>e", ":Lex 30<cr>", opts)

-- Resize with ctrl+shift+arrows
keymap("n", "<C-S-Up>", ":resize -2<CR>", opts)
keymap("n", "<C-S-Down>", ":resize +2<CR>", opts)
keymap("n", "<C-S-Left>", ":vertical resize -2<CR>", opts)
keymap("n", "<C-S-Right>", ":vertical resize +2<CR>", opts)

--[[
-- Navigate buffers
keymap("n", "<S-l>", ":bnext<CR>", opts)
keymap("n", "<S-h>", ":bprevious<CR>", opts)

-- Move text up and down
keymap("n", "<A-j>", "<Esc>:m .+1<CR>==gi", opts)
keymap("n", "<A-k>", "<Esc>:m .-2<CR>==gi", opts)

-- Insert --
-- Press jk fast to enter
keymap("i", "jk", "<ESC>", opts)

-- Visual --
-- Stay in indent mode
keymap("v", "<", "<gv", opts)
keymap("v", ">", ">gv", opts)

-- Move text up and down
keymap("v", "<A-j>", ":m .+1<CR>==", opts)
keymap("v", "<A-k>", ":m .-2<CR>==", opts)
keymap("v", "p", '"_dP', opts)

-- Visual Block --
-- Move text up and down
keymap("x", "J", ":move '>+1<CR>gv-gv", opts)
keymap("x", "K", ":move '<-2<CR>gv-gv", opts)
keymap("x", "<A-j>", ":move '>+1<CR>gv-gv", opts)
keymap("x", "<A-k>", ":move '<-2<CR>gv-gv", opts)

-- Terminal --
-- Better terminal navigation
keymap("t", "<C-h>", "<C-\\><C-N><C-w>h", term_opts)
keymap("t", "<C-j>", "<C-\\><C-N><C-w>j", term_opts)
keymap("t", "<C-k>", "<C-\\><C-N><C-w>k", term_opts)
keymap("t", "<C-l>", "<C-\\><C-N><C-w>l", term_opts)
]]

-- Buffer Options
keymap("n", "<leader>bd", ":b#<CR>:bd#<CR>", opts) --Close buffer without closing window ('b'uffer 'd'elete)
keymap("n", "<leader>bD", ":%bd|e#|bd#<CR>", opts) --Close all buffers except the current buffer
keymap("n", "<leader>bl", ":JABSOpen<CR>", opts)   --Open buffer switcher ('b'uffer 'l'ist)

-- Toggle GUI colors - see colorscheme.lua

-- LSP options - see lsp/handlers.lua

-- Telescope options
keymap("n", "<leader>t<CR>", ":Telescope <CR>", opts)         -- ('t'elescope)
keymap("n", "<leader>tf", ":Telescope find_files<CR>", opts)  -- ('f'ind_files)
keymap("n", "<leader>ts", ":Telescope live_grep<CR>", opts)   -- ('s'tring)
keymap("n", "<leader>tb", ":Telescope buffers<CR>", opts)     -- ('b'uffers)
keymap("n", "<leader>td", ":Telescope diagnostics<CR>", opts) -- ('d'iagnostics)
keymap("n", "<leader>th", ":Telescope keymaps<CR>", opts)     -- ('h'elp)
keymap("n", "<leader>tt", ":Telescope treesitter<CR>", opts)  -- ('t'reesitter)

-- Workspace Options
keymap("n", "<leader>wsh", ":split<CR>", opts) --Horizontal split workspace ('s'plit 'h'orizontal)
keymap("n", "<leader>wsv", ":vs<CR>", opts)    --Vertical split workspace ('s'plit 'v'ertical)