kickstart.nvim/init.lua

661 lines
22 KiB
Lua

-- DISABLED FOR NOW
-- @diagnostic disable: missing-fields -- disables annoying warnings
-- [[ Options ]]
-- See :help option-list
-- Must happen before plugins are required
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- For custom functions later
vim.g.have_nerd_font = true
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.colorcolumn = "80"
-- Only mouse in [h]elp windows
vim.opt.mouse = "h"
-- statusline already shows mode
vim.opt.showmode = false
-- Copy from anywhere
vim.opt.clipboard = "unnamedplus"
-- Visual wrap keeps indentation
vim.opt.breakindent = true
vim.opt.undofile = true
-- Case-insensitive searching UNLESS \C or capital in search
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- Text keeps moving, if not always on
vim.opt.signcolumn = "yes"
vim.opt.updatetime = 250
-- For which-key
vim.opt.timeoutlen = 300
vim.opt.list = true
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "" }
-- Preview substitutions live, as you type!
vim.opt.inccommand = "split"
vim.opt.cursorline = true
vim.opt.scrolloff = 10
vim.opt.splitright = true
vim.opt.splitbelow = true
-- wrap between words
vim.o.linebreak = true
vim.o.expandtab = true
vim.o.shiftwidth = 4
vim.o.tabstop = 8
vim.o.softtabstop = 4
-- [[ Basic Keymaps ]]
vim.opt.hlsearch = true
vim.keymap.set("n", "<Esc>", "<cmd>nohlsearch<CR>")
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true })
-- Remap for dealing with word wrap
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
vim.keymap.set("n", "gk", "v:count == 0 ? 'k' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "gj", "v:count == 0 ? 'j' : 'j'", { expr = true, silent = true })
-- Diagnostic keymaps
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous [D]iagnostic message" })
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next [D]iagnostic message" })
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, { desc = "Show diagnostic [E]rror messages" })
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" })
vim.keymap.set("t", "<Esc><Esc>", "<C-\\><C-n>", { desc = "Exit terminal mode" })
vim.keymap.set("n", "<C-h>", "<C-w><C-h>", { desc = "Move focus to the left window" })
vim.keymap.set("n", "<C-l>", "<C-w><C-l>", { desc = "Move focus to the right window" })
vim.keymap.set("n", "<C-j>", "<C-w><C-j>", { desc = "Move focus to the lower window" })
vim.keymap.set("n", "<C-k>", "<C-w><C-k>", { desc = "Move focus to the upper window" })
-- [[ Basic Autocommands ]]
-- See ':help lua-guide-autocommands'
vim.api.nvim_create_autocmd("TextYankPost", {
desc = "Highlight when yanking (copying text)",
group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})
-- [[ Install lazy.nvim ]]
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system {
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
}
end
vim.opt.runtimepath:prepend(lazypath)
-- [[ Plugins ]]
require("lazy").setup({
-- Detect tabstop and shiftwidth automatically
"tpope/vim-sleuth",
-- "gc" to comment visual regions/lines
{ "numToStr/Comment.nvim", opts = {} },
-- Git related plugins
"tpope/vim-fugitive",
"tpope/vim-rhubarb",
{
"lewis6991/gitsigns.nvim",
opts = {
signs = {
add = { text = "+" },
change = { text = "~" },
delete = { text = "_" },
topdelete = { text = "" },
changedelete = { text = "~" },
},
},
},
{ -- Shows pending keybinds
"folke/which-key.nvim",
event = "VimEnter",
config = function()
require("which-key").setup()
-- Document existing key chains
require("which-key").register {
-- Naming leader-key-groups
["<leader>c"] = { name = "[C]ode", _ = "which_key_ignore" },
["<leader>d"] = { name = "[D]ocument", _ = "which_key_ignore" },
["<leader>r"] = { name = "[R]ename", _ = "which_key_ignore" },
["<leader>s"] = { name = "[S]earch", _ = "which_key_ignore" },
["<leader>w"] = { name = "[W]orkspace", _ = "which_key_ignore" },
["<leader>o"] = { name = "[O]rgmode", _ = "which_key_ignore" },
}
end,
},
-- Fuzzy Finder (files, lsp, etc)
{
"nvim-telescope/telescope.nvim",
event = "VimEnter",
branch = "0.1.x",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ -- If encountering errors, see telescope-fzf-native README
"nvim-telescope/telescope-fzf-native.nvim",
build = "make",
cond = function()
return vim.fn.executable "make" == 1
end,
},
{ "nvim-telescope/telescope-ui-select.nvim" },
{ "nvim-tree/nvim-web-devicons", enabled = vim.g.have_nerd_font },
},
config = function()
require("telescope").setup {
defaults = {
mappings = {
i = { ["<c-enter>"] = "to_fuzzy_refine" },
},
},
extensions = {
["ui-select"] = {
require("telescope.themes").get_dropdown(),
},
},
}
-- Enable telescope fzf native, if installed
pcall(require("telescope").load_extension, "fzf")
pcall(require("telescope").load_extension, "ui-select")
-- See `:help telescope.builtin`
local builtin = require "telescope.builtin"
vim.keymap.set("n", "<leader>sh", builtin.help_tags, { desc = "[S]earch [H]elp" })
vim.keymap.set("n", "<leader>sk", builtin.keymaps, { desc = "[S]earch [K]eymaps" })
vim.keymap.set("n", "<leader>sf", builtin.find_files, { desc = "[S]earch [F]iles" })
vim.keymap.set("n", "<leader>ss", builtin.builtin, { desc = "[S]earch [S]elect Telescope" })
vim.keymap.set("n", "<leader>sw", builtin.grep_string, { desc = "[S]earch current [W]ord" })
vim.keymap.set("n", "<leader>sg", builtin.live_grep, { desc = "[S]earch by [G]rep" })
vim.keymap.set("n", "<leader>sd", builtin.diagnostics, { desc = "[S]earch [D]iagnostics" })
vim.keymap.set("n", "<leader>sr", builtin.resume, { desc = "[S]earch [R]esume" })
vim.keymap.set("n", "<leader>s.", builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
vim.keymap.set("n", "<leader>sg", builtin.git_files, { desc = "[S]earch [G]it Files" })
vim.keymap.set("n", "<leader><leader>", builtin.buffers, { desc = "[ ] Find existing buffers" })
-- Overriding default behavior and theme
vim.keymap.set("n", "<leader>/", function()
-- You can pass additional configuration to telescope to change theme, layout, etc.
builtin.current_buffer_fuzzy_find(require("telescope.themes").get_dropdown {
winblend = 10,
previewer = false,
})
end, { desc = "[/] Fuzzily search in current buffer" })
-- Also possible to pass additional configuration options.
-- See `:help telescope.builtin.live_grep()` for information about particular keys
vim.keymap.set("n", "<leader>s/", function()
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>sn", function()
builtin.find_files { cwd = vim.fn.stdpath "config" }
end, { desc = "[S]earch [N]eovim files" })
end,
},
{ -- LSP Configuration & Plugins
"neovim/nvim-lspconfig",
dependencies = {
-- Automatically install LSPs to stdpath for neovim
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"WhoIsSethDaniel/mason-tool-installer.nvim",
-- Useful status updates for LSP
{ "j-hui/fidget.nvim", opts = {} },
-- Lua LSP for Neovim config
{ "folke/neodev.nvim", opts = {} },
},
config = function()
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }),
callback = function(event)
-- Lua helper function
local nmap = function(keys, func, desc)
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
end
-- Jump to the definition of the word under your cursor.
-- This is where a variable was first declared, or where a function is defined, etc.
-- To jump back, press <C-t>.
nmap("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition")
-- Find references for the word under your cursor.
nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
-- Jump to the implementation of the word under your cursor.
-- Useful when your language has ways of declaring types without an actual implementation.
nmap("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation")
-- Jump to the type of the word under your cursor.
-- Useful when you're not sure what type a variable is and you want to see
-- the definition of its *type*, not where it was *defined*.
nmap("<leader>D", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition")
-- Fuzzy find all the symbols in your current document.
-- Symbols are things like variables, functions, types, etc.
nmap("<leader>ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]ymbols")
-- Fuzzy find all the symbols in your current workspace
-- Similar to document symbols, except searches over your whole project.
nmap("<leader>ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]ymbols")
-- Rename the variable under your cursor
-- Most Language Servers support renaming across files, etc.
nmap("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame")
-- Execute a code action, usually your cursor needs to be on top of an error
-- or a suggestion from your LSP for this to activate.
nmap("<leader>ca", vim.lsp.buf.code_action, "[C]ode [A]ction")
-- Opens a popup that displays documentation about the word under your cursor
-- See `:help K` for why this keymap
nmap("K", vim.lsp.buf.hover, "Hover Documentation")
-- WARN: This is not Goto Definition, this is Goto Declaration.
-- For example, in C this would take you to the header
nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
-- Highlight references of word under cursor
local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
buffer = event.buf,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
buffer = event.buf,
callback = vim.lsp.buf.clear_references,
})
end
end,
})
-- Broadcast cmp capabilities to servers.
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities())
-- Available config keys:
-- - cmd (table): Override the default command used to start the server
-- - filetypes (table): Override the default list of associated filetypes for the server
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
-- - settings (table): Override the default settings passed when initializing the server.
local servers = {
lua_ls = {
-- cmd = {...},
-- filetypes { ...},
-- capabilities = {},
settings = {
Lua = {
completion = {
callSnippet = "Replace",
},
-- diagnostics = { disable = { 'missing-fields' } },
},
},
},
}
-- Use :Mason to install manually
require("mason").setup()
local ensure_installed = vim.tbl_keys(servers or {})
vim.list_extend(ensure_installed, { "stylua" })
require("mason-tool-installer").setup { ensure_installed = ensure_installed }
require("mason-lspconfig").setup {
handlers = {
function(server_name)
local server = servers[server_name] or {}
-- This handles overriding only values explicitly passed
-- by the server configuration above. Useful when disabling
-- certain features of an LSP (for example, turning off formatting for tsserver)
server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {})
require("lspconfig")[server_name].setup(server)
end,
},
}
end,
},
{ -- Autoformat
"stevearc/conform.nvim",
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true }
return {
timeout_ms = 500,
lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
}
end,
formatters_by_ft = {
lua = { "stylua" },
haskell = { "fourmolu" },
-- Conform can also run multiple formatters sequentially
-- python = { "isort", "black" },
--
-- You can use a sub-list to tell conform to run *until* a formatter is found.
-- javascript = { { "prettierd", "prettier" } },
},
},
},
{
-- Autocompletion
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
-- Snippet Engine & its associated nvim-cmp source
{
"L3MON4D3/LuaSnip",
-- build needed for regex support
build = (function()
if vim.fn.has "win32" == 1 or vim.fn.executable "make" == 0 then
return
end
return "make install_jsregexp"
end)(),
dependencies = {
-- {
-- -- premade snippets
-- "rafamadriz/friendly-snippets",
-- config = function()
-- require("luasnip.loaders.from_vscode").lazy_load { exclude = { "tex" } }
-- require("luasnip.loaders.from_snipmate").lazy_load { exclude = { "tex" } }
-- end,
-- },
},
config = function()
require("luasnip.loaders.from_snipmate").lazy_load()
end,
},
"saadparwaiz1/cmp_luasnip",
-- Adds LSP completion capabilities
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
},
config = function()
local cmp = require "cmp"
local luasnip = require "luasnip"
luasnip.config.setup { enable_autosnippets = true }
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
-- old one: completeopt = "menuone,noselect",
completion = { completeopt = "menu,menuone,noinsert" },
mapping = cmp.mapping.preset.insert {
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-b>"] = cmp.mapping.scroll_docs(-8),
["<C-f>"] = cmp.mapping.scroll_docs(8),
-- Accept ([y]es) the completion
["<C-y>"] = cmp.mapping.confirm { select = true },
-- Manually trigger a completion from nvim-cmp (normally not needed)
["<C-Space>"] = cmp.mapping.complete {},
["<C-l>"] = cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
end
end, { "i", "s" }),
["<C-h>"] = cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
end
end, { "i", "s" }),
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
{ name = "neorg" },
},
}
end,
},
{
"nvim-lualine/lualine.nvim",
dependencies = {
{ "nvim-tree/nvim-web-devicons", enabled = vim.g.have_nerd_font },
},
opts = {
options = {
icons_enabled = false,
theme = "catppuccin",
component_separators = "|",
section_separators = "",
},
-- lualine layout:
-- +-------------------------------------------------+
-- | A | B | C X | Y | Z |
-- +-------------------------------------------------+
sections = {
lualine_x = {},
},
},
},
-- {
-- -- Add indentation guides even on blank lines
-- "lukas-reineke/indent-blankline.nvim",
-- main = "ibl",
-- opts = {
-- -- char = "┊",
-- -- show_trailing_blankline_indent = false,
-- },
-- },
-- Highlight todo, notes, etc in comments
{
"folke/todo-comments.nvim",
event = "VimEnter",
dependencies = { "nvim-lua/plenary.nvim" },
opts = { signs = false },
},
{ -- Collection of various small independent plugins/modules
"echasnovski/mini.nvim",
config = function()
-- Better Around/Inside textobjects
-- Examples:
-- - yinq - [Y]ank [I]nside [N]ext [']quote
-- - ci' - [C]hange [I]nside [']quote
require("mini.ai").setup { n_lines = 500 }
-- Add/delete/replace surroundings (brackets, quotes, etc.)
--
-- - saiw( - [S]urround [A]dd [I]nner [W]ord [)]Paren
-- - sd' - [S]urround [D]elete [']quotes
-- - sr(' - [S]urround [R]eplace [)] [']
require("mini.surround").setup()
-- See 'https://github.com/echasnovski/mini.nvim' for more uses
end,
},
{
-- Highlight, edit, and navigate code
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
dependencies = {
-- Interact with treesitter textobjects
"nvim-treesitter/nvim-treesitter-textobjects",
-- Keeps function description stuck on top
"nvim-treesitter/nvim-treesitter-context",
},
opts = {
-- Add languages to be installed here that you want installed for treesitter
ensure_installed = {
"bash",
"c",
"haskell",
"lua",
"vim",
"vimdoc",
"org",
"norg",
"markdown",
},
ignore_install = { "latex" },
auto_install = true,
indent = { enable = true },
highlight = {
enable = true,
disable = { "latex" },
additional_vim_regex_highlighting = { "latex", "markdown" },
},
incremental_selection = {
enable = true,
keymaps = {
-- Defaults
-- init_selection = "gnn",
-- node_incremental = "grn",
-- scope_incremental = "grc",
-- node_decremental = "grm",
init_selection = "<c-space>",
node_incremental = "<c-space>",
scope_incremental = "<c-s>",
node_decremental = "<m-space>",
},
},
textobjects = {
select = {
enable = true,
-- automatically jump forward to textobj, see targets.vim
lookahead = true,
keymaps = {
-- you can use the capture groups defined in textobjects.scm
["af"] = { query = "@function.outer", desc = "[a]round [f]unction" },
["if"] = { query = "@function.inner", desc = "[i]nner [f]unction" },
-- [a/i]p is taken for "paragraph".
["aa"] = { query = "@parameter.outer", desc = "[a]round [a]rgument" },
["ia"] = { query = "@parameter.inner", desc = "[i]nner [a]rgument" },
-- fucks up vimtex commands!
-- ['ac'] = '@class.outer',
-- ['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]m"] = "@function.outer",
["]]"] = "@class.outer",
},
goto_next_end = {
["]M"] = "@function.outer",
["]["] = "@class.outer",
},
goto_previous_start = {
["[m"] = "@function.outer",
["[["] = "@class.outer",
},
goto_previous_end = {
["[M"] = "@function.outer",
["[]"] = "@class.outer",
},
},
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
lsp_interop = {
enable = true,
border = "none",
floating_preview_opts = {},
peek_definition_code = {
["<leader>df"] = "@function.outer",
["<leader>dF"] = "@class.outer",
},
},
},
},
config = function(_, opts)
require("nvim-treesitter.configs").setup(opts)
end,
},
-- Uncomment for debug plugin
-- require 'kickstart.plugins.debug',
-- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
{ import = "custom.plugins" },
}, {
ui = {
-- Default icons, if no nerd font installed
icons = vim.g.have_nerd_font and {} or {
cmd = "",
config = "🛠",
event = "📅",
ft = "📂",
init = "",
keys = "🗝",
plugin = "🔌",
runtime = "💻",
require = "🌙",
source = "📄",
start = "🚀",
task = "📌",
lazy = "💤 ",
},
},
})
-- modeline
-- vim: ts=2 sts=4 sw=2 et