97 lines
3.9 KiB
Lua
97 lines
3.9 KiB
Lua
local map = vim.keymap.set
|
|
local wk = require("which-key")
|
|
|
|
-- better up/down
|
|
map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
|
map({ "n", "x" }, "<Down>", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
|
map({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
|
map({ "n", "x" }, "<Up>", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
|
|
|
-- Move to window using the <ctrl> hjkl keys
|
|
map("n", "<C-h>", "<C-w>h", { desc = "Go to left window", remap = true })
|
|
map("n", "<C-j>", "<C-w>j", { desc = "Go to lower window", remap = true })
|
|
map("n", "<C-k>", "<C-w>k", { desc = "Go to upper window", remap = true })
|
|
map("n", "<C-l>", "<C-w>l", { desc = "Go to right window", remap = true })
|
|
|
|
-- Resize window using <ctrl> arrow keys
|
|
map("n", "<C-Up>", "<cmd>resize +2<cr>", { desc = "Increase window height" })
|
|
map("n", "<C-Down>", "<cmd>resize -2<cr>", { desc = "Decrease window height" })
|
|
map("n", "<C-Left>", "<cmd>vertical resize -2<cr>", { desc = "Decrease window width" })
|
|
map("n", "<C-Right>", "<cmd>vertical resize +2<cr>", { desc = "Increase window width" })
|
|
|
|
-- Move Lines
|
|
map("n", "<A-j>", "<cmd>m .+1<cr>==", { desc = "Move down" })
|
|
map("n", "<A-k>", "<cmd>m .-2<cr>==", { desc = "Move up" })
|
|
map("i", "<A-j>", "<esc><cmd>m .+1<cr>==gi", { desc = "Move down" })
|
|
map("i", "<A-k>", "<esc><cmd>m .-2<cr>==gi", { desc = "Move up" })
|
|
map("v", "<A-j>", ":m '>+1<cr>gv=gv", { desc = "Move down" })
|
|
map("v", "<A-k>", ":m '<-2<cr>gv=gv", { desc = "Move up" })
|
|
|
|
-- buffers
|
|
map("n", "<S-h>", "<cmd>bprevious<cr>", { desc = "Prev buffer" })
|
|
map("n", "<S-l>", "<cmd>bnext<cr>", { desc = "Next buffer" })
|
|
|
|
-- Clear search with <esc>
|
|
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and clear hlsearch" })
|
|
|
|
-- save file
|
|
map({ "i", "x", "n", "s" }, "<C-s>", "<cmd>w<cr><esc>", { desc = "Save file" })
|
|
|
|
-- quit all
|
|
map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit all" })
|
|
|
|
--keywordprg
|
|
map("n", "<leader>K", "<cmd>norm! K<cr>", { desc = "Keywordprg" })
|
|
|
|
-- better indenting
|
|
map("v", "<", "<gv")
|
|
map("v", ">", ">gv")
|
|
|
|
wk.register({["<leader>f"] = { name = "File" }})
|
|
-- new file
|
|
map("n", "<leader>fn", "<cmd>enew<cr>", { desc = "New File" })
|
|
|
|
map("n", "<leader>xl", "<cmd>lopen<cr>", { desc = "Location List" })
|
|
map("n", "<leader>xq", "<cmd>copen<cr>", { desc = "Quickfix List" })
|
|
|
|
map("n", "<leader>ww", "<C-W>p", { desc = "Other window", remap = true })
|
|
map("n", "<leader>wd", "<C-W>c", { desc = "Delete window", remap = true })
|
|
map("n", "<leader>w-", "<C-W>s", { desc = "Split window below", remap = true })
|
|
map("n", "<leader>w|", "<C-W>v", { desc = "Split window right", remap = true })
|
|
map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true })
|
|
map("n", "<leader>|", "<C-W>v", { desc = "Split window right", remap = true })
|
|
|
|
-- tabs
|
|
wk.register({["<leader><tab>"] = { name = "Tabs" }})
|
|
map("n", "<leader><tab>l", "<cmd>tablast<cr>", { desc = "Last Tab" })
|
|
map("n", "<leader><tab>f", "<cmd>tabfirst<cr>", { desc = "First Tab" })
|
|
map("n", "<leader><tab><tab>", "<cmd>tabnew<cr>", { desc = "New Tab" })
|
|
map("n", "<leader><tab>]", "<cmd>tabnext<cr>", { desc = "Next Tab" })
|
|
map("n", "<leader><tab>d", "<cmd>tabclose<cr>", { desc = "Close Tab" })
|
|
map("n", "<leader><tab>[", "<cmd>tabprevious<cr>", { desc = "Previous Tab" })
|
|
|
|
|
|
-- NeoTree
|
|
map("n", "<leader>fe",
|
|
function()
|
|
require("neo-tree.command").execute({ toggle = true, dir = vim.loop.cwd() })
|
|
end, { desc = "NeoTree" }
|
|
)
|
|
map("n", "<leader>e", "<leader>fe", { desc = "NeoTree", remap = true })
|
|
|
|
map("n", "<leader>ge",
|
|
function()
|
|
require("neo-tree.command").execute({ source = "git_status", toggle = true })
|
|
end, { desc = "Git explorer" }
|
|
)
|
|
map("n", "<leader>be",
|
|
function()
|
|
require("neo-tree.command").execute({ source = "buffers", toggle = true })
|
|
end, { desc = "Buffer explorer" }
|
|
)
|
|
|
|
map({"n", "v"}, "<leader>cf",
|
|
function()
|
|
require("conform").format({ async = true, lsp_fallback = true, range = range })
|
|
end, { desc = "Format Code" }
|
|
)
|