From 487f87498407305422aa3d37776cb23d9d7f492a Mon Sep 17 00:00:00 2001 From: Joshua Finch Date: Thu, 29 Feb 2024 21:22:09 -0600 Subject: [PATCH] Massive rewrite and modularization of the existing neovim config to break it up into multiple files and to use a maintained package manager (lazy.nvim) --- init.lua | 562 +--------------------------------- lua/autocmds.lua | 6 + lua/custom_functions.lua | 31 ++ lua/keymappings.lua | 52 ++++ lua/lsp.lua | 8 + lua/plugins.lua | 35 +++ lua/plugins/comment.lua | 16 + lua/plugins/floaterm.lua | 7 + lua/plugins/gruvbox.lua | 11 + lua/plugins/lspconfig.lua | 4 + lua/plugins/lualine.lua | 18 ++ lua/plugins/luasnip.lua | 10 + lua/plugins/mason.lua | 95 ++++++ lua/plugins/nvim-cmp.lua | 90 ++++++ lua/plugins/telekasten.lua | 30 ++ lua/plugins/telescope.lua | 44 +++ lua/plugins/treesitter.lua | 42 +++ lua/plugins/vim-gitgutter.lua | 3 + lua/plugins/vim-godot.lua | 4 + lua/settings.lua | 33 ++ 20 files changed, 545 insertions(+), 556 deletions(-) create mode 100644 lua/autocmds.lua create mode 100644 lua/custom_functions.lua create mode 100644 lua/keymappings.lua create mode 100644 lua/lsp.lua create mode 100644 lua/plugins.lua create mode 100644 lua/plugins/comment.lua create mode 100644 lua/plugins/floaterm.lua create mode 100644 lua/plugins/gruvbox.lua create mode 100644 lua/plugins/lspconfig.lua create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/luasnip.lua create mode 100644 lua/plugins/mason.lua create mode 100644 lua/plugins/nvim-cmp.lua create mode 100644 lua/plugins/telekasten.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 lua/plugins/vim-gitgutter.lua create mode 100644 lua/plugins/vim-godot.lua create mode 100644 lua/settings.lua diff --git a/init.lua b/init.lua index d2a538f..4a6aa4f 100644 --- a/init.lua +++ b/init.lua @@ -42,559 +42,9 @@ -- -- Created: 7/2/2012 --- Custom Functions --- 'softrequire' provides a wrapper around the builtin require. If the require has failed in a `local mod = softrequire('m') call, a quick check of --- 'if mod then' can wrap code dependent upon the require, and fails gracefully -local function softrequire(m) - local ok, err = pcall(require, m) - if not ok then return nil, err end - return err -end - -local function execute(type) - local command_table = { - run = { - java = "java %", - python = "python %", - rust = "cargo run", - }, - test = { - python = "python test", - rust = "cargo test", - }, - benchmark = { - rust = "cargo bench", - }, - } - vim.api.nvim_command('write') - local command = command_table[type][vim.bo.filetype] - - if command ~= nil then - vim.cmd('FloatermNew --autoclose=0 ' .. command) - end -end - --- Force install Packer if it is not found locally -local packer_need_bootstrap = false -local install_path = vim.fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' -if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - vim.fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) - vim.cmd [[packadd packer.nvim]] - packer_need_bootstrap = true -end - --- Manage plugins -require('packer').startup(function(use) - use 'wbthomason/packer.nvim' -- Packer self management - - -- Completion, linting, search - use 'neovim/nvim-lspconfig' -- Adds native support for language servers and autocompletion - - use { - 'williamboman/mason.nvim', -- Installer for LSPs, DAP, linters, etc - run = ':MasonUpdate', - } - use 'williamboman/mason-lspconfig.nvim' -- Bridges the gap between lspconfig and mason - - use { - 'nvim-telescope/telescope.nvim', -- Popup, quick search plugin for looking up files, files content, loading a filebrowser, etc - requires = { - { 'nvim-lua/plenary.nvim' } - } - } - - use { - 'nvim-treesitter/nvim-treesitter', -- Support for syntax highlighting (and other bits) - run = ':TSUpdate' - } - - use 'tpope/vim-surround' -- Change surrounding characters '{},[],quotes,etc' - use 'numToStr/Comment.nvim' -- Fancy commenting plugin - - -- Completion support - use 'hrsh7th/cmp-nvim-lsp' -- Completion source for nvim-cmp: LSPs - use 'hrsh7th/cmp-buffer' -- Completion source for nvim-cmp: buffer - use 'hrsh7th/cmp-path' -- Completion source for nvim-cmp: path - use 'hrsh7th/cmp-cmdline' -- Completion source for nvim-cmp: vim's cmdline - use 'hrsh7th/nvim-cmp' -- Completion engine for neovim - - -- Snippets - use 'L3MON4D3/LuaSnip' -- Snippet engine written in Lua! - use 'saadparwaiz1/cmp_luasnip' -- Necessary plugin to load luasnips into nvim-cmp - use 'rafamadriz/friendly-snippets' -- Snippets! - - -- Theming - use { - 'ellisonleao/gruvbox.nvim', -- Color Scheme - config = function() - require('gruvbox').setup({ - contrast = 'hard', - }) - vim.cmd('colorscheme gruvbox') - end - } - - use { - 'nvim-lualine/lualine.nvim', -- Very quick and useful statusline setup - requires = { - { 'kyazdani42/nvim-web-devicons', opt = true } - }, - } - - -- Git - use 'airblade/vim-gitgutter' -- Show git diffs in the symbol gutter - use 'tpope/vim-fugitive' -- Git integration - - -- Utility - use 'voldikss/vim-floaterm' -- Floating terminal enabling working in the cli without adjusting window layout - use 'renerocksai/telekasten.nvim' -- Note taking helper with daily/weekly notes - - -- Experimental - use { - 'habamax/vim-godot', - ft = { 'gdscript' } - } - use 'mfussenegger/nvim-dap' - use 'rcarriga/nvim-dap-ui' - - -- Automatically set up your configuration after cloning packer.nvim - if packer_need_bootstrap then - require('packer').sync() - end -end) - --- Load plugin modules with a softfail option -local cmp = softrequire('cmp') -local comment = softrequire('Comment') -local dap = softrequire('dap') -local lualine = softrequire('lualine') -local luasnip = softrequire('luasnip') -local mason = softrequire('mason') -local mason_lspconfig = softrequire('mason-lspconfig') -local nvim_lsp = softrequire('lspconfig') -local telekasten = softrequire('telekasten') -local telescope = softrequire('telescope') -local telescope_builtin = softrequire('telescope.builtin') -local treesitter_configs = softrequire('nvim-treesitter.configs') - --- NEOVIM SETTINGS -vim.opt.background = 'dark' -- Force a dark background for the colorscheme -vim.opt.clipboard = "unnamed,unnamedplus" -- Use both the "*" and "+" registers for yanks and deletes (puts things in the system clipboard) -vim.opt.colorcolumn = '121' -- Highlight column to show -vim.opt.completeopt = 'menu,menuone,noinsert' -- Change how the completion menu is interacted with -vim.opt.cursorline = true -- Highlight the line the cursor is on. -vim.opt.expandtab = true -- Expand tabs into spaces -vim.opt.fileformat = 'unix' -- Explicitly state that files should use the unix style EOL characters. -vim.opt.fillchars = 'fold: ' -- Sets the character that fills in a fold line -vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' -- Uses Treesitter to determine where code folding should occur -vim.opt.foldlevel = 10 -- Sets the initial level at which folds will be closed -vim.opt.foldmethod = 'expr' -- Attempt to use the syntax of a file to set folds. -vim.opt.formatoptions = 'cqrto' -- Allow auto insertion of comment lines when using o or O on a comment. -vim.opt.list = true -- Show the listchars -vim.opt.listchars = 'tab:|·,trail:¬,extends:>,precedes:<,nbsp:+' -- Characters to display when showing whitespace -vim.opt.mouse = 'a' -- Enable mouse mode -vim.opt.number = true -- Show the line number in the gutter. -vim.opt.relativenumber = true -- Relative line number -vim.opt.shiftround = true -- Round indentation to shiftwidth -vim.opt.shiftwidth = 4 -- Number of spaces a tab counts for when converting tabs to spaces -vim.opt.shortmess = 'at' -- Abbreviations and truncation of cmd messages -vim.opt.showmatch = true -- Show matching bracket -vim.opt.signcolumn = 'yes' -- Always show the gutter -vim.opt.smartindent = true -- Attempt to insert indentation to fit traditional languages. -vim.opt.softtabstop = 4 -- Number of spaces a tab counts for when converting tabs to spaces -vim.opt.splitbelow = true -- Split windows below when horizontal splitting -vim.opt.splitright = true -- Split windows right when vertical splitting -vim.opt.swapfile = false -- Disable the creation of swap files for open files -vim.opt.tabstop = 4 -- Setting the value of spaces per tab -vim.opt.termguicolors = true -- Enable the truecolor GUI colors in a terminal -vim.opt.undodir = os.getenv('HOME') .. '/.config/nvim/undodir' -- Set a specific undo file directory -vim.opt.undofile = true -- Enable undo files -vim.opt.updatetime = 50 -- Update time in milliseconds -vim.opt.wrap = false -- Do _not_ wrap lines - --- KEYBOARD SHORTCUTS -vim.g.mapleader = ',' - -local keymap = vim.keymap.set - --- Standard keybinding options -local options = { noremap = true } - --- Block tab/untab without leaving visual mode -keymap('v', '<', '', '>gv', options) - --- Visual selection can be moved up and down -keymap('v', 'J', ':m \'>+1gv=gv') -keymap('v', 'K', ':m \'<-2gv=gv') - --- Sort selected lines alphabetically, descending -keymap('v', 's', ':sort', options) - --- Move between panes in Neovim -keymap('n', '', 'j', options) -keymap('n', '', 'k', options) -keymap('n', '', 'h', options) -keymap('n', '', 'l', options) - --- Don't move the cursor when appending the following line to the current -keymap('n', 'J', 'mzJ`z') - --- Switch or close buffers in the window -keymap('n', 'n', ':bn', options) -keymap('n', 'p', ':bp', options) -keymap('n', 'd', ':bp|bd #', options) - --- Reload the nvim config -keymap('n', 'r', ":source % | PackerCompile", options) - --- Toggle spellcheck -keymap('n', 's', ':set spell!', options) - --- Quick exit from Insert mode -keymap('i', 'jk', '', options) - --- Toggle display of whitespace chars -keymap('n', 'w', ':set list!', options) - --- Floating terminal -keymap('n', 't', ':FloatermToggle myfloat') -keymap('t', '', ':q') - --- Folding the section under the cursor -keymap('n', '', 'za') - --- Keymaps for custom functions -keymap('n', 'et', function() execute('test') end) -keymap('n', 'er', function() execute('run') end) -keymap('n', 'eb', function() execute('benchmark') end) - --- Vim-Fugitive -keymap('n', 'gis', vim.cmd.Git) -keymap('n', 'gid', vim.cmd.Gdiff) - -keymap('n', 'eo', ':Lexplore', options) - -keymap('n', '', ':noh', options) - -keymap('n', 'rn', ':%s///g<<', options) - --- Auto-recompile and load on init.lua file changes -vim.api.nvim_create_autocmd({ 'BufWritePost' }, { - pattern = { 'init.lua' }, - group = vim.api.nvim_create_augroup('nvim_reload', { clear = true }), - command = "source % | PackerCompile" -}) - --- Fix for treesitter folds, as folds are not recalculated upon buffer changes (especially when pasting text) -vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNew', 'BufWinEnter' }, { - pattern = '*', - group = vim.api.nvim_create_augroup('telescope_fold_workaround', { clear = true }), - command = 'set foldexpr=nvim_treesitter#foldexpr()', -}) - --- Create a new copy of capabilities and enable the snippetSupport -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true - -if luasnip then - require('luasnip.loaders.from_vscode').lazy_load() -- Attempt to load VSCode based snippets -end - --- All functions and keymappings contained here are universal to LSPs -local on_attach = function(client, bufnr) - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Keyboard Mappings - local bufopts = { noremap = true, silent = true, buffer = bufnr } - keymap('n', '', vim.diagnostic.goto_prev, bufopts) - keymap('n', '', vim.diagnostic.goto_next, bufopts) - -- keymap('n', 'gl', vim.diagnostic.open_float, bufopts) - keymap('n', 'ga', vim.lsp.buf.code_action, bufopts) - keymap('n', 'gD', vim.lsp.buf.declaration, bufopts) - keymap('n', 'gd', vim.lsp.buf.definition, bufopts) - keymap('n', 'K', vim.lsp.buf.hover, bufopts) - keymap('n', 'gi', vim.lsp.buf.implementation, bufopts) - keymap('n', 'gs', vim.lsp.buf.signature_help, bufopts) - keymap('n', 'D', vim.lsp.buf.type_definition, bufopts) - -- keymap('n', 'rn', vim.lsp.buf.rename, bufopts) - keymap('n', 'gr', vim.lsp.buf.references, bufopts) - keymap('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) - - -- DAP debug - if dap then - keymap('n', '', function() dap.continue() end, bufopts) - keymap('n', '', function() dap.step_over() end, bufopts) - keymap('n', '', function() dap.step_into() end, bufopts) - keymap('n', '', function() dap.step_out() end, bufopts) - keymap('n', 'b', function() dap.toggle_breakpoint() end, bufopts) - end -end - --- Module loading -if mason and mason_lspconfig and nvim_lsp then - mason.setup {} - - mason_lspconfig.setup { - automatic_installation = true, - } - - mason_lspconfig.setup_handlers { - -- Default LSP handler - function(server_name) - nvim_lsp[server_name].setup { - capabilities = capabilities, - on_attach = on_attach - } - end, - - ['rust_analyzer'] = function() - nvim_lsp.rust_analyzer.setup { - capabilities = capabilities, - on_attach = on_attach, - settings = { - ['rust-analyzer'] = { - checkOnSave = true, - check = { - command = 'clippy', - extraArgs = { '--', '-Dclippy::all', '-Wclippy::pedantic' }, - }, - diagnostics = { - enable = true, - experimental = { - enable = true, - } - } - } - } - } - end, - - ['lua_ls'] = function() - nvim_lsp.lua_ls.setup { - capabilities = capabilities, - on_attach = on_attach, - settings = { - Lua = { - diagnostics = { - globals = { 'vim' } - } - } - } - } - end, - } - - -- Manually adding gdscript as Mason doesn't handle this anymore - -- nvim_lsp.gdscript.setup {} -end - -if telescope and telescope_builtin then - local actions = require('telescope.actions') - - telescope.setup { - defaults = { - file_ignore_patterns = { - '.png$', - '.jpg$', - '.jpeg$', - '.ico$', - '.icns$', - '.webp$', - '.uproject$', -- Unreal Engine - '-workspace$', - }, - layout_strategy = 'vertical', - layout_config = { - height = 0.8 - }, - results_title = false, - prompt_prefix = '  ', - selection_caret = '➤ ', - mappings = { - i = { - [""] = actions.close - }, - }, - } - } - - keymap('n', 'ff', telescope_builtin.find_files, options) - keymap('n', 'fg', telescope_builtin.git_commits, options) - keymap('n', 'fh', telescope_builtin.help_tags, options) - keymap('n', 'fr', telescope_builtin.live_grep, options) - keymap('n', 'fm', telescope_builtin.marks, options) - keymap('n', 'fb', telescope_builtin.buffers, options) - keymap('n', 'fd', telescope_builtin.diagnostics, options) -end - -if treesitter_configs then - treesitter_configs.setup { - auto_install = true, - ensure_installed = { - 'c', - 'c_sharp', - 'comment', - 'css', - 'html', - 'java', - 'javascript', - 'json', - 'lua', - 'python', - 'query', - 'rust', - 'toml', - 'tsx', - 'typescript', - 'yaml', - }, - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, - incremental_selection = { - enable = true, - }, - indent = { - enable = true, - }, - rainbow = { - enable = true, - } - } -end - -if comment then - comment.setup { - ignore = '^$', - toggler = { - line = 'gc', - block = '', - }, - } - - keymap('n', 'c', ':norm gcc', options) - keymap('v', 'c', ':norm gc', options) -end - -if lualine then - lualine.setup { - -- See :h lualine-Default-Configuration for defaults and options - tabline = { - -- Set the contents of the top left tabline - lualine_a = { - 'tabs', - }, - lualine_z = { - 'buffers', - } - } - } -end - -if telekasten then - local home = vim.fn.expand('~/.zettelkasten') - telekasten.setup({ - home = home, - dailies = home .. '/' .. 'daily', - weeklies = home .. '/' .. 'weeklies', - templates = home .. '/' .. 'templates', - template_new_note = home .. '/' .. 'templates/new_note.md', - template_new_daily = home .. '/' .. 'templates/daily.md', - template_new_weekly = home .. '/' .. 'templates/weekly.md', - command_palette_theme = 'ivy', - show_tags_theme = 'get_cursor', - plug_into_calendar = false, - }) - - -- Color for telekasten syntax - vim.api.nvim_set_hl(0, 'tkLink', - { ctermfg = 72, cterm = { bold = true, underdouble = true }, fg = '#689d6a', bold = true, underdouble = true }) - vim.api.nvim_set_hl(0, 'tkBrackets', { ctermfg = 'gray', fg = 'gray' }) - vim.api.nvim_set_hl(0, 'tkTag', { ctermfg = 'gray', fg = 'gray' }) - - keymap('n', 'zp', telekasten.panel, options) - keymap('n', 'zn', telekasten.find_notes, options) - keymap('n', 'zt', telekasten.show_tags, options) -end - --- nvim-cmp config -if cmp then - cmp.setup { - snippet = { - -- REQUIRED, the plugin will NOT work without a snippet engine enabled - expand = function(args) - -- Enable luasnips - if luasnip then - luasnip.lsp_expand(args.body) - end - end - }, - completion = { - completeopt = 'menu,menuone,noinsert' - }, - experimental = { - ghost_text = true, - }, - mapping = { - -- Key mappings based off of the standard autocomplete keybindings from VIM - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }), - }, - formatting = { - format = function(entry, vim_item) - -- vim_item.kind = string.format('%s', vim_item.kind) - vim_item.menu = ({ - buffer = '[Buf]', - luasnip = '[Snips]', - nvim_lsp = '[LSP]', - nvim_lua = '[Lua]' - })[entry.source.name] - return vim_item - end, - fields = { 'abbr', 'kind', 'menu' } - }, - sources = cmp.config.sources({ - -- NOTE: the order of sources determines their loading priority in the autocomplete menu - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }, { - { name = 'buffer' }, - }) - } - - cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' }, - { name = 'buffer' } - }, { - { name = 'cmdline' } - }) - }) - - cmp.setup.cmdline('/', { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' } - } - }) -end - -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, { - underline = true, - virtual_text = true, - signs = true, - update_in_insert = true, - } -) +require('custom_functions') +require('keymappings') +require('settings') +require('autocmds') +require('lsp') +require('plugins') diff --git a/lua/autocmds.lua b/lua/autocmds.lua new file mode 100644 index 0000000..03e53e1 --- /dev/null +++ b/lua/autocmds.lua @@ -0,0 +1,6 @@ +-- Fix for treesitter folds, as folds are not recalculated upon buffer changes (especially when pasting text) +vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNew', 'BufWinEnter' }, { + pattern = '*', + group = vim.api.nvim_create_augroup('telescope_fold_workaround', { clear = true }), + command = 'set foldexpr=nvim_treesitter#foldexpr()', +}) diff --git a/lua/custom_functions.lua b/lua/custom_functions.lua new file mode 100644 index 0000000..c0e5dcb --- /dev/null +++ b/lua/custom_functions.lua @@ -0,0 +1,31 @@ +-- 'softrequire' provides a wrapper around the builtin require. If the require has failed in a `local mod = softrequire('m') call, a quick check of +-- 'if mod then' can wrap code dependent upon the require, and fails gracefully +local function softrequire(m) + local ok, err = pcall(require, m) + if not ok then return nil, err end + return err +end + +local function execute(type) + local command_table = { + run = { + java = "java %", + python = "python %", + rust = "cargo run", + }, + test = { + python = "python test", + rust = "cargo test", + }, + benchmark = { + rust = "cargo bench", + }, + } + vim.api.nvim_command('write') + local command = command_table[type][vim.bo.filetype] + + if command ~= nil then + vim.cmd('FloatermNew --autoclose=0 ' .. command) + end +end + diff --git a/lua/keymappings.lua b/lua/keymappings.lua new file mode 100644 index 0000000..5536552 --- /dev/null +++ b/lua/keymappings.lua @@ -0,0 +1,52 @@ +local cf = require('custom_functions') + +vim.g.mapleader = ',' + +-- Standard keybinding options +local options = { noremap = true } + +-- Block tab/untab without leaving visual mode +vim.keymap.set('v', '<', '', '>gv', options) + +-- Visual selection can be moved up and down +vim.keymap.set('v', 'J', ':m \'>+1gv=gv') +vim.keymap.set('v', 'K', ':m \'<-2gv=gv') + +-- Sort selected lines alphabetically, descending +vim.keymap.set('v', 's', ':sort', options) + +-- Move between panes in Neovim +vim.keymap.set('n', '', 'j', options) +vim.keymap.set('n', '', 'k', options) +vim.keymap.set('n', '', 'h', options) +vim.keymap.set('n', '', 'l', options) + +-- Don't move the cursor when appending the following line to the current +vim.keymap.set('n', 'J', 'mzJ`z') + +-- Switch or close buffers in the window +vim.keymap.set('n', 'n', ':bn', options) +vim.keymap.set('n', 'p', ':bp', options) +vim.keymap.set('n', 'd', ':bp|bd #', options) + +-- Toggle spellcheck +vim.keymap.set('n', 's', ':set spell!', options) + +-- Quick exit from Insert mode +vim.keymap.set('i', 'jk', '', options) + +-- Toggle display of whitespace chars +vim.keymap.set('n', 'w', ':set list!', options) + +-- Folding the section under the cursor +vim.keymap.set('n', '', 'za') + +-- Keymaps for custom functions +vim.keymap.set('n', 'et', function() cf.execute('test') end) +vim.keymap.set('n', 'er', function() cf.execute('run') end) +vim.keymap.set('n', 'eb', function() cf.execute('benchmark') end) + +vim.keymap.set('n', 'eo', ':Lexplore', options) + +vim.keymap.set('n', 'rn', ':%s///g', options) diff --git a/lua/lsp.lua b/lua/lsp.lua new file mode 100644 index 0000000..f40f7b7 --- /dev/null +++ b/lua/lsp.lua @@ -0,0 +1,8 @@ +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + underline = true, + virtual_text = true, + signs = true, + update_in_insert = true, + } +) diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..c8765d2 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,35 @@ +-- use 'tpope/vim-fugitive' -- Git integration +-- +-- -- Experimental +-- use 'mfussenegger/nvim-dap' +-- use 'rcarriga/nvim-dap-ui' + +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", + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require('lazy').setup({ + require('plugins/lspconfig'), + require('plugins/mason'), + require('plugins/gruvbox'), + require('plugins/comment'), + require('plugins/treesitter'), + require('plugins/vim-gitgutter'), + require('plugins/luasnip'), + require('plugins/nvim-cmp'), + require('plugins/lualine'), + require('plugins/telekasten'), + require('plugins/telescope'), + 'tpope/vim-surround', + require('plugins/floaterm'), + require('plugins/vim-godot'), +}) diff --git a/lua/plugins/comment.lua b/lua/plugins/comment.lua new file mode 100644 index 0000000..df45378 --- /dev/null +++ b/lua/plugins/comment.lua @@ -0,0 +1,16 @@ +return { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup { + ignore = '^$', + toggler = { + line = 'gc', + block = '', + }, + } + end, + keys = { + { 'c', ':norm gcc' }, + { 'c', ':norm gc', mode = 'v' }, + } +} diff --git a/lua/plugins/floaterm.lua b/lua/plugins/floaterm.lua new file mode 100644 index 0000000..db94f2b --- /dev/null +++ b/lua/plugins/floaterm.lua @@ -0,0 +1,7 @@ +return { + 'voldikss/vim-floaterm', + keys = { + { 't', ':FloatermToggle myfloat' }, + { '', ':q', mode = 't' }, + }, +} diff --git a/lua/plugins/gruvbox.lua b/lua/plugins/gruvbox.lua new file mode 100644 index 0000000..3ac8da5 --- /dev/null +++ b/lua/plugins/gruvbox.lua @@ -0,0 +1,11 @@ +return { + 'ellisonleao/gruvbox.nvim', + config = function() + require('gruvbox').setup({ + contrast = 'hard', + }) + vim.cmd([[colorscheme gruvbox]]) + end, + lazy = false, + priority = 1000, +} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..39f8bba --- /dev/null +++ b/lua/plugins/lspconfig.lua @@ -0,0 +1,4 @@ +return { + 'neovim/nvim-lspconfig', + lazy = false, +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..24e534d --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,18 @@ +return { + 'nvim-lualine/lualine.nvim', + config = function() + require('lualine').setup { + tabline = { + lualine_a = { + 'tabs', + }, + lualine_z = { + 'buffers', + } + } + } + end, + dependencies = { + 'kyazdani42/nvim-web-devicons' + }, +} diff --git a/lua/plugins/luasnip.lua b/lua/plugins/luasnip.lua new file mode 100644 index 0000000..a457834 --- /dev/null +++ b/lua/plugins/luasnip.lua @@ -0,0 +1,10 @@ +return { + 'L3MON4D3/LuaSnip', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + dependencies = { + 'saadparwaiz1/cmp_luasnip', -- Wrapper to load snippets in nvim-cmp + 'rafamadriz/friendly-snippets', + }, +} diff --git a/lua/plugins/mason.lua b/lua/plugins/mason.lua new file mode 100644 index 0000000..df85484 --- /dev/null +++ b/lua/plugins/mason.lua @@ -0,0 +1,95 @@ +return { + 'williamboman/mason.nvim', + config = function() + require('mason').setup() + + local mason_lspconfig = require('mason-lspconfig') + + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + + -- All functions and keymaps contained here are universal to LSPs + local on_attach = function(client, bufnr) + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Keyboard Mappings + local bufopts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set('n', '', vim.diagnostic.goto_prev, bufopts) + vim.keymap.set('n', '', vim.diagnostic.goto_next, bufopts) + -- vim.keymap.set('n', 'gl', vim.diagnostic.open_float, bufopts) + vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + -- vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) + + -- DAP debug + -- if dap then + -- vim.keymap.set('n', '', function() dap.continue() end, bufopts) + -- vim.keymap.set('n', '', function() dap.step_over() end, bufopts) + -- vim.keymap.set('n', '', function() dap.step_into() end, bufopts) + -- vim.keymap.set('n', '', function() dap.step_out() end, bufopts) + -- vim.keymap.set('n', 'b', function() dap.toggle_breakpoint() end, bufopts) + -- end + end + + mason_lspconfig.setup { + automatic_installation = true, + } + + local lspconfig = require('lspconfig') + + mason_lspconfig.setup_handlers { + function(server_name) + lspconfig[server_name].setup { + capabilities = capabilities, + on_attach = on_attach + } + end, + + ['rust_analyzer'] = function() + lspconfig.rust_analyzer.setup { + capabilities = capabilities, + on_attach = on_attach, + settings = { + ['rust-analyzer'] = { + checkOnSave = true, + check = { + command = 'clippy', + extraArgs = { '--', '-Dclippy::all', '-Wclippy::pedantic' }, + }, + diagnostics = { + enable = true, + experimental = { + enable = true, + } + } + } + } + } + end, + + ['lua_ls'] = function() + lspconfig.lua_ls.setup { + capabilities = capabilities, + on_attach = on_attach, + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } + } + end, + } + end, + dependencies = { + 'williamboman/mason-lspconfig.nvim' + }, +} diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..406e286 --- /dev/null +++ b/lua/plugins/nvim-cmp.lua @@ -0,0 +1,90 @@ +return { + 'hrsh7th/nvim-cmp', + config = function() + local cmp = require('cmp') + cmp.setup { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + completion = { + completeopt = 'menu,menuone,noinsert', + }, + experimental = { + ghost_text = true, + }, + mapping = { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }), + }, + formatting = { + format = function(entry, vim_item) + vim_item.menu = ({ + buffer = '[Buf]', + luasnip = '[Snips]', + nvim_lsp = '[LSP]', + nvim_lua = '[Lua]', + })[entry.source.name] + return vim_item + end, + field = { 'abbr', 'kind', 'menu' } + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, { + { name = 'buffer' }, + }) + } + + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' }, + { name = 'buffer' }, + }, { + { name = 'cmdline' }, + }) + }) + + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + end, + dependencies = { + { + 'hrsh7th/cmp-nvim-lsp', + lazy = false, + }, + { + 'hrsh7th/cmp-buffer', + lazy = false, + }, + { + 'hrsh7th/cmp-path', + lazy = false, + }, + { + 'hrsh7th/cmp-cmdline', + lazy = false, + }, + { + 'L3MON4D3/LuaSnip', + lazy = false, + }, + }, + event = "InsertEnter", + lazy = false, +} diff --git a/lua/plugins/telekasten.lua b/lua/plugins/telekasten.lua new file mode 100644 index 0000000..2a8a9f1 --- /dev/null +++ b/lua/plugins/telekasten.lua @@ -0,0 +1,30 @@ +return { + 'renerocksai/telekasten.nvim', + config = function() + local home = vim.fn.expand('~/.zettelkasten') + require('telekasten').setup({ + home = home, + dailies = home .. '/' .. 'daily', + weeklies = home .. '/' .. 'weeklies', + templates = home .. '/' .. 'templates', + template_new_note = home .. '/' .. 'templates/new_note.md', + template_new_daily = home .. '/' .. 'templates/daily.md', + template_new_weekly = home .. '/' .. 'templates/weekly.md', + command_palette_theme = 'ivy', + show_tags_theme = 'get_cursor', + plug_into_calendar = false, + + }) + + -- Color for telekasten syntax + vim.api.nvim_set_hl(0, 'tkLink', { ctermfg = 72, cterm = { bold = true, underdouble = true }, fg = '#689d6a', bold = true, underdouble = true }) + vim.api.nvim_set_hl(0, 'tkBrackets', { ctermfg = 'gray', fg = 'gray' }) + vim.api.nvim_set_hl(0, 'tkTag', { ctermfg = 'gray', fg = 'gray' }) + end, + keys = { + { 'zp', ':Telekasten panel' }, + { 'zn', ':Telekasten find_notes' }, + { 'zt', ':Telekasten show_tags' }, + }, + -- lazy = false +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..28ab4e8 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,44 @@ +return { + 'nvim-telescope/telescope.nvim', + config = function() + local actions = require('telescope.actions') + require('telescope').setup { + defaults = { + file_ignore_patterns = { + '.png$', + '.jpg$', + '.jpeg$', + '.ico$', + '.icns$', + '.webp$', + '.uproject$', + '-workspace$', + }, + -- layout_strategy = 'vertical', + -- layout_config = { + -- height = 0.0 + -- }, + results_title = false, + prompt_prefix = '  ', + selection_caret = '➤ ', + mappings = { + i = { + [""] = actions.close + }, + }, + }, + } + end, + dependencies = { + 'nvim-lua/plenary.nvim' + }, + keys = { + { 'ff', ":Telescope find_files" }, + { 'fg', ":Telescope git_commits" }, + { 'fh', ":Telescope help_tags" }, + { 'fr', ":Telescope live_grep" }, + { 'fm', ":Telescope marks" }, + { 'fb', ":Telescope buffers" }, + { 'fd', ":Telescope diagnostics" }, + }, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..bf13d69 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,42 @@ +return { + 'nvim-treesitter/nvim-treesitter', + config = function() + require('nvim-treesitter.configs').setup { + auto_install = true, + ensure_installed = { + 'c', + 'c_sharp', + 'comment', + 'css', + 'html', + 'java', + 'javascript', + 'json', + 'lua', + 'python', + 'query', + 'rust', + 'toml', + 'tsx', + 'typescript', + 'yaml', + }, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + incremental_selection = { + enable = true, + }, + indent = { + enable = true, + }, + rainbow = { + enable = true, + } + } + -- require('nvim-treesitter.install').prefer_git = true + -- TSUpdate + end, + lazy = false, +} diff --git a/lua/plugins/vim-gitgutter.lua b/lua/plugins/vim-gitgutter.lua new file mode 100644 index 0000000..c01d5d6 --- /dev/null +++ b/lua/plugins/vim-gitgutter.lua @@ -0,0 +1,3 @@ +return { + 'airblade/vim-gitgutter' +} diff --git a/lua/plugins/vim-godot.lua b/lua/plugins/vim-godot.lua new file mode 100644 index 0000000..31f2722 --- /dev/null +++ b/lua/plugins/vim-godot.lua @@ -0,0 +1,4 @@ +return { + 'habamax/vim-godot', + ft = 'gdscript', +} diff --git a/lua/settings.lua b/lua/settings.lua new file mode 100644 index 0000000..0cd5bcc --- /dev/null +++ b/lua/settings.lua @@ -0,0 +1,33 @@ +vim.opt.background = 'dark' -- Force a dark background for the colorscheme +vim.opt.clipboard = "unnamed,unnamedplus" -- Use both the "*" and "+" registers for yanks and deletes (puts things in the system clipboard) +vim.opt.colorcolumn = '121' -- Highlight column to show +vim.opt.completeopt = 'menu,menuone,noinsert' -- Change how the completion menu is interacted with +vim.opt.cursorline = true -- Highlight the line the cursor is on. +vim.opt.expandtab = true -- Expand tabs into spaces +vim.opt.fileformat = 'unix' -- Explicitly state that files should use the unix style EOL characters. +vim.opt.fillchars = 'fold: ' -- Sets the character that fills in a fold line +vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' -- Uses Treesitter to determine where code folding should occur +vim.opt.foldlevel = 10 -- Sets the initial level at which folds will be closed +vim.opt.foldmethod = 'expr' -- Attempt to use the syntax of a file to set folds. +vim.opt.formatoptions = 'cqrto' -- Allow auto insertion of comment lines when using o or O on a comment. +vim.opt.list = true -- Show the listchars +vim.opt.listchars = 'tab:|·,trail:¬,extends:>,precedes:<,nbsp:+' -- Characters to display when showing whitespace +vim.opt.mouse = 'a' -- Enable mouse mode +vim.opt.number = true -- Show the line number in the gutter. +vim.opt.relativenumber = true -- Relative line number +vim.opt.shiftround = true -- Round indentation to shiftwidth +vim.opt.shiftwidth = 4 -- Number of spaces a tab counts for when converting tabs to spaces +vim.opt.shortmess = 'at' -- Abbreviations and truncation of cmd messages +vim.opt.showmatch = true -- Show matching bracket +vim.opt.signcolumn = 'yes' -- Always show the gutter +vim.opt.smartindent = true -- Attempt to insert indentation to fit traditional languages. +vim.opt.softtabstop = 4 -- Number of spaces a tab counts for when converting tabs to spaces +vim.opt.splitbelow = true -- Split windows below when horizontal splitting +vim.opt.splitright = true -- Split windows right when vertical splitting +vim.opt.swapfile = false -- Disable the creation of swap files for open files +vim.opt.tabstop = 4 -- Setting the value of spaces per tab +vim.opt.termguicolors = true -- Enable the truecolor GUI colors in a terminal +vim.opt.undodir = os.getenv('HOME') .. '/.config/nvim/undodir' -- Set a specific undo file directory +vim.opt.undofile = true -- Enable undo files +vim.opt.updatetime = 50 -- Update time in milliseconds +vim.opt.wrap = false -- Do _not_ wrap lines