diff --git a/init.lua b/init.lua index 3340807..7dee2f3 100644 --- a/init.lua +++ b/init.lua @@ -1,12 +1,17 @@ -vim.g.mapleader = ' ' -vim.g.maplocalleader = ',' +vim.g.mapleader = " " +vim.g.maplocalleader = "," + +vim.o.shiftwidth = 4 +vim.o.tabstop = 4 vim.o.number = true -vim.o.mouse = 'a' +vim.o.mouse = "a" vim.o.showmode = false -vim.schedule(function() vim.o.clipboard = 'unnamedplus' end) +vim.schedule(function() + vim.o.clipboard = "unnamedplus" +end) vim.o.breakindent = true @@ -16,7 +21,7 @@ vim.o.ignorecase = true vim.o.smartcase = true -- Adds extra space for git diff symbols and stuff -vim.o.signcolumn = 'yes' +vim.o.signcolumn = "yes" -- Decrease update time vim.o.updatetime = 250 @@ -28,10 +33,10 @@ vim.o.timeoutlen = 300 vim.o.splitright = true vim.o.splitbelow = true vim.o.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" } -- Preview substitutions live, as you type! -vim.o.inccommand = 'split' +vim.o.inccommand = "split" -- Show which line your cursor is on vim.o.cursorline = true @@ -44,22 +49,24 @@ vim.o.scrolloff = 3 -- See `:help 'confirm'` vim.o.confirm = true -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() vim.hl.on_yank() end, +vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Highlight when yanking (copying) text", + group = vim.api.nvim_create_augroup("kickstart-highlight-yank", { clear = true }), + callback = function() + vim.hl.on_yank() + end, }) -- Clear highlights on search when pressing in normal mode -- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') +vim.keymap.set("n", "", "nohlsearch") -- Diagnostic Config & Keymaps -- See :help vim.diagnostic.Opts -vim.diagnostic.config { +vim.diagnostic.config({ update_in_insert = false, severity_sort = true, - float = { border = 'rounded', source = 'if_many' }, + float = { border = "rounded", source = "if_many" }, underline = { severity = { min = vim.diagnostic.severity.WARN } }, -- Can switch between these as you prefer @@ -68,46 +75,81 @@ vim.diagnostic.config { -- Auto open the float, so you can easily read the errors when jumping with `[d` and `]d` jump = { float = true }, -} +}) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) +vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" }) -vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) -vim.keymap.set('n', 'K', function() vim.lsp.buf.hover({border = 'rounded'}) end) +vim.keymap.set("t", "", "", { desc = "Exit terminal mode" }) +vim.keymap.set("n", "K", function() + vim.lsp.buf.hover({ border = "rounded" }) +end) -vim.lsp.enable({'lua_ls'}) +vim.lsp.enable({ "lua_ls" }) -local github = 'https://github.com/' +local github = "https://github.com/" vim.pack.add({ - github .. 'nvim-lua/plenary.nvim', - github .. 'nvim-telescope/telescope-fzf-native.nvim', - github .. 'nvim-telescope/telescope.nvim', - github .. 'stevearc/oil.nvim', - github .. 'neovim/nvim-lspconfig', - github .. 'nvim-mini/mini.nvim', - github .. 'lewis6991/gitsigns.nvim', - github .. 'neogitorg/neogit', + github .. "nvim-lua/plenary.nvim", + github .. "nvim-telescope/telescope-fzf-native.nvim", + github .. "nvim-telescope/telescope.nvim", + github .. "stevearc/oil.nvim", + github .. "neovim/nvim-lspconfig", + github .. "nvim-mini/mini.nvim", + github .. "lewis6991/gitsigns.nvim", + github .. "neogitorg/neogit", + github .. "stevearc/conform.nvim", }) -- Telescope -local builtin = require('telescope.builtin') -vim.keymap.set('n', 'ff', builtin.find_files, { desc = 'Telescope find files' }) -vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'Telescope live grep' }) -vim.keymap.set('n', 'fb', builtin.buffers, { desc = 'Telescope buffers' }) -vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Telescope help tags' }) +local builtin = require("telescope.builtin") +vim.keymap.set("n", "ff", builtin.find_files, { desc = "Telescope find files" }) +vim.keymap.set("n", "fg", builtin.live_grep, { desc = "Telescope live grep" }) +vim.keymap.set("n", "fb", builtin.buffers, { desc = "Telescope buffers" }) +vim.keymap.set("n", "fh", builtin.help_tags, { desc = "Telescope help tags" }) +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("telescope-lsp-attach", { clear = true }), + callback = function(event) + local buf = event.buf + vim.keymap.set("n", "gO", builtin.lsp_document_symbols, { buffer = buf, desc = "Open Document Symbols" }) + vim.keymap.set( + "n", + "gW", + builtin.lsp_dynamic_workspace_symbols, + { buffer = buf, desc = "Open Workspace Symbols" } + ) + end, +}) -- Oil -require('oil').setup({ +require("oil").setup({ default_file_explorer = true, columns = { "icon", - } + }, }) -vim.keymap.set('n', 'rw', 'Oil', { desc = 'Open file explorer' }) +vim.keymap.set("n", "rw", "Oil", { desc = "Open file explorer" }) -- Mini -require('mini.move').setup() -require('mini.surround').setup() +require("mini.move").setup() +require("mini.surround").setup() -- Neogit -vim.keymap.set('n', 'gg', 'Neogit') +vim.keymap.set("n", "gg", "Neogit") + +-- Conform +require("conform").setup({ + formatters_by_ft = { + lua = { "stylua" }, + -- Conform will run multiple formatters sequentially + python = { "ruff" }, + -- You can customize some of the format options for the filetype (:help conform.format) + rust = { "rustfmt", lsp_format = "fallback" }, + -- Conform will run the first available formatter + javascript = { "prettierd", "prettier", stop_after_first = true }, + }, +}) +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*", + callback = function(args) + require("conform").format({ bufnr = args.buf }) + end, +}) diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json index fe4a340..7d0fcc2 100644 --- a/nvim-pack-lock.json +++ b/nvim-pack-lock.json @@ -1,5 +1,9 @@ { "plugins": { + "conform.nvim": { + "rev": "086a40dc7ed8242c03be9f47fbcee68699cc2395", + "src": "https://github.com/stevearc/conform.nvim" + }, "gitsigns.nvim": { "rev": "50c205548d8b037b7ff6378fca6d21146f0b6161", "src": "https://github.com/lewis6991/gitsigns.nvim"