Changed a couple of nvim settings, added some keybinds, disabled treej, and added conform.nvim

This commit is contained in:
Dreaded_X 2024-04-13 05:38:25 +02:00
parent f2d0e639b4
commit b19f90dc7f
Signed by: Dreaded_X
GPG Key ID: FA5F485356B0D2D4
5 changed files with 605 additions and 475 deletions

View File

@ -38,147 +38,188 @@ P.S. You can delete this when you're done too. It's your config now :)
-- Set <space> as the leader key -- Set <space> as the leader key
-- See `:help mapleader` -- See `:help mapleader`
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
vim.g.mapleader = ' ' vim.g.mapleader = " "
vim.g.maplocalleader = ' ' vim.g.maplocalleader = " "
-- Install package manager -- Install package manager
-- https://github.com/folke/lazy.nvim -- https://github.com/folke/lazy.nvim
-- `:help lazy.nvim.txt` for more info -- `:help lazy.nvim.txt` for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then
vim.fn.system { vim.fn.system({
'git', "git",
'clone', "clone",
'--filter=blob:none', "--filter=blob:none",
'https://github.com/folke/lazy.nvim.git', "https://github.com/folke/lazy.nvim.git",
'--branch=stable', -- latest stable release "--branch=stable", -- latest stable release
lazypath, lazypath,
} })
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
local symbols = require('constant.symbols'); local symbols = require("constant.symbols")
local border = 'rounded'; local border = "rounded"
-- Helper function for staging selection
local function gitsigns_visual_op(op)
return function()
return require("gitsigns")[op]({ vim.fn.line("."), vim.fn.line("v") })
end
end
-- NOTE: Here is where you install your plugins. -- NOTE: Here is where you install your plugins.
-- You can configure plugins using the `config` key. -- You can configure plugins using the `config` key.
-- --
-- You can also configure plugins after the setup call, -- You can also configure plugins after the setup call,
-- as they will be available in your neovim runtime. -- as they will be available in your neovim runtime.
require('lazy').setup({ require("lazy").setup({
-- NOTE: This is where your plugins related to LSP can be installed. -- NOTE: This is where your plugins related to LSP can be installed.
-- The configuration is done below. Search for lspconfig to find it below. -- The configuration is done below. Search for lspconfig to find it below.
{ {
-- LSP Configuration & Plugins -- LSP Configuration & Plugins
'neovim/nvim-lspconfig', "neovim/nvim-lspconfig",
dependencies = { dependencies = {
-- Automatically install LSPs to stdpath for neovim -- Automatically install LSPs to stdpath for neovim
'williamboman/mason.nvim', "williamboman/mason.nvim",
'williamboman/mason-lspconfig.nvim', "williamboman/mason-lspconfig.nvim",
-- Useful status updates for LSP -- Useful status updates for LSP
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
{ 'j-hui/fidget.nvim', opts = {} }, { "j-hui/fidget.nvim", opts = {} },
-- Additional lua configuration, makes nvim stuff amazing! -- Additional lua configuration, makes nvim stuff amazing!
'folke/neodev.nvim', "folke/neodev.nvim",
-- Add document color -- Add document color
'mrshmllow/document-color.nvim', "mrshmllow/document-color.nvim",
'b0o/schemastore.nvim', "b0o/schemastore.nvim",
-- Rename with immediate visual feedback -- Rename with immediate visual feedback
{ {
'smjonas/inc-rename.nvim', "smjonas/inc-rename.nvim",
config = function() config = function()
require('inc_rename').setup { require("inc_rename").setup({
preview_empty_name = true, preview_empty_name = true,
} })
end end,
}, },
}, },
}, },
{ {
'ray-x/lsp_signature.nvim', "ray-x/lsp_signature.nvim",
dependencies = { dependencies = {
'neovim/nvim-lspconfig', "neovim/nvim-lspconfig",
}, },
opts = { opts = {
hint_enable = false, hint_enable = false,
handler_opts = { handler_opts = {
border = border border = border,
} },
}, },
}, },
{ {
-- Autocompletion -- Autocompletion
'hrsh7th/nvim-cmp', "hrsh7th/nvim-cmp",
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'hrsh7th/cmp-path', dependencies = {
'onsails/lspkind-nvim', }, "hrsh7th/cmp-nvim-lsp",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-path",
"onsails/lspkind-nvim",
},
}, },
-- Useful plugin to show you pending keybinds. -- Useful plugin to show you pending keybinds.
{ 'folke/which-key.nvim', opts = {} },
{ {
-- Adds git releated signs to the gutter, as well as utilities for managing changes "folke/which-key.nvim",
'lewis6991/gitsigns.nvim', opts = {},
init = function() init = function()
vim.keymap.set('n', '<leader>gs', require('gitsigns.actions').stage_hunk, { desc = "[G]it [S]tage hunk" }) require("which-key").register({
vim.keymap.set('n', '<leader>gS', require('gitsigns.actions').undo_stage_hunk, { desc = "[G]it undo [S]tage hunk" }) ["<leader>g"] = { name = "[G]it", _ = "which_key_ignore" },
vim.keymap.set('n', '<leader>gd', require('gitsigns.actions').preview_hunk_inline, { desc = "[G]it [D]iff hunk " }) ["<leader>b"] = { name = "[B]buffer", _ = "which_key_ignore" },
vim.keymap.set('n', ']g', require('gitsigns.actions').next_hunk, { desc = "Go to next hunk" }) ["<leader>s"] = { name = "[S]earch", _ = "which_key_ignore" },
vim.keymap.set('n', '[g', require('gitsigns.actions').prev_hunk, { desc = "Go to previous hunk" }) })
end,
},
{
-- Adds git related signs to the gutter, as well as utilities for managing changes
"lewis6991/gitsigns.nvim",
init = function()
vim.keymap.set("n", "<leader>gs", require("gitsigns.actions").stage_hunk, { desc = "[G]it [S]tage hunk" })
vim.keymap.set(
"n",
"<leader>gS",
require("gitsigns.actions").undo_stage_hunk,
{ desc = "[G]it undo [S]tage hunk" }
)
vim.keymap.set(
"n",
"<leader>gd",
require("gitsigns.actions").preview_hunk_inline,
{ desc = "[G]it [D]iff hunk" }
)
vim.keymap.set("n", "<leader>gr", require("gitsigns.actions").reset_hunk, { desc = "[G]it [R]eset hunk" })
vim.keymap.set("v", "<leader>gs", gitsigns_visual_op("stage_hunk"), { desc = "[G]it [S]tage selection" })
vim.keymap.set("v", "<leader>gr", gitsigns_visual_op("reset_hunk"), { desc = "[G]it [R]eset selection" })
vim.keymap.set("n", "]g", function()
require("gitsigns.actions").nav_hunk("next")
end, { desc = "Go to next hunk" })
vim.keymap.set("n", "[g", function()
require("gitsigns.actions").nav_hunk("prev")
end, { desc = "Go to previous hunk" })
end, end,
opts = { opts = {
-- See `:help gitsigns.txt` -- See `:help gitsigns.txt`
signs = { signs = {
add = { text = '+' }, add = { text = "+" },
change = { text = '~' }, change = { text = "~" },
delete = { text = '_' }, delete = { text = "_" },
topdelete = { text = '' }, topdelete = { text = "" },
changedelete = { text = '~' }, changedelete = { text = "~" },
}, },
}, },
}, },
{ {
-- Set lualine as statusline -- Set lualine as statusline
'nvim-lualine/lualine.nvim', "nvim-lualine/lualine.nvim",
-- See `:help lualine.txt` -- See `:help lualine.txt`
opts = { opts = {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = 'gruvbox', theme = "gruvbox",
component_separators = { left = '', right = '' }, component_separators = { left = "", right = "" },
section_separators = { left = '', right = '' }, section_separators = { left = "", right = "" },
}, },
sections = { sections = {
lualine_b = { lualine_b = {
'branch', "branch",
'diff', "diff",
{ 'diagnostics', symbols = { error = '', warn = '', info = '', hint = '' } }, { "diagnostics", symbols = { error = "", warn = "", info = "", hint = "" } },
}, },
lualine_c = { lualine_c = {
{ {
'filename', "filename",
path = 1, path = 1,
symbols = { symbols = {
modified = symbols.file.modified, modified = symbols.file.modified,
readonly = symbols.file.readonly, readonly = symbols.file.readonly,
} },
}, },
}, },
lualine_x = { lualine_x = {
'encoding', { 'fileformat', icons_enabled = false }, 'filetype', "encoding",
{ "fileformat", icons_enabled = false },
"filetype",
}, },
}, },
inactive_sections = { inactive_sections = {
lualine_c = { lualine_c = {
{ 'filename', path = 1 }, { "filename", path = 1 },
}, },
}, },
}, },
@ -186,68 +227,66 @@ require('lazy').setup({
{ {
-- Add indentation guides even on blank lines -- Add indentation guides even on blank lines
'lukas-reineke/indent-blankline.nvim', "lukas-reineke/indent-blankline.nvim",
-- Enable `lukas-reineke/indent-blankline.nvim` -- Enable `lukas-reineke/indent-blankline.nvim`
-- See `:help indent_blankline.txt` -- See `:help indent_blankline.txt`
main = "ibl", main = "ibl",
opts = { opts = {
indent = { indent = {
char = '¦', char = "¦",
}, },
}, },
}, },
-- Fuzzy Finder (files, lsp, etc) -- Fuzzy Finder (files, lsp, etc)
{ {
'nvim-telescope/telescope.nvim', "nvim-telescope/telescope.nvim",
version = '*', version = "*",
dependencies = { 'nvim-lua/plenary.nvim', dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope-ui-select.nvim" },
'nvim-telescope/telescope-ui-select.nvim' }
}, },
-- Fuzzy Finder Algorithm which requires local dependencies to be built. -- Fuzzy Finder Algorithm which requires local dependencies to be built.
-- Only load if `make` is available. Make sure you have the system -- Only load if `make` is available. Make sure you have the system
-- requirements installed. -- requirements installed.
{ {
'nvim-telescope/telescope-fzf-native.nvim', "nvim-telescope/telescope-fzf-native.nvim",
-- NOTE: If you are having trouble with this installation, -- NOTE: If you are having trouble with this installation,
-- refer to the README for telescope-fzf-native for more instructions. -- refer to the README for telescope-fzf-native for more instructions.
build = 'make', build = "make",
cond = function() cond = function()
return vim.fn.executable 'make' == 1 return vim.fn.executable("make") == 1
end, end,
}, },
{ {
-- Highlight, edit, and navigate code -- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter', "nvim-treesitter/nvim-treesitter",
dependencies = { dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects', "nvim-treesitter/nvim-treesitter-textobjects",
'nvim-treesitter/nvim-treesitter-context', "nvim-treesitter/nvim-treesitter-context",
}, },
config = function() config = function()
pcall(require('nvim-treesitter.install').update { with_sync = true }) pcall(require("nvim-treesitter.install").update({ with_sync = true }))
end, end,
}, },
require 'themes.gruvbox', require("themes.gruvbox"),
{ import = 'plugins' }, { import = "plugins" },
}, { }, {
install = { install = {
colorscheme = { colorscheme = {
'gruvbox', "gruvbox",
} },
} },
}) })
require('options') require("options")
require('keymaps') require("keymaps")
require('autocmds') require("autocmds")
-- [[ Configure Telescope ]] -- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()` -- See `:help telescope` and `:help telescope.setup()`
require('telescope').setup { require("telescope").setup({
pickers = { pickers = {
find_files = { find_files = {
hidden = true, hidden = true,
@ -259,70 +298,94 @@ require('telescope').setup {
}, },
mappings = { mappings = {
n = { n = {
['<c-d>'] = "delete_buffer", ["<c-d>"] = "delete_buffer",
['<Tab>'] = "move_selection_next", ["<Tab>"] = "move_selection_next",
['<S-Tab>'] = "move_selection_previous", ["<S-Tab>"] = "move_selection_previous",
}, },
i = { i = {
['<c-d>'] = "delete_buffer", ["<c-d>"] = "delete_buffer",
['<Tab>'] = "move_selection_next", ["<Tab>"] = "move_selection_next",
['<S-Tab>'] = "move_selection_previous", ["<S-Tab>"] = "move_selection_previous",
}, },
}, },
}, },
extensions = { extensions = {
["ui-select"] = { ["ui-select"] = {
require('telescope.themes').get_dropdown {} require("telescope.themes").get_dropdown({}),
} },
} },
} })
-- Enable telescope fzf native, if installed -- Enable telescope fzf native, if installed
pcall(require('telescope').load_extension, 'fzf') pcall(require("telescope").load_extension, "fzf")
pcall(require('telescope').load_extension, 'ui-select') pcall(require("telescope").load_extension, "ui-select")
-- See `:help telescope.builtin` -- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) vim.keymap.set("n", "<leader>.", require("telescope.builtin").oldfiles, { desc = "[.] Find recently opened files" })
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) vim.keymap.set("n", "<leader><space>", require("telescope.builtin").buffers, { desc = "[ ] Find existing buffers" })
vim.keymap.set('n', '<leader>/', function() vim.keymap.set("n", "<leader>/", function()
require('telescope.builtin').current_buffer_fuzzy_find({ require("telescope.builtin").current_buffer_fuzzy_find({
-- Show matches in the order they appear in the document -- Show matches in the order they appear in the document
sorting_strategy = "ascending", sorting_strategy = "ascending",
}) })
end, { desc = '[/] Fuzzily search in current buffer' }) end, { desc = "[/] Fuzzily search in current buffer" })
vim.keymap.set("n", "<leader>s/", function()
require("telescope.builtin").live_grep({
grep_open_files = true,
prompt_title = "Live Grep in Open Files",
})
end, { desc = "[S]earch [/] in Open Files" })
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set("n", "<leader>sf", require("telescope.builtin").find_files, { desc = "[S]earch [F]iles" })
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set("n", "<leader>sh", require("telescope.builtin").help_tags, { desc = "[S]earch [H]elp" })
vim.keymap.set('n', '<leader>sw', function() vim.keymap.set("n", "<leader>sw", function()
require('telescope.builtin').grep_string({ require("telescope.builtin").grep_string({
-- Show matches in the order they appear in the document -- Show matches in the order they appear in the document
sorting_strategy = "ascending", sorting_strategy = "ascending",
}) })
end, { desc = '[S]earch current [W]ord' }) end, { desc = "[S]earch current [W]ord" })
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set("n", "<leader>sg", require("telescope.builtin").live_grep, { desc = "[S]earch by [G]rep" })
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set("n", "<leader>sd", require("telescope.builtin").diagnostics, { desc = "[S]earch [D]iagnostics" })
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) vim.keymap.set("n", "<leader>sr", require("telescope.builtin").resume, { desc = "[S]earch [R]esume" })
vim.keymap.set("n", "<leader>sk", require("telescope.builtin").keymaps, { desc = "[S]earch [K]eymaps" })
vim.keymap.set("n", "<leader>sn", function()
require("telescope.builtin").find_files({ cwd = vim.fn.stdpath("config") })
end, { desc = "[S]earch [N]eovim files" })
-- [[ Configure Treesitter ]] -- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter` -- See `:help nvim-treesitter`
require('nvim-treesitter.configs').setup { require("nvim-treesitter.configs").setup({
-- Add languages to be installed here that you want installed for treesitter -- Add languages to be installed here that you want installed for treesitter
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim', 'markdown', ensure_installed = {
'markdown_inline', 'bash', 'zig' }, "c",
"cpp",
"go",
"lua",
"python",
"rust",
"tsx",
"typescript",
"vimdoc",
"vim",
"markdown",
"markdown_inline",
"bash",
"zig",
},
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
auto_install = true, auto_install = true,
highlight = { enable = true }, highlight = { enable = true },
-- Disabled because it caueses issues with nvim-autopair -- Disabled because it caueses issues with nvim-autopair
indent = { enable = false, disable = { 'python' } }, indent = { enable = false, disable = { "python" } },
incremental_selection = { incremental_selection = {
enable = true, enable = true,
keymaps = { keymaps = {
init_selection = '<c-space>', init_selection = "<c-space>",
node_incremental = '<c-space>', node_incremental = "<c-space>",
scope_incremental = '<c-s>', scope_incremental = "<c-s>",
node_decremental = '<M-space>', node_decremental = "<M-space>",
}, },
}, },
textobjects = { textobjects = {
@ -331,70 +394,64 @@ require('nvim-treesitter.configs').setup {
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = { keymaps = {
-- You can use the capture groups defined in textobjects.scm -- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer', ["aa"] = "@parameter.outer",
['ia'] = '@parameter.inner', ["ia"] = "@parameter.inner",
['af'] = '@function.outer', ["af"] = "@function.outer",
['if'] = '@function.inner', ["if"] = "@function.inner",
['ac'] = '@class.outer', ["ac"] = "@class.outer",
['ic'] = '@class.inner', ["ic"] = "@class.inner",
}, },
}, },
move = { move = {
enable = true, enable = true,
set_jumps = true, -- whether to set jumps in the jumplist set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = { goto_next_start = {
[']m'] = '@function.outer', ["]m"] = "@function.outer",
[']]'] = '@class.outer', ["]]"] = "@class.outer",
}, },
goto_next_end = { goto_next_end = {
[']M'] = '@function.outer', ["]M"] = "@function.outer",
[']['] = '@class.outer', ["]["] = "@class.outer",
}, },
goto_previous_start = { goto_previous_start = {
['[m'] = '@function.outer', ["[m"] = "@function.outer",
['[['] = '@class.outer', ["[["] = "@class.outer",
}, },
goto_previous_end = { goto_previous_end = {
['[M'] = '@function.outer', ["[M"] = "@function.outer",
['[]'] = '@class.outer', ["[]"] = "@class.outer",
}, },
}, },
swap = { swap = {
enable = true, enable = true,
swap_next = { swap_next = {
['<leader>a'] = '@parameter.inner', ["<leader>a"] = "@parameter.inner",
}, },
swap_previous = { swap_previous = {
['<leader>A'] = '@parameter.inner', ["<leader>A"] = "@parameter.inner",
}, },
}, },
}, },
} })
-- LSP settings. -- LSP settings.
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers.hover,
{ border = border }
)
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers.hover,
{ border = border }
)
vim.diagnostic.config { vim.diagnostic.config({
float = { float = {
border = border border = border,
} },
} })
-- Set the diagnostic symbols (Also used by Neo-tree) -- Set the diagnostic symbols (Also used by Neo-tree)
local signs = { local signs = {
Error = symbols.diagnostic.error, Error = symbols.diagnostic.error,
Warn = symbols.diagnostic.warning, Warn = symbols.diagnostic.warning,
Hint = symbols.diagnostic.hint, Hint = symbols.diagnostic.hint,
Info = symbols.diagnostic.info Info = symbols.diagnostic.info,
} }
for type, icon in pairs(signs) do for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type local hl = "DiagnosticSign" .. type
@ -411,63 +468,67 @@ local on_attach = function(client, bufnr)
-- for LSP related items. It sets the mode, buffer and description for us each time. -- for LSP related items. It sets the mode, buffer and description for us each time.
local nmap = function(keys, func, desc) local nmap = function(keys, func, desc)
if desc then if desc then
desc = 'LSP: ' .. desc desc = "LSP: " .. desc
end end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc })
end end
vim.keymap.set('n', '<leader>rn', function() vim.keymap.set("n", "<leader>rn", function()
return ':IncRename ' .. vim.fn.expand('<cword>') return ":IncRename " .. vim.fn.expand("<cword>")
end, { expr = true, desc = '[R]e[n]ame' }) end, { expr = true, desc = "[R]e[n]ame" })
-- nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') -- nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
-- Should allow code actions in visual mode -- Should allow code actions in visual mode
vim.keymap.set({ 'v', 'n' }, '<leader>ca', vim.lsp.buf.code_action, vim.keymap.set(
{ buffer = bufnr, desc = 'LSP: [C]ode [A]ction', remap = true }) { "v", "n" },
"<leader>ca",
vim.lsp.buf.code_action,
{ buffer = bufnr, desc = "LSP: [C]ode [A]ction", remap = true }
)
-- nmap('<leader>ca', require('telescope.builtin')., '[C]ode [A]ction') -- nmap('<leader>ca', require('telescope.builtin')., '[C]ode [A]ction')
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') nmap("gd", vim.lsp.buf.definition, "[G]oto [D]efinition")
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') nmap("gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation")
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') nmap("<leader>D", vim.lsp.buf.type_definition, "Type [D]efinition")
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') nmap("<leader>ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]symbols")
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') nmap("<leader>ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]symbols")
-- See `:help K` for why this keymap -- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation') nmap("K", vim.lsp.buf.hover, "Hover Documentation")
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') nmap("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation")
-- Lesser used LSP functionality -- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') nmap("<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder")
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') nmap("<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder")
nmap('<leader>wl', function() nmap("<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders') end, "[W]orkspace [L]ist Folders")
-- Create a command `:Format` local to the LSP buffer -- -- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) -- vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format() -- vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' }) -- end, { desc = 'Format current buffer with LSP' })
--
-- Format on save -- -- Format on save
local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) -- local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
if client.supports_method("textDocument/formatting") then -- if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) -- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", { -- vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup, -- group = augroup,
buffer = bufnr, -- buffer = bufnr,
callback = function() -- callback = function()
vim.lsp.buf.format() -- vim.lsp.buf.format()
end, -- end,
}) -- })
end -- end
--
-- Attach document colour support -- -- Attach document colour support
if client.server_capabilities.colorProvider then -- if client.server_capabilities.colorProvider then
require("document-color").buf_attach(bufnr) -- require("document-color").buf_attach(bufnr)
end -- end
end end
-- Enable the following language servers -- Enable the following language servers
@ -479,7 +540,6 @@ local servers = {
clangd = {}, clangd = {},
gopls = {}, gopls = {},
pyright = {}, pyright = {},
zls = {},
rust_analyzer = { rust_analyzer = {
-- enable clippy on save -- enable clippy on save
["rust-analyzer"] = { ["rust-analyzer"] = {
@ -503,56 +563,56 @@ local servers = {
}, },
jsonls = { jsonls = {
json = { json = {
schemas = require('schemastore').json.schemas(), schemas = require("schemastore").json.schemas(),
}, },
}, },
yamlls = { yamlls = {
yaml = { yaml = {
schemas = require('schemastore').yaml.schemas(), schemas = require("schemastore").yaml.schemas(),
}, },
}, },
taplo = {}, taplo = {},
cmake = {} cmake = {},
} }
-- Setup neovim lua configuration -- Setup neovim lua configuration
require('neodev').setup() require("neodev").setup()
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
capabilities.textDocument.colorProvider = { capabilities.textDocument.colorProvider = {
dynamicRegistration = true dynamicRegistration = true,
} }
-- Setup mason so it can manage external tooling -- Setup mason so it can manage external tooling
require('mason').setup() require("mason").setup()
-- Ensure the servers above are installed -- Ensure the servers above are installed
local mason_lspconfig = require 'mason-lspconfig' local mason_lspconfig = require("mason-lspconfig")
mason_lspconfig.setup { mason_lspconfig.setup({
ensure_installed = vim.tbl_keys(servers), ensure_installed = vim.tbl_keys(servers),
} })
mason_lspconfig.setup_handlers { mason_lspconfig.setup_handlers({
function(server_name) function(server_name)
require('lspconfig')[server_name].setup { require("lspconfig")[server_name].setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
settings = servers[server_name], settings = servers[server_name],
} })
end, end,
} })
-- nvim-cmp setup -- nvim-cmp setup
local cmp = require 'cmp' local cmp = require("cmp")
local luasnip = require 'luasnip' local luasnip = require("luasnip")
local lspkind = require 'lspkind' local lspkind = require("lspkind")
luasnip.config.setup {} luasnip.config.setup({})
cmp.setup { cmp.setup({
snippet = { snippet = {
expand = function(args) expand = function(args)
luasnip.lsp_expand(args.body) luasnip.lsp_expand(args.body)
@ -569,15 +629,15 @@ cmp.setup {
}, },
}), }),
}, },
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert({
['<C-u>'] = cmp.mapping.scroll_docs(-4), ["<C-u>"] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4), ["<C-d>"] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete {}, ["<C-Space>"] = cmp.mapping.complete({}),
['<CR>'] = cmp.mapping.confirm { ["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true,
}, }),
['<Tab>'] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
@ -585,8 +645,8 @@ cmp.setup {
else else
fallback() fallback()
end end
end, { 'i', 's' }), end, { "i", "s" }),
['<S-Tab>'] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.jumpable(-1) then elseif luasnip.jumpable(-1) then
@ -594,14 +654,14 @@ cmp.setup {
else else
fallback() fallback()
end end
end, { 'i', 's' }), end, { "i", "s" }),
}, }),
sources = { sources = {
{ name = 'luasnip' }, { name = "luasnip" },
{ name = 'nvim_lsp' }, { name = "nvim_lsp" },
{ name = 'path' }, { name = "path" },
}, },
} })
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et

View File

@ -5,6 +5,7 @@
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"conform.nvim": { "branch": "master", "commit": "9d5ba06d6ee7418c674f498634617416d15b6239" },
"document-color.nvim": { "branch": "main", "commit": "74c487f0e5accfaae033755451b9e367220693fd" }, "document-color.nvim": { "branch": "main", "commit": "74c487f0e5accfaae033755451b9e367220693fd" },
"fidget.nvim": { "branch": "main", "commit": "1ba38e4cbb24683973e00c2e36f53ae64da38ef5" }, "fidget.nvim": { "branch": "main", "commit": "1ba38e4cbb24683973e00c2e36f53ae64da38ef5" },
"gitsigns.nvim": { "branch": "main", "commit": "c097cb255096f333e14d341082a84f572b394fa2" }, "gitsigns.nvim": { "branch": "main", "commit": "c097cb255096f333e14d341082a84f572b394fa2" },
@ -40,7 +41,6 @@
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
"telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" },
"todo-comments.nvim": { "branch": "main", "commit": "a736bbe08c8eff370dfa60701f1e669816d4e3c8" }, "todo-comments.nvim": { "branch": "main", "commit": "a736bbe08c8eff370dfa60701f1e669816d4e3c8" },
"treesj": { "branch": "main", "commit": "60e27280030f9cd8dfb6ceb335922c6ff76682cc" },
"trouble.nvim": { "branch": "main", "commit": "b9cf677f20bb2faa2dacfa870b084e568dca9572" }, "trouble.nvim": { "branch": "main", "commit": "b9cf677f20bb2faa2dacfa870b084e568dca9572" },
"undotree": { "branch": "master", "commit": "aa93a7e5890dbbebbc064cd22260721a6db1a196" }, "undotree": { "branch": "master", "commit": "aa93a7e5890dbbebbc064cd22260721a6db1a196" },
"which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }, "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" },

View File

@ -1,6 +1,6 @@
-- See `:help vim.o` -- Set highlight on search, clear by pressing esc
-- Set highlight on search vim.o.hlsearch = true
vim.o.hlsearch = false vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
-- Make line numbers default -- Make line numbers default
vim.wo.number = true vim.wo.number = true
@ -52,3 +52,9 @@ vim.o.confirm = true
-- Turn on cursorline -- Turn on cursorline
vim.o.cursorline = true vim.o.cursorline = true
-- Don't show mode, powerline already shows it
vim.o.showmode = false
-- Minimum number of screen lines above and below the cursor
vim.o.scrolloff = 10

View File

@ -0,0 +1,63 @@
-- https://github.com/stevearc/conform.nvim
return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{
-- Customize or remove this keymap to your liking
"<leader>f",
function()
require("conform").format({ async = true, lsp_fallback = true })
end,
mode = "",
desc = "[F]ormat buffer",
},
},
opts = {
-- TODO: Automate installing these using e.g. mason
formatters_by_ft = {
c = { "clang-format" },
cpp = { "clang-format" },
go = { "goimports", "gofmt" },
python = { "ruff_format" },
rust = { "rustfmt" },
javascript = { { "prettierd", "prettier" } },
typescript = { { "prettierd", "prettier" } },
typescriptreact = { { "prettierd", "prettier" } },
css = { { "prettierd", "prettier" } },
markdown = { { "prettierd", "prettier" } },
lua = { "stylua" },
json = { "jq" },
yaml = { { "prettierd", "prettier" } },
toml = { "taplo" },
cmake = { "cmake_format" },
-- ["*"] = { "codespell" },
["_"] = { "trim_whitespace", "trim_newlines" },
},
format_after_save = {
lsp_fallback = true,
},
notify_on_error = true,
},
init = function()
vim.api.nvim_create_user_command("FormatDisable", function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true
end
end, {
desc = "Disable autoformat-on-save",
bang = true,
})
vim.api.nvim_create_user_command("FormatEnable", function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = "Re-enable autoformat-on-save",
})
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}

View File

@ -1,5 +1,6 @@
-- https://github.com/Wansmer/treesj -- https://github.com/Wansmer/treesj
return { return {
enabled = false,
'Wansmer/treesj', 'Wansmer/treesj',
keys = { keys = {
{ {