diff --git a/init.lua b/init.lua index 3b4d246f..5445dc11 100644 --- a/init.lua +++ b/init.lua @@ -53,6 +53,8 @@ do -- Vera specific settings elseif hostname == 'tau' then -- tau specific settings + elseif hostname == 'hecate' then + -- hecate specific settings end -- Set to true if you have a Nerd Font installed and selected in the terminal @@ -61,6 +63,7 @@ do -- [[ Setting options ]] -- See `:help vim.o` vim.o.number = true + vim.o.relativenumber = true vim.o.mouse = 'a' vim.o.showmode = false vim.schedule(function() vim.o.clipboard = 'unnamedplus' end) @@ -79,6 +82,9 @@ do vim.o.cursorline = true vim.o.scrolloff = 10 vim.o.confirm = true + vim.o.colorcolumn = '120' + vim.o.expandtab = false + vim.opt.isfname:append '@-@' -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -100,6 +106,9 @@ do } vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) + vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) + vim.keymap.set('n', '[d', function() vim.diagnostic.jump { count = -1 } end, { desc = 'Go to previous [D]iagnostic' }) + vim.keymap.set('n', ']d', function() vim.diagnostic.jump { count = 1 } end, { desc = 'Go to next [D]iagnostic' }) vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) -- Split navigation diff --git a/lua/custom/plugins/gitsigns.lua b/lua/custom/plugins/gitsigns.lua new file mode 100644 index 00000000..c6ff4061 --- /dev/null +++ b/lua/custom/plugins/gitsigns.lua @@ -0,0 +1,2 @@ +-- Enable extended gitsigns keymaps (hunk navigation, stage/reset, blame, diff, text object) +require 'whipsmart.plugins.gitsigns' diff --git a/lua/custom/plugins/rust.lua b/lua/custom/plugins/rust.lua new file mode 100644 index 00000000..0398975c --- /dev/null +++ b/lua/custom/plugins/rust.lua @@ -0,0 +1,2 @@ +-- Rust: rustaceanvim manages rust-analyzer (installed by Mason via lsp.lua) +vim.pack.add { { src = 'https://github.com/mrcjkb/rustaceanvim', version = vim.version.range '^6' } } diff --git a/lua/custom/plugins/trouble.lua b/lua/custom/plugins/trouble.lua new file mode 100644 index 00000000..fe22fc4b --- /dev/null +++ b/lua/custom/plugins/trouble.lua @@ -0,0 +1,9 @@ +vim.pack.add { 'https://github.com/folke/trouble.nvim' } +require('trouble').setup {} + +vim.keymap.set('n', 'xx', 'Trouble diagnostics toggle', { desc = 'Diagnostics (Trouble)' }) +vim.keymap.set('n', 'xX', 'Trouble diagnostics toggle filter.buf=0', { desc = 'Buffer Diagnostics (Trouble)' }) +vim.keymap.set('n', 'cs', 'Trouble symbols toggle focus=false', { desc = 'Symbols (Trouble)' }) +vim.keymap.set('n', 'cl', 'Trouble lsp toggle focus=false win.position=right', { desc = 'LSP Definitions/References (Trouble)' }) +vim.keymap.set('n', 'xL', 'Trouble loclist toggle', { desc = 'Location List (Trouble)' }) +vim.keymap.set('n', 'xQ', 'Trouble qflist toggle', { desc = 'Quickfix List (Trouble)' }) diff --git a/lua/plugins/format.lua b/lua/plugins/format.lua index 26b67d01..5752d6cc 100644 --- a/lua/plugins/format.lua +++ b/lua/plugins/format.lua @@ -7,18 +7,35 @@ local function gh(repo) return 'https://github.com/' .. repo end vim.pack.add { gh 'stevearc/conform.nvim' } --- Add filetypes here to enable format-on-save for them, e.g. lua = true -local fmt_on_save_fts = {} - require('conform').setup { notify_on_error = false, - format_on_save = function(bufnr) - if fmt_on_save_fts[vim.bo[bufnr].filetype] then - return { timeout_ms = 500, lsp_format = 'fallback' } - end - end, - default_format_opts = { lsp_format = 'fallback' }, - formatters_by_ft = {}, + format_on_save = { timeout_ms = 500, lsp_format = 'fallback' }, + formatters_by_ft = { + lua = { 'stylua' }, + python = { 'ruff_format', 'ruff_organize_imports' }, + rust = { 'rustfmt' }, + go = { 'goimports', 'gofmt' }, + javascript = { 'prettierd', 'prettier', stop_after_first = true }, + typescript = { 'prettierd', 'prettier', stop_after_first = true }, + javascriptreact = { 'prettierd', 'prettier', stop_after_first = true }, + typescriptreact = { 'prettierd', 'prettier', stop_after_first = true }, + json = { 'prettierd', 'prettier', stop_after_first = true }, + html = { 'prettierd', 'prettier', stop_after_first = true }, + css = { 'prettierd', 'prettier', stop_after_first = true }, + markdown = { 'prettierd', 'prettier', stop_after_first = true }, + yaml = { 'prettierd', 'prettier', stop_after_first = true }, + }, } -vim.keymap.set({ 'n', 'v' }, 'f', function() require('conform').format { async = true } end, { desc = '[F]ormat buffer' }) +vim.api.nvim_create_user_command('Format', function(args) + local range = nil + if args.count ~= -1 then + local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] + range = { start = { args.line1, 0 }, ['end'] = { args.line2, end_line:len() } } + end + require('conform').format { async = true, lsp_format = 'fallback', range = range } +end, { range = true }) + +vim.keymap.set({ 'n', 'v' }, 'cf', function() + require('conform').format { async = false, lsp_format = 'fallback', timeout_ms = 1000 } +end, { desc = '[C]ode [F]ormat file or range' }) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 910eec7a..fccad152 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -70,6 +70,32 @@ local servers = { end, settings = { Lua = { format = { enable = false } } }, }, + gopls = {}, + basedpyright = { + settings = { + basedpyright = { + analysis = { + autoSearchPaths = true, + useLibraryCodeForTypes = true, + diagnosticMode = 'openFilesOnly', + }, + }, + }, + before_init = function(_, config) + local root_dir = config.root_dir + if root_dir then + local venv_path = root_dir .. '/.venv' + if vim.fn.isdirectory(venv_path) == 1 then + local python_path = venv_path .. '/bin/python' + if vim.fn.filereadable(python_path) == 1 then + config.settings.python = config.settings.python or {} + config.settings.python.pythonPath = python_path + end + end + end + end, + }, + ts_ls = {}, } vim.pack.add { @@ -82,6 +108,13 @@ vim.pack.add { local mason_tools = { 'lua-language-server', 'stylua', + 'gopls', + 'goimports', + 'basedpyright', + 'ruff', + 'typescript-language-server', + 'prettierd', + 'rust-analyzer', -- installed by Mason, managed by rustaceanvim (see custom/plugins/rust.lua) } require('mason').setup {} @@ -91,3 +124,26 @@ for name, server in pairs(servers) do vim.lsp.config(name, server) vim.lsp.enable(name) end + +-- System-installed LSPs (not managed by Mason) +if vim.fn.executable 'nimls' == 1 then + vim.lsp.config('nimls', {}) + vim.lsp.enable 'nimls' +end + +if vim.fn.executable 'gleam' == 1 then + vim.lsp.config('gleam', {}) + vim.lsp.enable 'gleam' +end + +-- Gleam indentation +vim.api.nvim_create_autocmd('FileType', { + group = vim.api.nvim_create_augroup('whipsmart-gleam-indent', { clear = true }), + pattern = 'gleam', + callback = function() + vim.bo.shiftwidth = 2 + vim.bo.tabstop = 2 + vim.bo.softtabstop = 2 + vim.bo.expandtab = true + end, +}) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index f82ed971..1644ad55 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -64,3 +64,7 @@ vim.keymap.set('n', 's/', function() end, { desc = '[S]earch [/] in Open Files' }) vim.keymap.set('n', 'sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) +vim.keymap.set('n', '', builtin.git_files, { desc = 'Search [G]it Files' }) +vim.keymap.set('n', 'pf', function() + builtin.grep_string { search = vim.fn.input 'Grep > ' } +end, { desc = '[P]roject [F]ind (grep with input)' }) diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 3e11a9f9..6277a15e 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -7,7 +7,10 @@ local function gh(repo) return 'https://github.com/' .. repo end vim.pack.add { { src = gh 'nvim-treesitter/nvim-treesitter', version = 'main' } } -local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' } +local parsers = { + 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', + 'rust', 'go', 'javascript', 'typescript', 'python', 'json', 'yaml', 'toml', 'gleam', 'nim', +} require('nvim-treesitter').install(parsers) local function treesitter_try_attach(buf, language)