nvim/lua/config/keymaps.lua

100 lines
3.1 KiB
Lua
Raw Normal View History

2023-03-08 13:06:56 -05:00
-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here
--
-- Shorten function name
local keymap = vim.keymap.set
-- Silent keymap option
local opts = { silent = true }
2023-03-14 14:30:37 -04:00
-- Remap LazyVim
keymap("n", "<Leader>l", "<Nop>", opts)
keymap("n", "<Leader>lz", "<cmd>:Lazy<cr>", { desc = "Lazy" })
2023-03-08 13:06:56 -05:00
-- Navigate buffers
2023-07-17 11:08:44 -04:00
for _, mode in ipairs({ "n", "i", "x" }) do
keymap(mode, "<M-l>", "<cmd>BufferLineCycleNext<CR>", opts)
keymap(mode, "<M-h>", "<cmd>BufferLineCyclePrev<CR>", opts)
end
2023-03-08 13:06:56 -05:00
keymap("n", "<H>", "<Nop>", opts)
keymap("n", "<L>", "<Nop>", opts)
keymap("n", "<M-L>", ":BufferLineMoveNext<CR>", opts)
keymap("n", "<M-H>", ":BufferLineMovePrev<CR>", opts)
for _, mode in ipairs({ "n", "i", "v" }) do
vim.keymap.set(mode, "<A-1>", "<Cmd>BufferLineGoToBuffer 1<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, "<A-2>", "<Cmd>BufferLineGoToBuffer 2<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, "<A-3>", "<Cmd>BufferLineGoToBuffer 3<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, "<A-4>", "<Cmd>BufferLineGoToBuffer 4<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, "<A-5>", "<Cmd>BufferLineGoToBuffer 5<CR>", { noremap = true, silent = true })
end
2023-06-09 20:53:37 -04:00
-- Clear highlights
keymap("n", "<leader>h", "<cmd>nohlsearch<CR>", opts)
2023-03-14 14:30:37 -04:00
-- Close buffers
keymap("n", "<M-q>", "<cmd>Bdelete<CR>", opts)
keymap("n", "<M-Q>", "<cmd>Bdelete!<CR>", opts)
2023-06-09 20:53:37 -04:00
-- search with '-', for my LatinAmerican layout
2023-03-14 20:51:54 -04:00
keymap("n", "-", "/", opts)
keymap("x", "-", "/", opts)
2023-06-09 20:53:37 -04:00
2023-03-14 20:51:54 -04:00
-- disable arrow keys
keymap("n", "<Right>", "<Nop>", opts)
keymap("n", "<Left>", "<Nop>", opts)
keymap("n", "<Up>", "<Nop>", opts)
keymap("n", "<Down>", "<Nop>", opts)
keymap("i", "<Right>", "<Nop>", opts)
keymap("i", "<Left>", "<Nop>", opts)
keymap("i", "<Up>", "<Nop>", opts)
keymap("i", "<Down>", "<Nop>", opts)
2023-06-09 20:53:37 -04:00
local function clean_screen()
vim.o.number = not vim.o.number
--if not vim.diagnostic.get_next() then return end
if vim.o.number then
vim.diagnostic.show()
vim.opt.signcolumn = "yes"
2023-06-12 16:41:51 -04:00
vim.g.miniindentscope_disable = false
MiniIndentscope.draw()
2023-06-09 20:53:37 -04:00
vim.cmd("syntax on")
2023-06-12 09:07:22 -04:00
vim.cmd("IndentBlanklineEnable")
2023-06-09 20:53:37 -04:00
else
2023-06-12 16:41:51 -04:00
MiniIndentscope.undraw()
vim.g.miniindentscope_disable = true
2023-06-09 20:53:37 -04:00
vim.diagnostic.hide()
vim.opt.signcolumn = "no"
vim.cmd("syntax off")
2023-06-12 09:07:22 -04:00
vim.cmd("IndentBlanklineDisable")
2023-06-09 20:53:37 -04:00
end
end
keymap("n", "<leader>n", clean_screen, opts)
2023-06-09 08:10:32 -04:00
function vim.getVisualSelection()
2023-06-09 20:53:37 -04:00
vim.cmd('noau normal! "vy"')
local text = vim.fn.getreg("v")
vim.fn.setreg("v", {})
2023-06-09 08:10:32 -04:00
2023-06-09 20:53:37 -04:00
text = string.gsub(text, "\n", "")
if #text > 0 then
return text
else
return ""
end
2023-06-09 08:10:32 -04:00
end
2023-06-09 20:53:37 -04:00
keymap("v", "<space>sw", function()
local tb = require("telescope.builtin")
local text = vim.getVisualSelection()
tb.live_grep({ default_text = text })
2023-06-09 08:10:32 -04:00
end, opts)
2023-06-12 09:07:22 -04:00
keymap("n", "<S-ScrollWheelDown>", "5zl")
keymap("n", "<S-ScrollWheelUp>", "5zh")
keymap("i", "<S-ScrollWheelDown>", "5zl")
keymap("i", "<S-ScrollWheelUp>", "5zh")
keymap("x", "<S-ScrollWheelDown>", "5zl")
keymap("x", "<S-ScrollWheelUp>", "5zh")