2024-11-10 11:23:44 +00:00
|
|
|
vim.g.mapleader = " "
|
|
|
|
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
|
2024-11-10 16:38:56 +00:00
|
|
|
vim.keymap.set("n", "<C-n>", ":Neotree right filesystem toggle<CR>")
|
2024-11-10 11:23:44 +00:00
|
|
|
|
|
|
|
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
|
|
|
|
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
|
|
|
|
|
|
|
|
vim.keymap.set("n", "J", "mzJ`z")
|
|
|
|
vim.keymap.set("n", "<C-]>", "<C-d>zz")
|
|
|
|
vim.keymap.set("n", "<C-[>", "<C-u>zz")
|
|
|
|
vim.keymap.set("n", "<C-}>", "<C-}>zz")
|
|
|
|
vim.keymap.set("n", "<C-{>", "<C-{>zz")
|
|
|
|
vim.keymap.set("n", "n", "nzzzv")
|
|
|
|
vim.keymap.set("n", "N", "Nzzzv")
|
|
|
|
vim.keymap.set("n", "<tab>", "<nop>")
|
2024-11-10 16:40:17 +00:00
|
|
|
vim.keymap.set("n", "<A-m>", "<C-6>")
|
2024-11-10 11:23:44 +00:00
|
|
|
|
2024-11-10 11:54:25 +00:00
|
|
|
-- terminal remaps
|
|
|
|
vim.keymap.set("t", "<Esc>", "<C-\\><C-n>", { noremap = true, silent = true })
|
2024-11-10 15:58:00 +00:00
|
|
|
-- vim.keymap.set("n", "<leader>;", ":vsplit term://left<CR><A-Right><CR>", { noremap = true, silent = true })
|
2024-11-10 16:29:00 +00:00
|
|
|
|
2024-11-10 16:36:32 +00:00
|
|
|
local term_buf = nil
|
|
|
|
|
2024-11-10 16:33:13 +00:00
|
|
|
function toggleTerminal()
|
2024-11-10 16:36:32 +00:00
|
|
|
-- If we already have a terminal buffer and it's hidden, reopen it
|
|
|
|
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
|
|
|
-- If the terminal is open in the current window, hide it
|
|
|
|
if vim.api.nvim_get_current_buf() == term_buf then
|
|
|
|
vim.cmd("close")
|
|
|
|
else
|
|
|
|
-- Otherwise, open the terminal buffer in a split at the bottom
|
|
|
|
vim.cmd("belowright split | resize " .. math.floor(vim.o.lines * 0.25))
|
|
|
|
vim.api.nvim_set_current_buf(term_buf)
|
|
|
|
vim.cmd("startinsert")
|
|
|
|
end
|
2024-11-10 16:33:13 +00:00
|
|
|
else
|
2024-11-10 16:36:32 +00:00
|
|
|
-- If no terminal buffer exists, create a new one
|
2024-11-10 16:25:22 +00:00
|
|
|
vim.cmd("belowright split | resize " .. math.floor(vim.o.lines * 0.25))
|
|
|
|
vim.cmd("terminal")
|
|
|
|
vim.cmd("startinsert")
|
2024-11-10 16:36:32 +00:00
|
|
|
term_buf = vim.api.nvim_get_current_buf() -- Store the terminal buffer ID
|
|
|
|
end -- Check if the current buffer is a terminal
|
2024-11-10 16:33:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
vim.keymap.set("n", "<C-o>", toggleTerminal, { noremap = true, silent = true })
|
|
|
|
vim.keymap.set("v", "<C-o>", toggleTerminal, { noremap = true, silent = true })
|
|
|
|
vim.keymap.set("i", "<C-o>", toggleTerminal, { noremap = true, silent = true })
|
|
|
|
vim.keymap.set("t", "<C-o>", toggleTerminal, { noremap = true, silent = true })
|
2024-11-10 11:54:25 +00:00
|
|
|
|
|
|
|
-- Terminal mode mappings (Alt + hjkl and Alt + Arrow Keys)
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-h>', '<C-\\><C-N><C-w>h', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-j>', '<C-\\><C-N><C-w>j', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-k>', '<C-\\><C-N><C-w>k', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-l>', '<C-\\><C-N><C-w>l', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-Left>', '<C-\\><C-N><C-w>h', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-Down>', '<C-\\><C-N><C-w>j', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-Up>', '<C-\\><C-N><C-w>k', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<A-Right>', '<C-\\><C-N><C-w>l', { noremap = true, silent = true })
|
|
|
|
|
|
|
|
-- Insert mode mappings (Alt + hjkl and Alt + Arrow Keys)
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-h>', '<C-\\><C-N><C-w>h', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-j>', '<C-\\><C-N><C-w>j', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-k>', '<C-\\><C-N><C-w>k', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-l>', '<C-\\><C-N><C-w>l', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-Left>', '<C-\\><C-N><C-w>h', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-Down>', '<C-\\><C-N><C-w>j', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-Up>', '<C-\\><C-N><C-w>k', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('i', '<A-Right>', '<C-\\><C-N><C-w>l', { noremap = true, silent = true })
|
|
|
|
|
|
|
|
-- Normal mode mappings (Alt + hjkl and Alt + Arrow Keys)
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-h>', '<C-w>h', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-j>', '<C-w>j', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-k>', '<C-w>k', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-l>', '<C-w>l', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-Left>', '<C-w>h', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-Down>', '<C-w>j', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-Up>', '<C-w>k', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<A-Right>', '<C-w>l', { noremap = true, silent = true })
|
|
|
|
|
2024-11-11 11:57:16 +00:00
|
|
|
-- Resize splits with Ctrl+Shift+h/j/k/l
|
|
|
|
vim.api.nvim_set_keymap('n', '<S-Left>', ':vertical resize +2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<S-Down>', ':resize -2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<S-Up>', ':resize +2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('n', '<S-Right>', ':vertical resize -2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<S-Left>', '<C-\\><C-O>:vertical resize +2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<S-Down>', '<C-\\><C-O>:horizontal resize -2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<S-Up>', '<C-\\><C-O>:resize +2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('t', '<S-Right>', '<C-\\><C-O>:vertical resize -2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('v', '<S-Left>', ':vertical resize +2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('v', '<S-Down>', ':resize -2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('v', '<S-Up>', ':resize +2<CR>', { noremap = true, silent = true })
|
|
|
|
vim.api.nvim_set_keymap('v', '<S-Right>', ':vertical resize -2<CR>', { noremap = true, silent = true })
|
2024-11-10 16:11:33 +00:00
|
|
|
-- swap between windows
|
2024-11-10 16:43:38 +00:00
|
|
|
vim.keymap.set("n", ";", "<C-w>w")
|
|
|
|
vim.keymap.set("v", ";", "<C-w>w")
|
2024-11-10 16:11:33 +00:00
|
|
|
vim.api.nvim_set_keymap("t", "<A-m>", "<C-\\><C-O><C-w>w", { noremap = true, silent = true })
|
|
|
|
|
2024-11-10 11:23:44 +00:00
|
|
|
-- greatest remap ever
|
|
|
|
vim.keymap.set("x", "<leader>p", [["_dP]])
|
|
|
|
|
|
|
|
-- next greatest remap ever : asbjornHaland
|
|
|
|
vim.keymap.set({"n", "v"}, "<leader>y", [["+y]])
|
|
|
|
vim.keymap.set("n", "<leader>Y", [["+Y]])
|
|
|
|
|
|
|
|
vim.keymap.set({"n", "v"}, "<leader>d", [["_d]])
|
|
|
|
|
|
|
|
-- This is going to get me cancelled
|
|
|
|
vim.keymap.set("i", "<C-c>", "<Esc>")
|
|
|
|
|
|
|
|
vim.keymap.set("n", "Q", "<nop>")
|
|
|
|
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format)
|
|
|
|
|
|
|
|
vim.keymap.set("n", "<A-k>", "<cmd>cnext<CR>zz")
|
|
|
|
vim.keymap.set("n", "<A-j>", "<cmd>cprev<CR>zz")
|
|
|
|
vim.keymap.set("n", "<leader>k", "<cmd>lnext<CR>zz")
|
|
|
|
vim.keymap.set("n", "<leader>j", "<cmd>lprev<CR>zz")
|
|
|
|
|
|
|
|
vim.keymap.set("n", "<leader>s", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
|
|
|
|
|
|
|
|
vim.keymap.set("n", "<leader>so", function()
|
|
|
|
vim.cmd("so")
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Function to get config directory based on OS
|
|
|
|
local function get_config_dir()
|
|
|
|
if vim.fn.has('win32') == 1 then
|
|
|
|
return vim.fn.stdpath('config')
|
|
|
|
else
|
|
|
|
return '~/.config/nvim'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Create the mapping
|
|
|
|
vim.keymap.set('n', '<leader>cd', function()
|
|
|
|
-- Get the config directory
|
|
|
|
local config_dir = get_config_dir()
|
|
|
|
|
|
|
|
-- Change to the config directory
|
|
|
|
vim.cmd('cd ' .. config_dir)
|
|
|
|
|
|
|
|
-- Open file explorer in the config directory
|
|
|
|
vim.cmd('Ex ' .. config_dir)
|
|
|
|
end, { desc = 'Jump to Neovim config directory' })
|
|
|
|
|
2024-11-11 12:14:16 +00:00
|
|
|
vim.g.is_maximized = false
|
|
|
|
vim.g.original_height = 0
|
|
|
|
vim.g.original_width = 0
|
|
|
|
|
|
|
|
function ToggleZen()
|
|
|
|
if vim.g.is_maximized then
|
|
|
|
-- Restore original size
|
|
|
|
if vim.g.original_height > 0 then vim.cmd('resize ' .. vim.g.original_height) end
|
|
|
|
if vim.g.original_width > 0 then vim.cmd('vertical resize ' .. vim.g.original_width) end
|
|
|
|
vim.g.is_maximized = false
|
|
|
|
else
|
|
|
|
-- Save current dimensions
|
|
|
|
vim.g.original_height = vim.fn.winheight(0)
|
|
|
|
vim.g.original_width = vim.fn.winwidth(0)
|
|
|
|
|
|
|
|
-- Check if the buffer is a terminal
|
|
|
|
if vim.bo.buftype == "terminal" then
|
|
|
|
-- Maximize height only
|
|
|
|
vim.cmd('resize')
|
|
|
|
else
|
|
|
|
-- Maximize both height and width
|
|
|
|
vim.cmd('resize')
|
|
|
|
vim.cmd('vertical resize')
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.g.is_maximized = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.keymap.set('n', '<A-z>', ToggleZen, { desc = 'Zen Mode' })
|
|
|
|
vim.keymap.set('v', '<A-z>', ToggleZen, { desc = 'Zen Mode' })
|
|
|
|
vim.keymap.set('i', '<A-z>', ToggleZen, { desc = 'Zen Mode' })
|
2024-11-11 12:57:17 +00:00
|
|
|
vim.keymap.set('t', '<A-z>', ToggleZen, { desc = 'Zen Mode' })
|