init
This commit is contained in:
127
nvim/lua/config/autocmds.lua
Normal file
127
nvim/lua/config/autocmds.lua
Normal file
@@ -0,0 +1,127 @@
|
||||
local ac = vim.api.nvim_create_autocmd
|
||||
local ag = vim.api.nvim_create_augroup
|
||||
|
||||
-- Disable diagnostics in a .env file
|
||||
ac("BufRead", {
|
||||
pattern = ".env",
|
||||
callback = function()
|
||||
vim.diagnostic.disable(false)
|
||||
end,
|
||||
})
|
||||
|
||||
local auto_close_filetype = {
|
||||
"lazy",
|
||||
"mason",
|
||||
"lspinfo",
|
||||
"toggleterm",
|
||||
"null-ls-info",
|
||||
"TelescopePrompt",
|
||||
"notify",
|
||||
}
|
||||
|
||||
-- Auto close window when leaving
|
||||
ac("BufLeave", {
|
||||
group = ag("lazyvim_auto_close_win", { clear = true }),
|
||||
callback = function(event)
|
||||
local ft = vim.api.nvim_buf_get_option(event.buf, "filetype")
|
||||
|
||||
if vim.fn.index(auto_close_filetype, ft) ~= -1 then
|
||||
local winids = vim.fn.win_findbuf(event.buf)
|
||||
for _, win in pairs(winids) do
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Disable leader and localleader for some filetypes
|
||||
ac("FileType", {
|
||||
group = ag("lazyvim_unbind_leader_key", { clear = true }),
|
||||
pattern = {
|
||||
"lazy",
|
||||
"mason",
|
||||
"lspinfo",
|
||||
"toggleterm",
|
||||
"null-ls-info",
|
||||
"neo-tree-popup",
|
||||
"TelescopePrompt",
|
||||
"notify",
|
||||
"floaterm",
|
||||
},
|
||||
callback = function(event)
|
||||
vim.keymap.set("n", "<leader>", "<nop>", { buffer = event.buf, desc = "" })
|
||||
vim.keymap.set("n", "<localleader>", "<nop>", { buffer = event.buf, desc = "" })
|
||||
end,
|
||||
})
|
||||
|
||||
-- Delete number column on terminals
|
||||
ac("TermOpen", {
|
||||
callback = function()
|
||||
vim.cmd("setlocal listchars= nonumber norelativenumber")
|
||||
vim.cmd("setlocal nospell")
|
||||
end,
|
||||
})
|
||||
|
||||
-- Disable next line comments
|
||||
ac("BufEnter", {
|
||||
callback = function()
|
||||
vim.cmd("set formatoptions-=cro")
|
||||
vim.cmd("setlocal formatoptions-=cro")
|
||||
end,
|
||||
})
|
||||
|
||||
-- Disable eslint on node_modules
|
||||
ac({ "BufNewFile", "BufRead" }, {
|
||||
group = ag("DisableEslintOnNodeModules", { clear = true }),
|
||||
pattern = { "**/node_modules/**", "node_modules", "/node_modules/*" },
|
||||
callback = function()
|
||||
vim.diagnostic.disable(false)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Toggle between relative/absolute line numbers
|
||||
local numbertoggle = ag("numbertoggle", { clear = true })
|
||||
ac({ "BufEnter", "FocusGained", "InsertLeave", "CmdlineLeave", "WinEnter" }, {
|
||||
pattern = "*",
|
||||
group = numbertoggle,
|
||||
callback = function()
|
||||
if vim.o.nu and vim.api.nvim_get_mode().mode ~= "i" then
|
||||
vim.opt.relativenumber = true
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
ac({ "BufLeave", "FocusLost", "InsertEnter", "CmdlineEnter", "WinLeave" }, {
|
||||
pattern = "*",
|
||||
group = numbertoggle,
|
||||
callback = function()
|
||||
if vim.o.nu then
|
||||
vim.opt.relativenumber = false
|
||||
vim.cmd.redraw()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Create a dir when saving a file if it doesnt exist
|
||||
ac("BufWritePre", {
|
||||
group = ag("auto_create_dir", { clear = true }),
|
||||
callback = function(args)
|
||||
if args.match:match("^%w%w+://") then
|
||||
return
|
||||
end
|
||||
local file = vim.uv.fs_realpath(args.match) or args.match
|
||||
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
|
||||
end,
|
||||
})
|
||||
|
||||
-- Toggle lazygit instead of closing
|
||||
ac("TermOpen", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
local term_title = vim.b.term_title
|
||||
if term_title and term_title:match("lazygit") then
|
||||
-- Create lazygit specific mappings
|
||||
vim.keymap.set("t", "q", "<cmd>close<cr>", { buffer = true })
|
||||
end
|
||||
end,
|
||||
})
|
||||
248
nvim/lua/config/keymaps.lua
Normal file
248
nvim/lua/config/keymaps.lua
Normal file
@@ -0,0 +1,248 @@
|
||||
local map = vim.keymap.set
|
||||
local o = vim.opt
|
||||
|
||||
local lazy = require("lazy")
|
||||
|
||||
-- Search current word
|
||||
local searching_brave = function()
|
||||
vim.fn.system({ "xdg-open", "https://search.brave.com/search?q=" .. vim.fn.expand("<cword>") })
|
||||
end
|
||||
map("n", "<leader>?", searching_brave, { noremap = true, silent = true, desc = "Search Current Word on Brave Search" })
|
||||
|
||||
-- Lazy options
|
||||
map("n", "<leader>l", "<Nop>")
|
||||
map("n", "<leader>ll", "<cmd>Lazy<cr>", { desc = "Lazy" })
|
||||
-- stylua: ignore start
|
||||
map("n", "<leader>ld", function() vim.fn.system({ "xdg-open", "https://lazyvim.org" }) end, { desc = "LazyVim Docs" })
|
||||
map("n", "<leader>lr", function() vim.fn.system({ "xdg-open", "https://github.com/LazyVim/LazyVim" }) end, { desc = "LazyVim Repo" })
|
||||
map("n", "<leader>lx", "<cmd>LazyExtras<cr>", { desc = "Extras" })
|
||||
map("n", "<leader>lc", function() LazyVim.news.changelog() end, { desc = "LazyVim Changelog" })
|
||||
|
||||
map("n", "<leader>lu", function() lazy.update() end, { desc = "Lazy Update" })
|
||||
map("n", "<leader>lC", function() lazy.check() end, { desc = "Lazy Check" })
|
||||
map("n", "<leader>ls", function() lazy.sync() end, { desc = "Lazy Sync" })
|
||||
-- stylua: ignore end
|
||||
|
||||
-- Disable LazyVim bindings
|
||||
map("n", "<leader>L", "<Nop>")
|
||||
map("n", "<leader>fT", "<Nop>")
|
||||
|
||||
-- Identation
|
||||
map("n", "<", "<<", { desc = "Deindent" })
|
||||
map("n", ">", ">>", { desc = "Indent" })
|
||||
|
||||
-- Save without formatting
|
||||
map("n", "<A-s>", "<cmd>noautocmd w<CR>", { desc = "Save Without Formatting" })
|
||||
|
||||
-- Cursor navigation on insert mode
|
||||
map("i", "<M-h>", "<left>", { desc = "Move Cursor Left" })
|
||||
map("i", "<M-l>", "<right>", { desc = "Move Cursor Left" })
|
||||
map("i", "<M-j>", "<down>", { desc = "Move Cursor Left" })
|
||||
map("i", "<M-k>", "<up>", { desc = "Move Cursor Left" })
|
||||
|
||||
-- End of the word backwards
|
||||
map("n", "E", "ge")
|
||||
|
||||
-- Increment/decrement
|
||||
map("n", "+", "<C-a>")
|
||||
map("n", "-", "<C-x>")
|
||||
|
||||
-- Tabs
|
||||
map("n", "]<tab>", "<cmd>tabnext<cr>", { desc = "Next Tab" })
|
||||
map("n", "[<tab>", "<cmd>tabprevious<cr>", { desc = "Previous Tab" })
|
||||
map("n", "<tab>", "<cmd>tabnext<cr>", { desc = "Next Tab" })
|
||||
map("n", "<s-tab>", "<cmd>tabprevious<cr>", { desc = "Previous Tab" })
|
||||
for i = 1, 9 do
|
||||
map("n", "<leader><tab>" .. i, "<cmd>tabn " .. i .. "<cr>", { desc = "Tab " .. i })
|
||||
end
|
||||
map("n", "<leader>f<tab>", function()
|
||||
vim.ui.select(vim.api.nvim_list_tabpages(), {
|
||||
prompt = "Select Tab:",
|
||||
format_item = function(tabid)
|
||||
local wins = vim.api.nvim_tabpage_list_wins(tabid)
|
||||
local not_floating_win = function(winid)
|
||||
return vim.api.nvim_win_get_config(winid).relative == ""
|
||||
end
|
||||
wins = vim.tbl_filter(not_floating_win, wins)
|
||||
local bufs = {}
|
||||
for _, win in ipairs(wins) do
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
local buftype = vim.api.nvim_get_option_value("buftype", { buf = buf })
|
||||
if buftype ~= "nofile" then
|
||||
local fname = vim.api.nvim_buf_get_name(buf)
|
||||
table.insert(bufs, vim.fn.fnamemodify(fname, ":t"))
|
||||
end
|
||||
end
|
||||
local tabnr = vim.api.nvim_tabpage_get_number(tabid)
|
||||
local cwd = string.format(" %8s: ", vim.fn.fnamemodify(vim.fn.getcwd(-1, tabnr), ":t"))
|
||||
local is_current = vim.api.nvim_tabpage_get_number(0) == tabnr and "✸" or " "
|
||||
return tabnr .. is_current .. cwd .. table.concat(bufs, ", ")
|
||||
end,
|
||||
}, function(tabid)
|
||||
if tabid ~= nil then
|
||||
vim.cmd(tabid .. "tabnext")
|
||||
end
|
||||
end)
|
||||
end, { desc = "Tabs" })
|
||||
|
||||
-- Buffers
|
||||
map("n", "<leader>bf", "<cmd>bfirst<cr>", { desc = "First Buffer" })
|
||||
map("n", "<leader>ba", "<cmd>blast<cr>", { desc = "Last Buffer" })
|
||||
map("n", "<leader>b<tab>", "<cmd>tabnew %<cr>", { desc = "Current Buffer in New Tab" })
|
||||
|
||||
-- Toggle statusline
|
||||
map("n", "<leader>uS", function()
|
||||
if o.laststatus:get() == 0 then
|
||||
o.laststatus = 3
|
||||
else
|
||||
o.laststatus = 0
|
||||
end
|
||||
end, { desc = "Toggle Statusline" })
|
||||
|
||||
-- Comment box
|
||||
map("n", "]/", "/\\S\\zs\\s*╭<CR>zt", { desc = "Next Block Comment" })
|
||||
map("n", "[/", "?\\S\\zs\\s*╭<CR>zt", { desc = "Prev Block Comment" })
|
||||
|
||||
-- Plugin Info
|
||||
map("n", "<leader>cif", "<cmd>LazyFormatInfo<cr>", { desc = "Formatting" })
|
||||
map("n", "<leader>cic", "<cmd>ConformInfo<cr>", { desc = "Conform" })
|
||||
local linters = function()
|
||||
local linters_attached = require("lint").linters_by_ft[vim.bo.filetype]
|
||||
local buf_linters = {}
|
||||
|
||||
if not linters_attached then
|
||||
LazyVim.warn("No linters attached", { title = "Linter" })
|
||||
return
|
||||
end
|
||||
|
||||
for _, linter in pairs(linters_attached) do
|
||||
table.insert(buf_linters, linter)
|
||||
end
|
||||
|
||||
local unique_client_names = table.concat(buf_linters, ", ")
|
||||
local linters = string.format("%s", unique_client_names)
|
||||
|
||||
LazyVim.notify(linters, { title = "Linter" })
|
||||
end
|
||||
map("n", "<leader>ciL", linters, { desc = "Lint" })
|
||||
map("n", "<leader>cir", "<cmd>LazyRoot<cr>", { desc = "Root" })
|
||||
|
||||
-- U for redo
|
||||
map("n", "U", "<C-r>", { desc = "Redo" })
|
||||
|
||||
-- Copy whole text to clipboard
|
||||
map("n", "<C-c>", ":%y+<CR>", { desc = "Copy Whole Text to Clipboard", silent = true })
|
||||
|
||||
-- Motion
|
||||
map("c", "<C-a>", "<C-b>", { desc = "Start Of Line" })
|
||||
map("i", "<C-a>", "<Home>", { desc = "Start Of Line" })
|
||||
map("i", "<C-e>", "<End>", { desc = "End Of Line" })
|
||||
|
||||
-- Select all text
|
||||
map("n", "<C-e>", "gg<S-V>G", { desc = "Select all Text", silent = true, noremap = true })
|
||||
|
||||
-- Paste options
|
||||
map("i", "<C-v>", '<C-r>"', { desc = "Paste on Insert Mode" })
|
||||
map("v", "p", '"_dP', { desc = "Paste Without Overwriting" })
|
||||
|
||||
-- Delete and change without yanking
|
||||
map({ "n", "x" }, "<A-d>", '"_d', { desc = "Delete Without Yanking" })
|
||||
map({ "n", "x" }, "<A-c>", '"_c', { desc = "Change Without Yanking" })
|
||||
|
||||
-- Deleting without yanking empty line
|
||||
map("n", "dd", function()
|
||||
local is_empty_line = vim.api.nvim_get_current_line():match("^%s*$")
|
||||
if is_empty_line then
|
||||
return '"_dd'
|
||||
else
|
||||
return "dd"
|
||||
end
|
||||
end, { noremap = true, expr = true, desc = "Don't Yank Empty Line to Clipboard" })
|
||||
|
||||
-- Search inside visually highlighted text
|
||||
map("x", "g/", "<esc>/\\%V", { silent = false, desc = "Search Inside Visual Selection" })
|
||||
|
||||
-- Search visually selected text (slightly better than builtins in Neovim>=0.8)
|
||||
map("x", "*", [[y/\V<C-R>=escape(@", '/\')<CR><CR>]], { desc = "Search Selected Text", silent = true })
|
||||
map("x", "#", [[y?\V<C-R>=escape(@", '?\')<CR><CR>]], { desc = "Search Selected Text (Backwards)", silent = true })
|
||||
|
||||
-- Dashboard
|
||||
map("n", "<leader>fd", function()
|
||||
if LazyVim.has("snacks.nvim") then
|
||||
Snacks.dashboard()
|
||||
elseif LazyVim.has("alpha-nvim") then
|
||||
require("alpha").start(true)
|
||||
elseif LazyVim.has("dashboard-nvim") then
|
||||
vim.cmd("Dashboard")
|
||||
end
|
||||
end, { desc = "Dashboard" })
|
||||
|
||||
-- Spelling
|
||||
map("n", "<leader>!", "zg", { desc = "Add Word to Dictionary" })
|
||||
map("n", "<leader>@", "zug", { desc = "Remove Word from Dictionary" })
|
||||
|
||||
-- Terminal Stuff
|
||||
if not LazyVim.has("floaterm.nvim") or not LazyVim.has("toggleterm.nvim") then
|
||||
local lazyterm = function()
|
||||
Snacks.terminal(nil, { size = { width = 0.8, height = 0.8 }, cwd = LazyVim.root() })
|
||||
end
|
||||
map("n", "<leader>ft", lazyterm, { desc = "Terminal (Root Dir)" })
|
||||
map("n", "<leader>fT", function()
|
||||
Snacks.terminal(nil, { size = { width = 0.8, height = 0.8 }, cwd = vim.fn.getcwd() })
|
||||
end, { desc = "Terminal (cwd)" })
|
||||
map("n", [[<c-\>]], lazyterm, { desc = "Terminal (Root Dir)" })
|
||||
map("t", [[<c-\>]], "<cmd>close<cr>", { desc = "Hide Terminal" })
|
||||
end
|
||||
|
||||
-- Marks
|
||||
map("n", "dm", function()
|
||||
local cur_line = vim.fn.line(".")
|
||||
-- Delete buffer local mark
|
||||
for _, mark in ipairs(vim.fn.getmarklist("%")) do
|
||||
if mark.pos[2] == cur_line and mark.mark:match("[a-zA-Z]") then
|
||||
vim.api.nvim_buf_del_mark(0, string.sub(mark.mark, 2, #mark.mark))
|
||||
return
|
||||
end
|
||||
end
|
||||
-- Delete global marks
|
||||
local cur_buf = vim.api.nvim_win_get_buf(vim.api.nvim_get_current_win())
|
||||
for _, mark in ipairs(vim.fn.getmarklist()) do
|
||||
if mark.pos[1] == cur_buf and mark.pos[2] == cur_line and mark.mark:match("[a-zA-Z]") then
|
||||
vim.api.nvim_buf_del_mark(0, string.sub(mark.mark, 2, #mark.mark))
|
||||
return
|
||||
end
|
||||
end
|
||||
end, { noremap = true, desc = "Mark on Current Line" })
|
||||
|
||||
-- Empty Line
|
||||
map("n", "gO", "<Cmd>call append(line('.') - 1, repeat([''], v:count1))<CR>", { desc = "Empty Line Above" })
|
||||
map("n", "go", "<Cmd>call append(line('.'), repeat([''], v:count1))<CR>", { desc = "Empty Line Below" })
|
||||
|
||||
-- Insert Mode
|
||||
map({ "c", "i", "t" }, "<M-BS>", "<C-w>", { desc = "Delete Word" })
|
||||
|
||||
-- Git
|
||||
map("n", "<leader>ghb", Snacks.git.blame_line, { desc = "Blame Line" })
|
||||
|
||||
-- Windows Split
|
||||
map("n", "<leader>_", "<C-W>s", { desc = "Split Window Below", remap = true })
|
||||
map("n", "<leader>\\", "<C-W>v", { desc = "Split Window Right", remap = true })
|
||||
|
||||
-- Center when scrolling
|
||||
if Snacks.scroll.enabled then
|
||||
map("n", "<C-d>", function()
|
||||
vim.wo.scrolloff = 999
|
||||
vim.defer_fn(function()
|
||||
vim.wo.scrolloff = 8
|
||||
end, 500)
|
||||
return "<c-d>"
|
||||
end, { expr = true })
|
||||
|
||||
map("n", "<C-u>", function()
|
||||
vim.wo.scrolloff = 999
|
||||
vim.defer_fn(function()
|
||||
vim.wo.scrolloff = 8
|
||||
end, 500)
|
||||
return "<c-u>"
|
||||
end, { expr = true })
|
||||
end
|
||||
50
nvim/lua/config/lazy.lua
Normal file
50
nvim/lua/config/lazy.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
if not vim.uv.fs_stat(lazypath) then
|
||||
-- bootstrap lazy.nvim
|
||||
-- stylua: ignore
|
||||
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable",
|
||||
lazypath })
|
||||
end
|
||||
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
|
||||
|
||||
require("lazy").setup({
|
||||
spec = {
|
||||
{
|
||||
"LazyVim/LazyVim",
|
||||
import = "lazyvim.plugins",
|
||||
opts = {
|
||||
colorscheme = "catppuccin",
|
||||
},
|
||||
},
|
||||
{
|
||||
import = "plugins",
|
||||
},
|
||||
},
|
||||
ui = {
|
||||
backdrop = 100,
|
||||
},
|
||||
defaults = {
|
||||
lazy = true,
|
||||
version = false, -- always use the latest git commit
|
||||
-- version = "*", -- try installing the latest stable version for plugins that support semver
|
||||
},
|
||||
local_spec = true,
|
||||
checker = { enabled = true }, -- automatically check for plugin updates
|
||||
performance = {
|
||||
cache = {
|
||||
enabled = true,
|
||||
-- disable_events = {},
|
||||
},
|
||||
rtp = {
|
||||
-- disable some rtp plugins
|
||||
disabled_plugins = {
|
||||
"gzip",
|
||||
"tarPlugin",
|
||||
"tohtml",
|
||||
"tutor",
|
||||
"netrwPlugin",
|
||||
"zipPlugin",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
54
nvim/lua/config/options.lua
Normal file
54
nvim/lua/config/options.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
local go = vim.g
|
||||
local o = vim.opt
|
||||
|
||||
-- Optimizations on startup
|
||||
vim.loader.enable()
|
||||
|
||||
-- Personal Config and LazyVim global options
|
||||
go.lualine_info_extras = false
|
||||
go.codeium_cmp_hide = false
|
||||
go.lazygit_config = false
|
||||
go.lazyvim_cmp = "blink"
|
||||
go.lazyvim_picker = "snacks"
|
||||
|
||||
-- Define leader key
|
||||
go.mapleader = " "
|
||||
go.maplocalleader = "\\"
|
||||
|
||||
-- Autoformat on save (Global)
|
||||
go.autoformat = true
|
||||
|
||||
-- Font
|
||||
go.gui_font_default_size = 10
|
||||
go.gui_font_size = go.gui_font_default_size
|
||||
go.gui_font_face = "JetBrainsMono Nerd Font"
|
||||
|
||||
-- Enable EditorConfig integration
|
||||
go.editorconfig = true
|
||||
|
||||
-- Root dir detection
|
||||
go.root_spec = {
|
||||
"lsp",
|
||||
{ ".git", "lua", ".obsidian", "package.json", "Makefile", "go.mod", "cargo.toml", "pyproject.toml", "src" },
|
||||
"cwd",
|
||||
}
|
||||
|
||||
-- Disable annoying cmd line stuff
|
||||
o.showcmd = false
|
||||
o.laststatus = 3
|
||||
o.cmdheight = 0
|
||||
|
||||
-- Enable spell checking
|
||||
o.spell = true
|
||||
o.spelllang:append("es")
|
||||
|
||||
-- Backspacing and indentation when wrapping
|
||||
o.backspace = { "start", "eol", "indent" }
|
||||
o.breakindent = true
|
||||
|
||||
-- Smoothscroll
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
o.smoothscroll = true
|
||||
end
|
||||
|
||||
o.conceallevel = 2
|
||||
Reference in New Issue
Block a user