diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 9a7ad9a..fbc4e5b 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -13,32 +13,32 @@ vim.opt.relativenumber = true vim.opt.termguicolors = true vim.opt.undofile = true vim.opt.signcolumn = "yes" -vim.g.netrw_banner = 0 -- gets rid of the annoying banner for netrw +vim.g.netrw_banner = 0 -- gets rid of the annoying banner for netrw vim.g.netrw_browse_split = 4 -- open in prior window -vim.g.netrw_altv = 1 -- change from left splitting to right splitting -vim.g.netrw_liststyle = 3 -- tree style view in netrw +vim.g.netrw_altv = 1 -- change from left splitting to right splitting +vim.g.netrw_liststyle = 3 -- tree style view in netrw ------------------------------------------------------------------- -- Autocommands ------------------------------------------------------------------- --- -- show cursor line only in active window --- local cursorLineGrp = vim.api.nvim_create_augroup("CursorLine", { clear = true }) --- vim.api.nvim_create_autocmd( --- { "InsertLeave", "WinEnter" }, --- { pattern = "*", command = "set cursorline", group = cursorLineGrp } --- ) --- vim.api.nvim_create_autocmd( --- { "InsertEnter", "WinLeave" }, --- { pattern = "*", command = "set nocursorline", group = cursorLineGrp } --- ) --- vim.api.nvim_create_autocmd( --- { "InsertLeave", "FocusGained" }, --- { pattern = "*", command = "set cursorline", group = cursorLineGrp } --- ) --- vim.api.nvim_create_autocmd( --- { "InsertEnter", "FocusLost" }, --- { pattern = "*", command = "set nocursorline", group = cursorLineGrp } --- ) +-- show cursor line only in active window +local cursorLineGrp = vim.api.nvim_create_augroup("CursorLine", { clear = true }) +vim.api.nvim_create_autocmd( + { "InsertLeave", "WinEnter" }, + { pattern = "*", command = "set cursorline", group = cursorLineGrp } +) +vim.api.nvim_create_autocmd( + { "InsertEnter", "WinLeave" }, + { pattern = "*", command = "set nocursorline", group = cursorLineGrp } +) +vim.api.nvim_create_autocmd( + { "InsertLeave", "FocusGained" }, + { pattern = "*", command = "set cursorline", group = cursorLineGrp } +) +vim.api.nvim_create_autocmd( + { "InsertEnter", "FocusLost" }, + { pattern = "*", command = "set nocursorline", group = cursorLineGrp } +) ------------------------------------------------------------------- -- Plugin installation @@ -52,35 +52,67 @@ vim.pack.add({ { src = "https://github.com/echasnovski/mini.statusline" }, { src = "https://github.com/echasnovski/mini.pick" }, { src = "https://github.com/echasnovski/mini.extra" }, - { src = 'https://github.com/neovim/nvim-lspconfig' }, - { src = 'https://github.com/lewis6991/gitsigns.nvim' }, - { src = 'https://github.com/MunifTanjim/nui.nvim' }, - { src = 'https://github.com/folke/noice.nvim' }, + { src = "https://github.com/neovim/nvim-lspconfig" }, + { src = "https://github.com/lewis6991/gitsigns.nvim" }, + { src = "https://github.com/MunifTanjim/nui.nvim" }, + { src = "https://github.com/folke/noice.nvim" }, { src = "https://github.com/L3MON4D3/LuaSnip" }, { src = "https://github.com/rafamadriz/friendly-snippets" }, - { src = 'https://github.com/saghen/blink.cmp' }, + { src = "https://github.com/saghen/blink.cmp" }, + { src = "https://github.com/stevearc/conform.nvim" }, }) ------------------------------------------------------------------- -- Plugin config ------------------------------------------------------------------- -require "noice".setup() +require("noice").setup() +require("conform").setup({ + formatters_by_ft = { + lua = { "stylua" }, + python = { "isort", "black" }, + rust = { "rustfmt", lsp_format = "fallback" }, + c = { "clang_format" }, + cpp = { "clang_format" }, + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + json = { "prettier" }, + yaml = { "prettier" }, + markdown = { "prettier" }, + sh = { "shfmt" }, + }, + formatters = { + clang_format = { + prepend_args = { "--style={BasedOnStyle: LLVM, IndentWidth: 4, TabWidth: 4, UseTab: Never}" }, + }, + shfmt = { + prepend_args = { "-i", "4" }, + }, + }, + format_on_save = { + timeout_ms = 3000, + lsp_format = "fallback", + }, +}) local win_config = function() local height = math.floor(0.618 * vim.o.lines) local width = math.floor(0.618 * vim.o.columns) return { - anchor = 'NW', + anchor = "NW", height = height, width = width, row = math.floor(0.5 * (vim.o.lines - height)), col = math.floor(0.5 * (vim.o.columns - width)), } end -require "mini.pick".setup({ window = { config = win_config } }) -require "mini.extra".setup() -require "mini.statusline".setup() -require "gitsigns".setup({ +require("mini.pick").setup({ window = { config = win_config } }) +require("mini.extra").setup() +require("mini.statusline").setup() +require("gitsigns").setup({ signs = { add = { text = "▎" }, change = { text = "▎" }, @@ -110,17 +142,17 @@ require("blink.cmp").setup({ auto_show = true, draw = { columns = { - { "label", "label_description", gap = 1 }, - { "kind_icon", "kind" } + { "label", "label_description", gap = 1 }, + { "kind_icon", "kind" }, }, - } + }, }, }, sources = { - default = { 'lsp', 'buffer', 'path', 'snippets' }, + default = { "lsp", "buffer", "path", "snippets" }, providers = { -- defaults to `{ 'buffer' }` - lsp = { fallbacks = {} } + lsp = { fallbacks = {} }, }, }, fuzzy = { implementation = "lua" }, @@ -168,27 +200,29 @@ vim.diagnostic.config({ local map = vim.keymap.set vim.g.mapleader = " " -- QoL bindings -map('i', 'jj', '', { noremap = true, silent = true }) -map('n', 'u', ':update :source', { noremap = true, silent = true }) -map('n', 'w', ':write', { noremap = true, silent = true }) -map('n', 'q', ':quit', { noremap = true, silent = true }) -map('n', 'v', ':vsplit', { noremap = true, silent = true }) +map("i", "jj", "", { noremap = true, silent = true }) +map("n", "u", ":update :source", { noremap = true, silent = true }) +map("n", "w", ":write", { noremap = true, silent = true }) +map("n", "q", ":quit", { noremap = true, silent = true }) +map("n", "v", ":vsplit", { noremap = true, silent = true }) -- Git -map('n', 'g', ':LazyGitCurrentFile', { noremap = true, silent = true }) +map("n", "g", ":LazyGitCurrentFile", { noremap = true, silent = true }) -- File browser -map('n', 'e', ':25Lex', { noremap = true, silent = true }) -map('n', 'f', ":Pick files", { noremap = true, silent = true }) -map('n', 'h', ":Pick help", { noremap = true, silent = true }) +map("n", "e", ":25Lex", { noremap = true, silent = true }) +map("n", "f", ":Pick files", { noremap = true, silent = true }) +map("n", "h", ":Pick help", { noremap = true, silent = true }) -- LSP -map('n', 'lf', vim.lsp.buf.format, { noremap = true, silent = true }) +map("n", "grr", ":Pick lsp scope='references'", { noremap = true, silent = true }) +map("n", "grt", ":Pick lsp scope='type_definition'", { noremap = true, silent = true }) +map("n", "gri", ":Pick lsp scope='implementation'", { noremap = true, silent = true }) -- Global Copy/Paste -map({ 'n', 'v' }, 'y', '"+y', { noremap = true, silent = true }) -map({ 'n', 'v' }, 'd', '"+d', { noremap = true, silent = true }) -map({ 'n', 'v' }, 'c', '1z=', { noremap = true, silent = true }) +map({ "n", "v" }, "y", '"+y', { noremap = true, silent = true }) +map({ "n", "v" }, "d", '"+d', { noremap = true, silent = true }) +map({ "n", "v" }, "c", "1z=", { noremap = true, silent = true }) -- Smart splits to support TMUX map({ "n", "t" }, "", require("smart-splits").resize_left, { desc = "Resize left" })