Nvim cleanup, autocmd setup added.
This commit is contained in:
+12
-8
@@ -1,11 +1,12 @@
|
|||||||
local map = vim.keymap.set
|
map = vim.keymap.set
|
||||||
vim.g.mapleader = " "
|
vim.g.mapleader = " "
|
||||||
vim.g.termguicolors = true -- Enable 24-bit RGB colors
|
vim.g.termguicolors = true -- Enable 24-bit RGB colors
|
||||||
vim.o.nu = true -- Show line numbers
|
vim.o.nu = true -- Show line numbers
|
||||||
|
vim.o.relativenumber = true -- Show relative line numbers
|
||||||
vim.o.cursorline = true -- Highlight the line where the cursor is
|
vim.o.cursorline = true -- Highlight the line where the cursor is
|
||||||
vim.o.wrap = false -- Don't wrap long lines to the next line
|
vim.o.wrap = false -- Don't wrap long lines to the next line
|
||||||
vim.o.list = true -- Show invisible characters (tabs, trailing spaces)
|
vim.o.list = true -- Show invisible characters (tabs, trailing spaces)
|
||||||
vim.o.scrolloff = 8 -- Keep 8 lines above/below cursor when scrolling
|
vim.o.scrolloff = 20 -- Keep 20 lines above/below cursor when scrolling
|
||||||
vim.o.winborder = 'rounded' -- Use rounded borders for floating windows
|
vim.o.winborder = 'rounded' -- Use rounded borders for floating windows
|
||||||
vim.o.ignorecase = true -- Ignore case in search patterns
|
vim.o.ignorecase = true -- Ignore case in search patterns
|
||||||
vim.o.smartcase = true -- ...unless search contains an uppercase letter
|
vim.o.smartcase = true -- ...unless search contains an uppercase letter
|
||||||
@@ -13,20 +14,20 @@ vim.o.hlsearch = true -- Keep search results highlighted
|
|||||||
vim.o.incsearch = true -- Show search results as you type
|
vim.o.incsearch = true -- Show search results as you type
|
||||||
vim.o.path = "**" -- Search down into subdirectories (classic Vim)
|
vim.o.path = "**" -- Search down into subdirectories (classic Vim)
|
||||||
vim.o.expandtab = true -- Use spaces instead of tabs
|
vim.o.expandtab = true -- Use spaces instead of tabs
|
||||||
vim.o.tabstop = 4 -- 1 tab = 4 spaces
|
vim.o.shiftwidth = 4 -- 4 spaces per indent
|
||||||
vim.o.shiftwidth = 4 -- Indentation amount for >> and << commands
|
vim.o.tabstop = 4 -- 4 spaces for a tab
|
||||||
|
vim.o.softtabstop = 4 -- Tab key inserts 4 spaces
|
||||||
vim.o.swapfile = false -- Disable creation of .swp files
|
vim.o.swapfile = false -- Disable creation of .swp files
|
||||||
vim.o.backup = false -- Disable backup files
|
vim.o.backup = false -- Disable backup files
|
||||||
vim.o.undofile = true -- Save undo history to a file
|
vim.o.undofile = true -- Save undo history to a file
|
||||||
vim.o.splitright = true -- Open vertical splits to the right
|
vim.o.splitright = true -- Open vertical splits to the right
|
||||||
vim.o.splitbelow = true -- Open horizontal splits below
|
vim.o.splitbelow = true -- Open horizontal splits below
|
||||||
vim.o.timeoutlen = 300 -- Time (ms) to wait for a mapped sequence to complete
|
vim.o.timeoutlen = 300 -- Time (ms) to wait for a mapped sequence to complete
|
||||||
|
vim.o.autocomplete = true
|
||||||
vim.opt.clipboard = "unnamedplus"
|
vim.opt.clipboard = "unnamedplus"
|
||||||
vim.o.completeopt = 'menuone,noselect'
|
vim.o.completeopt = 'menuone,noselect'
|
||||||
vim.o.undodir = os.getenv("HOME") .. "/.cache/nvim/undodir"
|
vim.o.undodir = os.getenv("HOME") .. "/.cache/nvim/undodir"
|
||||||
vim.api.nvim_create_autocmd("BufEnter", { pattern = "term://*", callback = function() vim.cmd("startinsert") end })
|
|
||||||
vim.lsp.enable({ "gopls", "gdscript" })
|
vim.lsp.enable({ "gopls", "gdscript" })
|
||||||
vim.cmd(":colorscheme retrobox")
|
|
||||||
|
|
||||||
map({"t", "n"}, "<C-h>", "<C-\\><C-n><C-w><C-h>")
|
map({"t", "n"}, "<C-h>", "<C-\\><C-n><C-w><C-h>")
|
||||||
map({"t", "n"}, "<C-j>", "<C-\\><C-n><C-w><C-j>")
|
map({"t", "n"}, "<C-j>", "<C-\\><C-n><C-w><C-j>")
|
||||||
@@ -39,10 +40,13 @@ map("v", "J", ":m '>+1<CR>gv=gv")
|
|||||||
map("v", "K", ":m '<-2<CR>gv=gv")
|
map("v", "K", ":m '<-2<CR>gv=gv")
|
||||||
map("v", "<S-Tab>", "<gv")
|
map("v", "<S-Tab>", "<gv")
|
||||||
map("v", "<Tab>" , ">gv")
|
map("v", "<Tab>" , ">gv")
|
||||||
map("n", "gd", ":lua vim.lsp.buf.definition()<CR>")
|
|
||||||
map("n", "<leader>r", ":lua vim.lsp.buf.rename()<CR>")
|
|
||||||
map("n", "<leader>p", ":b#<CR>")
|
map("n", "<leader>p", ":b#<CR>")
|
||||||
map("n", "<leader>e", ":Ex<CR>")
|
map("n", "<leader>e", ":Ex<CR>")
|
||||||
map("n", "<leader>x", ":bd<CR>")
|
map("n", "<leader>x", ":bd<CR>")
|
||||||
|
map("n", "L", ":lua vim.diagnostic.open_float()<CR>")
|
||||||
|
map("n", "gd", ":lua vim.lsp.buf.definition()<CR>")
|
||||||
|
map("n", "<leader>r", ":lua vim.lsp.buf.rename()<CR>")
|
||||||
|
map({"v","n"}, "<leader>F", ":lua vim.lsp.buf.format()<CR>")
|
||||||
|
|
||||||
|
require("autocmds")
|
||||||
require("plugins")
|
require("plugins")
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
-- Terminals should open with insert mode
|
||||||
|
vim.api.nvim_create_autocmd("BufEnter", { pattern = "term://*", callback = function() vim.cmd("startinsert") end })
|
||||||
|
-- Start treesitter
|
||||||
|
vim.api.nvim_create_autocmd('FileType', {
|
||||||
|
pattern = '*',
|
||||||
|
callback = function()
|
||||||
|
pcall(vim.treesitter.start)
|
||||||
|
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
-- highlights yanked text
|
||||||
|
vim.api.nvim_create_autocmd("TextYankPost", {
|
||||||
|
callback = function()
|
||||||
|
vim.highlight.on_yank({
|
||||||
|
higroup = "IncSearch",
|
||||||
|
timeout = 200,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
-- Set absolute numbers when in insert mode otherwise relativenumbers
|
||||||
|
local nums = vim.api.nvim_create_augroup('smart_numbers', {})
|
||||||
|
vim.api.nvim_create_autocmd('InsertEnter', {
|
||||||
|
group = nums,
|
||||||
|
callback = function()
|
||||||
|
vim.opt.relativenumber = false
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_autocmd('InsertLeave', {
|
||||||
|
group = nums,
|
||||||
|
callback = function()
|
||||||
|
vim.opt.relativenumber = true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
-- removes trailing whitespace on save
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
callback = function()
|
||||||
|
local save_cursor = vim.fn.getpos(".")
|
||||||
|
vim.cmd([[%s/\s\+$//e]])
|
||||||
|
vim.fn.setpos(".", save_cursor)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
-- Lsp autocomplete
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
group = vim.api.nvim_create_augroup('my.lsp', {}),
|
||||||
|
callback = function(ev)
|
||||||
|
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||||
|
if not client then return end
|
||||||
|
|
||||||
|
-- Set completeopt for a better experience
|
||||||
|
vim.opt.completeopt = { 'menu', 'menuone', 'noinsert', 'noselect' }
|
||||||
|
|
||||||
|
-- Enable completion if the server supports it
|
||||||
|
if client:supports_method('textDocument/completion') then
|
||||||
|
vim.lsp.completion.enable(true, client.id, ev.buf, {
|
||||||
|
autotrigger = true, -- false = manual trigger only
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Format: whole file or visual selection via :Fc
|
||||||
|
local function smart_format()
|
||||||
|
local mode = vim.fn.mode()
|
||||||
|
local in_visual = mode == "v" or mode == "V" or mode == "\22"
|
||||||
|
|
||||||
|
local clients = vim.lsp.get_clients({ bufnr = 0 })
|
||||||
|
local has_formatter = false
|
||||||
|
for _, client in ipairs(clients) do
|
||||||
|
if client.supports_method("textDocument/formatting") then
|
||||||
|
has_formatter = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if in_visual then
|
||||||
|
if has_formatter then
|
||||||
|
vim.lsp.buf.format({
|
||||||
|
range = {
|
||||||
|
start = vim.api.nvim_buf_get_mark(0, "<"),
|
||||||
|
["end"] = vim.api.nvim_buf_get_mark(0, ">"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
else
|
||||||
|
vim.cmd("normal! gv=")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if has_formatter then
|
||||||
|
vim.lsp.buf.format({ async = false })
|
||||||
|
else
|
||||||
|
local view = vim.fn.winsaveview()
|
||||||
|
vim.cmd("normal! gg=G")
|
||||||
|
vim.fn.winrestview(view)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- :FF (Format Function) works in normal and visual mode
|
||||||
|
vim.api.nvim_create_user_command("FF", smart_format, { range = true })
|
||||||
@@ -9,24 +9,13 @@ vim.cmd(":colorscheme catppuccin-nvim")
|
|||||||
|
|
||||||
require("tree-sitter-manager").setup({})
|
require("tree-sitter-manager").setup({})
|
||||||
|
|
||||||
local map = vim.keymap.set
|
|
||||||
local acmd = vim.api.nvim_create_autocmd
|
|
||||||
|
|
||||||
acmd('FileType', {
|
|
||||||
pattern = '*',
|
|
||||||
callback = function()
|
|
||||||
pcall(vim.treesitter.start)
|
|
||||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
require("fzf-lua").setup()
|
require("fzf-lua").setup()
|
||||||
map("n", "<leader>f", ":lua FzfLua.files()<CR>")
|
map("n", "<leader>f", ":lua FzfLua.files()<CR>")
|
||||||
map("n", "<leader>o", ":lua FzfLua.buffers()<CR>")
|
map("n", "<leader>o", ":lua FzfLua.buffers()<CR>")
|
||||||
|
map("n", "<leader>h", ":lua FzfLua.help_tags()<CR>")
|
||||||
|
map("n", "<leader>d", ":lua FzfLua.diagnostics_document()<CR>")
|
||||||
|
map("n", "<leader>a", ":lua FzfLua.lsp_code_actions()<CR>")
|
||||||
map("n", "<leader>ss", ":lua FzfLua.grep_project()<CR>")
|
map("n", "<leader>ss", ":lua FzfLua.grep_project()<CR>")
|
||||||
map("n", "<leader>sf", ":lua FzfLua.grep_curbuf()<CR>")
|
map("n", "<leader>sf", ":lua FzfLua.grep_curbuf()<CR>")
|
||||||
map("n", "<leader>sw", ":lua FzfLua.grep_cword()<CR>")
|
map("n", "<leader>sw", ":lua FzfLua.grep_cword()<CR>")
|
||||||
map("n", "<leader>sh", ":lua FzfLua.help_tags()<CR>")
|
|
||||||
map("n", "<leader>sd", ":lua FzfLua.diagnostics_document()<CR>")
|
|
||||||
map("n", "<leader>sa", ":lua FzfLua.lsp_code_actions()<CR>")
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user