From 3f08a95c7bdcd356aeed7228f8d064083c02ade6 Mon Sep 17 00:00:00 2001 From: Norm Rasmussen Date: Thu, 8 Sep 2022 12:21:50 -0400 Subject: [PATCH] new plugins & organization --- lua/plugins/cheatsheet.lua | 30 - lua/plugins/indent-blankline.lua | 49 +- ...-lsp-installer.lua => mason-lspconfig.lua} | 4 +- lua/plugins/neoscroll.lua | 31 +- lua/plugins/nvim-cmp.lua | 39 +- lua/plugins/nvim-lspconfig.lua | 91 ++- lua/plugins/nvim-treesitter.lua | 26 +- lua/plugins/plugins.lua | 181 +++--- lua/plugins/prettier.lua | 1 + lua/plugins/snippets.lua | 533 ++++++++++++++++++ lua/plugins/vista.lua | 38 -- 11 files changed, 815 insertions(+), 208 deletions(-) delete mode 100644 lua/plugins/cheatsheet.lua rename lua/plugins/{nvim-lsp-installer.lua => mason-lspconfig.lua} (62%) create mode 100644 lua/plugins/snippets.lua delete mode 100644 lua/plugins/vista.lua diff --git a/lua/plugins/cheatsheet.lua b/lua/plugins/cheatsheet.lua deleted file mode 100644 index 24d2a61..0000000 --- a/lua/plugins/cheatsheet.lua +++ /dev/null @@ -1,30 +0,0 @@ -require("cheatsheet").setup({ - -- Whether to show bundled cheatsheets - - -- For generic cheatsheets like default, unicode, nerd-fonts, etc - -- bundled_cheatsheets = { - -- enabled = {}, - -- disabled = {}, - -- }, - bundled_cheatsheets = true, - - -- For plugin specific cheatsheets - -- bundled_plugin_cheatsheets = { - -- enabled = {}, - -- disabled = {}, - -- } - bundled_plugin_cheatsheets = true, - - -- For bundled plugin cheatsheets, do not show a sheet if you - -- don't have the plugin installed (searches runtimepath for - -- same directory name) - include_only_installed_plugins = true, - - -- Key mappings bound inside the telescope window - telescope_mappings = { - [''] = require('cheatsheet.telescope.actions').select_or_fill_commandline, - [''] = require('cheatsheet.telescope.actions').select_or_execute, - [''] = require('cheatsheet.telescope.actions').copy_cheat_value, - [''] = require('cheatsheet.telescope.actions').edit_user_cheatsheet, - } -}) diff --git a/lua/plugins/indent-blankline.lua b/lua/plugins/indent-blankline.lua index 8ed0c97..edbd6c0 100644 --- a/lua/plugins/indent-blankline.lua +++ b/lua/plugins/indent-blankline.lua @@ -5,21 +5,38 @@ -- Plugin: indent-blankline -- url: https://github.com/lukas-reineke/indent-blankline.nvim +vim.opt.termguicolors = true +vim.cmd [[highlight IndentBlanklineIndent1 guifg=#E06C75 gui=nocombine]] +vim.cmd [[highlight IndentBlanklineIndent2 guifg=#E5C07B gui=nocombine]] +vim.cmd [[highlight IndentBlanklineIndent3 guifg=#98C379 gui=nocombine]] +vim.cmd [[highlight IndentBlanklineIndent4 guifg=#56B6C2 gui=nocombine]] +vim.cmd [[highlight IndentBlanklineIndent5 guifg=#61AFEF gui=nocombine]] +vim.cmd [[highlight IndentBlanklineIndent6 guifg=#C678DD gui=nocombine]] -require('indent_blankline').setup { - char = "▏", - show_first_indent_level = false, - filetype_exclude = { - 'help', - 'git', - 'markdown', - 'text', - 'terminal', - 'lspinfo', - 'packer', - }, - buftype_exclude = { - 'terminal', - 'nofile', - }, +vim.opt.list = true +vim.opt.listchars:append "space:⋅" +vim.opt.listchars:append "eol: " + +require("indent_blankline").setup { + space_char_blankline = " ", + char_highlight_list = { + "IndentBlanklineIndent1", + "IndentBlanklineIndent2", + "IndentBlanklineIndent3", + "IndentBlanklineIndent4", + "IndentBlanklineIndent5", + "IndentBlanklineIndent6", + }, } +--[[ + +vim.opt.list = true +vim.opt.listchars:append "space:⋅" +vim.opt.listchars:append "eol:↴" + +require("indent_blankline").setup { + space_char_blankline = " ", + show_current_context = true, + show_current_context_start = true, +} +--]] diff --git a/lua/plugins/nvim-lsp-installer.lua b/lua/plugins/mason-lspconfig.lua similarity index 62% rename from lua/plugins/nvim-lsp-installer.lua rename to lua/plugins/mason-lspconfig.lua index 2ad64ff..0118611 100644 --- a/lua/plugins/nvim-lsp-installer.lua +++ b/lua/plugins/mason-lspconfig.lua @@ -1,5 +1,5 @@ -local lsp_installer = require("nvim-lsp-installer").setup({ - automatic_installation = true, +local lsp_installer = require("mason-lspconfig").setup({ + automatic_instalsation = true, ui = { icons = { server_installed = "✓", diff --git a/lua/plugins/neoscroll.lua b/lua/plugins/neoscroll.lua index da5e293..67a1f52 100644 --- a/lua/plugins/neoscroll.lua +++ b/lua/plugins/neoscroll.lua @@ -1,14 +1,17 @@ -require('neoscroll').setup({ - -- All these keys will be mapped to their corresponding default scrolling animation - mappings = {'', '', '', '', - '', '', 'zt', 'zz', 'zb'}, - hide_cursor = true, -- Hide cursor while scrolling - stop_eof = true, -- Stop at when scrolling downwards - use_local_scrolloff = false, -- Use the local scope of scrolloff instead of the global scope - respect_scrolloff = false, -- Stop scrolling when the cursor reaches the scrolloff margin of the file - cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further - easing_function = nil, -- Default easing function - pre_hook = nil, -- Function to run before the scrolling animation starts - post_hook = nil, -- Function to run after the scrolling animation ends - performance_mode = false, -- Disable "Performance Mode" on all buffers. - }) +local t = {} +-- Syntax: t[keys] = {function, {function arguments}} +-- Use the "sine" easing function +t[""] = { "scroll", { "-vim.wo.scroll", "true", "20", [['cubic']] } } +t[""] = { "scroll", { "vim.wo.scroll", "true", "20", [['cubic']] } } +-- Use the "circular" easing function +t[""] = { "scroll", { "-vim.api.nvim_win_get_height(0)", "true", "50", [['cubic']] } } +t[""] = { "scroll", { "vim.api.nvim_win_get_height(0)", "true", "50", [['cubic']] } } +-- Pass "nil" to disable the easing animation (constant scrolling speed) +t[""] = { "scroll", { "-0.10", "false", "100", nil } } +t[""] = { "scroll", { "0.10", "false", "100", nil } } +-- When no easing function is provided the default easing function (in this case "quadratic") will be used +t["zt"] = { "zt", { "10" } } +t["zz"] = { "zz", { "10" } } +t["zb"] = { "zb", { "10" } } + +require("neoscroll.config").set_mappings(t) diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua index 5bf468f..7a7ea4a 100644 --- a/lua/plugins/nvim-cmp.lua +++ b/lua/plugins/nvim-cmp.lua @@ -3,7 +3,8 @@ ----------------------------------------------------------- -- Plugin: nvim-cmp --- url: https://github.com/hrsh7th/nvim-cmpa +-- url: https://github.com/hrsh7th/nvim-cmp + local cmp_status_ok, cmp = pcall(require, 'cmp') if not cmp_status_ok then @@ -23,7 +24,7 @@ cmp.setup { end, }, --- Completion settings + -- Completion settings completion = { --completeopt = 'menu,menuone,noselect' keyword_length = 2 @@ -35,7 +36,7 @@ cmp.setup { [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), + [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, @@ -43,7 +44,7 @@ cmp.setup { }, -- Tab mapping - ['g'] = function(fallback) + [''] = function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_jumpable() then @@ -52,7 +53,7 @@ cmp.setup { fallback() end end, - ['h'] = function(fallback) + [''] = function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.jumpable(-1) then @@ -65,10 +66,36 @@ cmp.setup { -- Load sources, see: https://github.com/topics/nvim-cmp sources = { - { name = 'nvim_lsp' }, + { name = 'nvim-lsp' }, { name = 'luasnip' }, + { name = 'cmdline'}, { name = 'path' }, { name = 'buffer' }, + { name = 'zsh' }, }, } + + +-- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu +vim.cmd[[ + highlight! link CmpItemMenu Comment + " gray + highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080 + " blue + highlight! CmpItemAbbrMatch guibg=NONE guifg=#569CD6 + highlight! CmpItemAbbrMatchFuzzy guibg=NONE guifg=#569CD6 + " light blue + highlight! CmpItemKindVariable guibg=NONE guifg=#9CDCFE + highlight! CmpItemKindInterface guibg=NONE guifg=#9CDCFE + highlight! CmpItemKindText guibg=NONE guifg=#9CDCFE + " pink + highlight! CmpItemKindFunction guibg=NONE guifg=#C586C0 + highlight! CmpItemKindMethod guibg=NONE guifg=#C586C0 + " front + highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4 + highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4 + highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4 +]] + + diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua index f21f31a..92d8b5e 100644 --- a/lua/plugins/nvim-lspconfig.lua +++ b/lua/plugins/nvim-lspconfig.lua @@ -5,10 +5,42 @@ -- Plugin: nvim-lspconfig -- url: https://github.com/neovim/nvim-lspconfig -local nvim_lsp = require 'lspconfig' +-- For configuration see the Wiki: https://github.com/neovim/nvim-lspconfig/wiki +-- Autocompletion settings of "nvim-cmp" are defined in plugins/nvim-cmp.lua + +local lsp_status_ok, lspconfig = pcall(require, 'lspconfig') +if not lsp_status_ok then + return +end + +local cmp_status_ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp') +if not cmp_status_ok then + return +end + +-- Diagnostic options, see: `:help vim.diagnostic.config` +vim.diagnostic.config({ + update_in_insert = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, +}) + +-- Show line diagnostics automatically in hover window +vim.cmd([[ + autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, { focus = false }) +]]) -- Add additional capabilities supported by nvim-cmp +-- See: https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + capabilities.textDocument.completion.completionItem.documentationFormat = { 'markdown', 'plaintext' } capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.preselectSupport = true @@ -31,11 +63,22 @@ local on_attach = function(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- Highlighting references + if client.resolved_capabilities.document_highlight then + vim.api.nvim_exec([[ + augroup lsp_document_highlight + autocmd! * + autocmd CursorHold lua vim.lsp.buf.document_highlight() + autocmd CursorMoved lua vim.lsp.buf.clear_references() + augroup END + ]], false) + end + -- Enable completion triggered by buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. - local opts = { noremap=true, silent=true } + local opts = { noremap = true, silent = true } -- See `:help vim.lsp.*` for documentation on any of the below functions buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) @@ -55,27 +98,45 @@ local on_attach = function(client, bufnr) buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) - end + +--[[ + +Language servers setup: + +For language servers list see: +https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + +Language server installed: + +Bash -> bashls +Python -> pyright +C-C++ -> clangd +HTML/CSS/JSON -> vscode-html-languageserver +JavaScript/TypeScript -> tsserver + +--]] + +-- Define `root_dir` when needed +-- See: https://github.com/neovim/nvim-lspconfig/issues/320 +-- This is a workaround, maybe not work with some servers. +local root_dir = function() + return vim.fn.getcwd() +end + -- Use a loop to conveniently call 'setup' on multiple servers and --- map buffer local keybindings when the language server attaches -local servers = { 'bashls', 'pyright', 'pylsp', 'clangd', 'html', 'tsserver', 'marksman', 'prosemd_lsp', 'dockerls', 'cssls', 'cssmodules_ls', 'arduino_language_server', 'pyre', 'gopls', 'theme_check' } - --- Set settings for language servers: - --- tsserver settings -local ts_settings = function(client) - client.resolved_capabilities.document_formatting = false - ts_settings(client) -end +-- map buffer local keybindings when the language server attaches. +-- Add your language server below: +local servers = { 'bashls', 'pyright', 'clangd', 'html', 'cssls', 'tsserver' } -- Call setup for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup { + lspconfig[lsp].setup { on_attach = on_attach, + root_dir = root_dir, capabilities = capabilities, - ts_settings = ts_settings, flags = { + -- default in neovim 0.7+ debounce_text_changes = 150, } } diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua index acfbf05..8dc5a19 100644 --- a/lua/plugins/nvim-treesitter.lua +++ b/lua/plugins/nvim-treesitter.lua @@ -1,23 +1,27 @@ - - ----------------------------------------------------------- -- Treesitter configuration file ---------------------------------------------------------- -- Plugin: nvim-treesitter -- url: https://github.com/nvim-treesitter/nvim-treesitter -local parser_configs = require("nvim-treesitter.parsers").get_parser_configs() -parser_configs.markdown = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-markdown", - files = { "src/parser.c", "src/scanner.cc" }, + +local status_ok, nvim_treesitter = pcall(require, 'nvim-treesitter.configs') +if not status_ok then + return +end + +-- See: https://github.com/nvim-treesitter/nvim-treesitter#quickstart +nvim_treesitter.setup { + -- A list of parser names, or "all" + ensure_installed = { + 'bash', 'css', 'html', 'javascript', 'json', 'lua', 'python', + 'vim', 'yaml', }, - filetype = "markdown", -} - -require('nvim-treesitter.configs').setup { + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, highlight = { + -- `false` will disable the whole extension enable = true, }, } diff --git a/lua/plugins/plugins.lua b/lua/plugins/plugins.lua index 884bdeb..6baa770 100755 --- a/lua/plugins/plugins.lua +++ b/lua/plugins/plugins.lua @@ -8,8 +8,93 @@ return require'packer'.startup(function() -- Wakatime Tracking use 'wakatime/vim-wakatime' +---------------------------------------------------------------- +-- LSP and Autocomplete Plugins +-- They should be pulled first! +----------------------------------------------------------------- + + -- Easy Way to install Language Servers + use 'williamboman/mason.nvim' + use 'williamboman/mason-lspconfig.nvim' + + -- Neovim Autocomplete with LSP + use { + 'hrsh7th/nvim-cmp', + requires = { + 'neovim/nvim-lspconfig', + 'L3MON4D3/LuaSnip', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-cmdline', + 'hrsh7th/nvim-cmp', + 'saadparwaiz1/cmp_luasnip', + } + } + + use { + 'L3MON4D3/LuaSnip', + requires = { + 'saadparwaiz1/cmp_luasnip' + } + } + + -- Treesitter interface + use { + 'nvim-treesitter/nvim-treesitter', + --run = function() require('nvim-treesitter.install').update({ with_sync = true }) end, + } + + -- Null-LS + use'jose-elias-alvarez/null-ls.nvim' + +------------------------------------------------------------ +-- General Functionality +------------------------------------------------------------ + + -- Find & Search LSP Tags + use 'liuchengxu/vista.vim' + -- Snippets + use 'rafamadriz/friendly-snippets' + + -- Rename and Work with Buffer & Tabs + use 'pacha/vem-tabline' + -- Nvim Tree File Manager on the Left use 'kyazdani42/nvim-tree.lua' + + -- Trouble Shows Errors with Files. + use { + "folke/trouble.nvim", + requires = "kyazdani42/nvim-web-devicons", + config = function() + require("trouble").setup { + } + end +} + + use { + 'windwp/nvim-autopairs', + config = function() + require('nvim-autopairs').setup() + end + } + + use 'rcarriga/nvim-notify' + + use { + 'phaazon/mind.nvim', + branch = 'v2.2', + requires = { 'nvim-lua/plenary.nvim' }, + config = function() + require'mind'.setup() + end +} + +----------------------------------------------------------- +-- Markdown Plugins +------------------------------------------------------------ + use({ 'jakewvincent/mkdnflow.nvim', config = function() @@ -32,36 +117,21 @@ return require'packer'.startup(function() -- Follow MD Links use 'jghauser/follow-md-links.nvim' - -- Glow, a Markdown Preview plugin - use {"ellisonleao/glow.nvim", branch = 'main'} - - -- Treesitter Language Stuff - use 'nvim-treesitter/nvim-treesitter' - -- Rename and Work with Buffer & Tabs - use 'pacha/vem-tabline' - - -- Null-LS - use'jose-elias-alvarez/null-ls.nvim' - - -- Prettier Plugin for Neovim specifically - use'MunifTanjim/prettier.nvim' - -- Markdown Preview use({ "iamcco/markdown-preview.nvim", run = function() vim.fn["mkdp#util#install"]() end, }) + + use 'chentoast/marks.nvim' - -- Trouble Shows Errors with Files. - use { - "folke/trouble.nvim", - requires = "kyazdani42/nvim-web-devicons", - config = function() - require("trouble").setup { - } - end -} + -- Prettier Plugin for Neovim specifically + -- use'MunifTanjim/prettier.nvim' + +--------------------------------------------------------- +-- Text, Icons, Symbols +---------------------------------------------------------- use 'lukas-reineke/indent-blankline.nvim' @@ -69,17 +139,23 @@ return require'packer'.startup(function() use 'kyazdani42/nvim-web-devicons' - use 'liuchengxu/vista.vim' - use 'karb94/neoscroll.nvim' - use 'nvim-lua/plenary.nvim' - -- Allow Popups for Telescope etc - use 'nvim-lua/popup.nvim' + --use 'nvim-lua/popup.nvim' + + -- Todo & Comments for Organization + use { + "folke/todo-comments.nvim", + requires = "nvim-lua/plenary.nvim", + config = function() + require("todo-comments").setup { + } + end +} ----------------------------------------------------------- --- Various Color Schemes +-- Various Color Schemes, Dashboard, etc ----------------------------------------------------------- use 'tjdevries/colorbuddy.nvim' use 'bkegley/gloombuddy' @@ -89,24 +165,6 @@ return require'packer'.startup(function() use { 'rose-pine/neovim', as = 'rose-pine' } use 'folke/tokyonight.nvim' - -- Easy Way to install Language Servers - use 'williamboman/nvim-lsp-installer' - - -- Config for Language Servers - use 'neovim/nvim-lspconfig' - - -- Navigate Tmux and Vim! - use 'christoomey/vim-tmux-navigator' - - -- Easy Access to Vim keymappings - use { - 'sudormrfbin/cheatsheet.nvim', - requires = { - --{'nvim-telescope/telescope.nvim'}, - {'nvim-lua/popup.nvim'}, - {'nvim-lua/plenary.nvim'}, - } -} use { 'feline-nvim/feline.nvim', requires = { 'kyazdani42/nvim-web-devicons' }, @@ -123,33 +181,4 @@ return require'packer'.startup(function() 'goolord/alpha-nvim', requires = { 'kyazdani42/nvim-web-devicons' }, } - - use { - 'windwp/nvim-autopairs', - config = function() - require('nvim-autopairs').setup() - end - } - use { - 'hrsh7th/nvim-cmp', - requires = { - 'L3MON4D3/LuaSnip', - 'hrsh7th/cmp-nvim-lsp', - 'quangnguyen30192/cmp-nvim-ultisnips', - 'hrsh7th/cmp-calc', - 'f3fora/cmp-spell', - 'hrsh7th/cmp-emoji', - 'hrsh7th/cmp-look', - 'hrsh7th/cmp-path', - 'hrsh7th/cmp-buffer', - 'saadparwaiz1/cmp_luasnip', - } - } - use { - 'tzachar/cmp-tabnine', - run = './install.sh', - requires = 'hrsh7th/nvim-cmp' - } - use 'chentoast/marks.nvim' - end) diff --git a/lua/plugins/prettier.lua b/lua/plugins/prettier.lua index 3193925..817da0c 100644 --- a/lua/plugins/prettier.lua +++ b/lua/plugins/prettier.lua @@ -15,6 +15,7 @@ prettier.setup({ "typescript", "typescriptreact", "yaml", + "python", }, -- prettier format options (you can use config files too. ex: `.prettierrc`) diff --git a/lua/plugins/snippets.lua b/lua/plugins/snippets.lua new file mode 100644 index 0000000..937535a --- /dev/null +++ b/lua/plugins/snippets.lua @@ -0,0 +1,533 @@ +local ls = require("luasnip") +-- some shorthands... +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local l = require("luasnip.extras").lambda +local rep = require("luasnip.extras").rep +local p = require("luasnip.extras").partial +local m = require("luasnip.extras").match +local n = require("luasnip.extras").nonempty +local dl = require("luasnip.extras").dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local types = require("luasnip.util.types") +local conds = require("luasnip.extras.expand_conditions") + +-- If you're reading this file for the first time, best skip to around line 190 +-- where the actual snippet-definitions start. + +-- Every unspecified option will be set to the default. +ls.setup({ + history = true, + -- Update more often, :h events for more info. + update_events = "TextChanged,TextChangedI", + -- Snippets aren't automatically removed if their text is deleted. + -- `delete_check_events` determines on which events (:h events) a check for + -- deleted snippets is performed. + -- This can be especially useful when `history` is enabled. + delete_check_events = "TextChanged", + ext_opts = { + [types.choiceNode] = { + active = { + virt_text = { { "choiceNode", "Comment" } }, + }, + }, + }, + -- treesitter-hl has 100, use something higher (default is 200). + ext_base_prio = 300, + -- minimal increase in priority. + ext_prio_increase = 1, + enable_autosnippets = true, + -- mapping for cutting selected text so it's usable as SELECT_DEDENT, + -- SELECT_RAW or TM_SELECTED_TEXT (mapped via xmap). + store_selection_keys = "", + -- luasnip uses this function to get the currently active filetype. This + -- is the (rather uninteresting) default, but it's possible to use + -- eg. treesitter for getting the current filetype by setting ft_func to + -- require("luasnip.extras.filetype_functions").from_cursor (requires + -- `nvim-treesitter/nvim-treesitter`). This allows correctly resolving + -- the current filetype in eg. a markdown-code block or `vim.cmd()`. + ft_func = function() + return vim.split(vim.bo.filetype, ".", true) + end, +}) + +-- args is a table, where 1 is the text in Placeholder 1, 2 the text in +-- placeholder 2,... +local function copy(args) + return args[1] +end + +-- 'recursive' dynamic snippet. Expands to some text followed by itself. +local rec_ls +rec_ls = function() + return sn( + nil, + c(1, { + -- Order is important, sn(...) first would cause infinite loop of expansion. + t(""), + sn(nil, { t({ "", "\t\\item " }), i(1), d(2, rec_ls, {}) }), + }) + ) +end + +-- complicated function for dynamicNode. +local function jdocsnip(args, _, old_state) + -- !!! old_state is used to preserve user-input here. DON'T DO IT THAT WAY! + -- Using a restoreNode instead is much easier. + -- View this only as an example on how old_state functions. + local nodes = { + t({ "/**", " * " }), + i(1, "A short Description"), + t({ "", "" }), + } + + -- These will be merged with the snippet; that way, should the snippet be updated, + -- some user input eg. text can be referred to in the new snippet. + local param_nodes = {} + + if old_state then + nodes[2] = i(1, old_state.descr:get_text()) + end + param_nodes.descr = nodes[2] + + -- At least one param. + if string.find(args[2][1], ", ") then + vim.list_extend(nodes, { t({ " * ", "" }) }) + end + + local insert = 2 + for indx, arg in ipairs(vim.split(args[2][1], ", ", true)) do + -- Get actual name parameter. + arg = vim.split(arg, " ", true)[2] + if arg then + local inode + -- if there was some text in this parameter, use it as static_text for this new snippet. + if old_state and old_state[arg] then + inode = i(insert, old_state["arg" .. arg]:get_text()) + else + inode = i(insert) + end + vim.list_extend( + nodes, + { t({ " * @param " .. arg .. " " }), inode, t({ "", "" }) } + ) + param_nodes["arg" .. arg] = inode + + insert = insert + 1 + end + end + + if args[1][1] ~= "void" then + local inode + if old_state and old_state.ret then + inode = i(insert, old_state.ret:get_text()) + else + inode = i(insert) + end + + vim.list_extend( + nodes, + { t({ " * ", " * @return " }), inode, t({ "", "" }) } + ) + param_nodes.ret = inode + insert = insert + 1 + end + + if vim.tbl_count(args[3]) ~= 1 then + local exc = string.gsub(args[3][2], " throws ", "") + local ins + if old_state and old_state.ex then + ins = i(insert, old_state.ex:get_text()) + else + ins = i(insert) + end + vim.list_extend( + nodes, + { t({ " * ", " * @throws " .. exc .. " " }), ins, t({ "", "" }) } + ) + param_nodes.ex = ins + insert = insert + 1 + end + + vim.list_extend(nodes, { t({ " */" }) }) + + local snip = sn(nil, nodes) + -- Error on attempting overwrite. + snip.old_state = param_nodes + return snip +end + +-- Make sure to not pass an invalid command, as io.popen() may write over nvim-text. +local function bash(_, _, command) + local file = io.popen(command, "r") + local res = {} + for line in file:lines() do + table.insert(res, line) + end + return res +end + +-- Returns a snippet_node wrapped around an insert_node whose initial +-- text value is set to the current date in the desired format. +local date_input = function(args, snip, old_state, fmt) + local fmt = fmt or "%Y-%m-%d" + return sn(nil, i(1, os.date(fmt))) +end + +-- snippets are added via ls.add_snippets(filetype, snippets[, opts]), where +-- opts may specify the `type` of the snippets ("snippets" or "autosnippets", +-- for snippets that should expand directly after the trigger is typed). +-- +-- opts can also specify a key. By passing an unique key to each add_snippets, it's possible to reload snippets by +-- re-`:luafile`ing the file in which they are defined (eg. this one). +ls.add_snippets("all", { + -- trigger is `fn`, second argument to snippet-constructor are the nodes to insert into the buffer on expansion. + s("fn", { + -- Simple static text. + t("//Parameters: "), + -- function, first parameter is the function, second the Placeholders + -- whose text it gets as input. + f(copy, 2), + t({ "", "function " }), + -- Placeholder/Insert. + i(1), + t("("), + -- Placeholder with initial text. + i(2, "int foo"), + -- Linebreak + t({ ") {", "\t" }), + -- Last Placeholder, exit Point of the snippet. + i(0), + t({ "", "}" }), + }), + s("class", { + -- Choice: Switch between two different Nodes, first parameter is its position, second a list of nodes. + c(1, { + t("public "), + t("private "), + }), + t("class "), + i(2), + t(" "), + c(3, { + t("{"), + -- sn: Nested Snippet. Instead of a trigger, it has a position, just like insert-nodes. !!! These don't expect a 0-node!!!! + -- Inside Choices, Nodes don't need a position as the choice node is the one being jumped to. + sn(nil, { + t("extends "), + -- restoreNode: stores and restores nodes. + -- pass position, store-key and nodes. + r(1, "other_class", i(1)), + t(" {"), + }), + sn(nil, { + t("implements "), + -- no need to define the nodes for a given key a second time. + r(1, "other_class"), + t(" {"), + }), + }), + t({ "", "\t" }), + i(0), + t({ "", "}" }), + }), + -- Alternative printf-like notation for defining snippets. It uses format + -- string with placeholders similar to the ones used with Python's .format(). + s( + "fmt1", + fmt("To {title} {} {}.", { + i(2, "Name"), + i(3, "Surname"), + title = c(1, { t("Mr."), t("Ms.") }), + }) + ), + -- To escape delimiters use double them, e.g. `{}` -> `{{}}`. + -- Multi-line format strings by default have empty first/last line removed. + -- Indent common to all lines is also removed. Use the third `opts` argument + -- to control this behaviour. + s( + "fmt2", + fmt( + [[ + foo({1}, {3}) {{ + return {2} * {4} + }} + ]], + { + i(1, "x"), + rep(1), + i(2, "y"), + rep(2), + } + ) + ), + -- Empty placeholders are numbered automatically starting from 1 or the last + -- value of a numbered placeholder. Named placeholders do not affect numbering. + s( + "fmt3", + fmt("{} {a} {} {1} {}", { + t("1"), + t("2"), + a = t("A"), + }) + ), + -- The delimiters can be changed from the default `{}` to something else. + s("fmt4", fmt("foo() { return []; }", i(1, "x"), { delimiters = "[]" })), + -- `fmta` is a convenient wrapper that uses `<>` instead of `{}`. + s("fmt5", fmta("foo() { return <>; }", i(1, "x"))), + -- By default all args must be used. Use strict=false to disable the check + s( + "fmt6", + fmt("use {} only", { t("this"), t("not this") }, { strict = false }) + ), + -- Use a dynamic_node to interpolate the output of a + -- function (see date_input above) into the initial + -- value of an insert_node. + s("novel", { + t("It was a dark and stormy night on "), + d(1, date_input, {}, { user_args = { "%A, %B %d of %Y" } }), + t(" and the clocks were striking thirteen."), + }), + -- Parsing snippets: First parameter: Snippet-Trigger, Second: Snippet body. + -- Placeholders are parsed into choices with 1. the placeholder text(as a snippet) and 2. an empty string. + -- This means they are not SELECTed like in other editors/Snippet engines. + ls.parser.parse_snippet( + "lspsyn", + "Wow! This ${1:Stuff} really ${2:works. ${3:Well, a bit.}}" + ), + + -- When wordTrig is set to false, snippets may also expand inside other words. + ls.parser.parse_snippet( + { trig = "te", wordTrig = false }, + "${1:cond} ? ${2:true} : ${3:false}" + ), + + -- When regTrig is set, trig is treated like a pattern, this snippet will expand after any number. + ls.parser.parse_snippet({ trig = "%d", regTrig = true }, "A Number!!"), + -- Using the condition, it's possible to allow expansion only in specific cases. + s("cond", { + t("will only expand in c-style comments"), + }, { + condition = function(line_to_cursor, matched_trigger, captures) + -- optional whitespace followed by // + return line_to_cursor:match("%s*//") + end, + }), + -- there's some built-in conditions in "luasnip.extras.expand_conditions". + s("cond2", { + t("will only expand at the beginning of the line"), + }, { + condition = conds.line_begin, + }), + -- The last entry of args passed to the user-function is the surrounding snippet. + s( + { trig = "a%d", regTrig = true }, + f(function(_, snip) + return "Triggered with " .. snip.trigger .. "." + end, {}) + ), + -- It's possible to use capture-groups inside regex-triggers. + s( + { trig = "b(%d)", regTrig = true }, + f(function(_, snip) + return "Captured Text: " .. snip.captures[1] .. "." + end, {}) + ), + s({ trig = "c(%d+)", regTrig = true }, { + t("will only expand for even numbers"), + }, { + condition = function(line_to_cursor, matched_trigger, captures) + return tonumber(captures[1]) % 2 == 0 + end, + }), + -- Use a function to execute any shell command and print its text. + s("bash", f(bash, {}, { user_args = { "ls" } })), + -- Short version for applying String transformations using function nodes. + s("transform", { + i(1, "initial text"), + t({ "", "" }), + -- lambda nodes accept an l._1,2,3,4,5, which in turn accept any string transformations. + -- This list will be applied in order to the first node given in the second argument. + l(l._1:match("[^i]*$"):gsub("i", "o"):gsub(" ", "_"):upper(), 1), + }), + + s("transform2", { + i(1, "initial text"), + t("::"), + i(2, "replacement for e"), + t({ "", "" }), + -- Lambdas can also apply transforms USING the text of other nodes: + l(l._1:gsub("e", l._2), { 1, 2 }), + }), + s({ trig = "trafo(%d+)", regTrig = true }, { + -- env-variables and captures can also be used: + l(l.CAPTURE1:gsub("1", l.TM_FILENAME), {}), + }), + -- Set store_selection_keys = "" (for example) in your + -- luasnip.config.setup() call to populate + -- TM_SELECTED_TEXT/SELECT_RAW/SELECT_DEDENT. + -- In this case: select a URL, hit Tab, then expand this snippet. + s("link_url", { + t(''), + i(1), + t(""), + i(0), + }), + -- Shorthand for repeating the text in a given node. + s("repeat", { i(1, "text"), t({ "", "" }), rep(1) }), + -- Directly insert the ouput from a function evaluated at runtime. + s("part", p(os.date, "%Y")), + -- use matchNodes (`m(argnode, condition, then, else)`) to insert text + -- based on a pattern/function/lambda-evaluation. + -- It's basically a shortcut for simple functionNodes: + s("mat", { + i(1, { "sample_text" }), + t(": "), + m(1, "%d", "contains a number", "no number :("), + }), + -- The `then`-text defaults to the first capture group/the entire + -- match if there are none. + s("mat2", { + i(1, { "sample_text" }), + t(": "), + m(1, "[abc][abc][abc]"), + }), + -- It is even possible to apply gsubs' or other transformations + -- before matching. + s("mat3", { + i(1, { "sample_text" }), + t(": "), + m( + 1, + l._1:gsub("[123]", ""):match("%d"), + "contains a number that isn't 1, 2 or 3!" + ), + }), + -- `match` also accepts a function in place of the condition, which in + -- turn accepts the usual functionNode-args. + -- The condition is considered true if the function returns any + -- non-nil/false-value. + -- If that value is a string, it is used as the `if`-text if no if is explicitly given. + s("mat4", { + i(1, { "sample_text" }), + t(": "), + m(1, function(args) + -- args is a table of multiline-strings (as usual). + return (#args[1][1] % 2 == 0 and args[1]) or nil + end), + }), + -- The nonempty-node inserts text depending on whether the arg-node is + -- empty. + s("nempty", { + i(1, "sample_text"), + n(1, "i(1) is not empty!"), + }), + -- dynamic lambdas work exactly like regular lambdas, except that they + -- don't return a textNode, but a dynamicNode containing one insertNode. + -- This makes it easier to dynamically set preset-text for insertNodes. + s("dl1", { + i(1, "sample_text"), + t({ ":", "" }), + dl(2, l._1, 1), + }), + -- Obviously, it's also possible to apply transformations, just like lambdas. + s("dl2", { + i(1, "sample_text"), + i(2, "sample_text_2"), + t({ "", "" }), + dl(3, l._1:gsub("\n", " linebreak ") .. l._2, { 1, 2 }), + }), +}, { + key = "all", +}) + +ls.add_snippets("java", { + -- Very long example for a java class. + s("fn", { + d(6, jdocsnip, { 2, 4, 5 }), + t({ "", "" }), + c(1, { + t("public "), + t("private "), + }), + c(2, { + t("void"), + t("String"), + t("char"), + t("int"), + t("double"), + t("boolean"), + i(nil, ""), + }), + t(" "), + i(3, "myFunc"), + t("("), + i(4), + t(")"), + c(5, { + t(""), + sn(nil, { + t({ "", " throws " }), + i(1), + }), + }), + t({ " {", "\t" }), + i(0), + t({ "", "}" }), + }), +}, { + key = "java", +}) + +ls.add_snippets("tex", { + -- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many + -- \item as necessary by utilizing a choiceNode. + s("ls", { + t({ "\\begin{itemize}", "\t\\item " }), + i(1), + d(2, rec_ls, {}), + t({ "", "\\end{itemize}" }), + }), +}, { + key = "tex", +}) + +-- set type to "autosnippets" for adding autotriggered snippets. +ls.add_snippets("all", { + s("autotrigger", { + t("autosnippet"), + }), +}, { + type = "autosnippets", + key = "all_auto", +}) + +-- in a lua file: search lua-, then c-, then all-snippets. +ls.filetype_extend("lua", { "c" }) +-- in a cpp file: search c-snippets, then all-snippets only (no cpp-snippets!!). +ls.filetype_set("cpp", { "c" }) + +-- Beside defining your own snippets you can also load snippets from "vscode-like" packages +-- that expose snippets in json files, for example . + +require("luasnip.loaders.from_vscode").load({ include = { "python" } }) -- Load only python snippets + +-- The directories will have to be structured like eg. (include +-- a similar `package.json`) +--require("luasnip.loaders.from_vscode").load({ paths = { "./my-snippets" } }) -- Load snippets from my-snippets folder + +-- You can also use lazy loading so snippets are loaded on-demand, not all at once (may interfere with lazy-loading luasnip itself). +require("luasnip.loaders.from_vscode").lazy_load() -- You can pass { paths = "./my-snippets/"} as well diff --git a/lua/plugins/vista.lua b/lua/plugins/vista.lua deleted file mode 100644 index 75b604c..0000000 --- a/lua/plugins/vista.lua +++ /dev/null @@ -1,38 +0,0 @@ ----------------------------------------------------------- --- Vista (tagbar) configuration file ------------------------------------------------------------ - --- Plugin: vista.vim --- url: https://github.com/liuchengxu/vista.vim - - -local g = vim.g -local cmd = vim.cmd - --- How each level is indented and what to prepend. ---- This could make the display more compact or more spacious. ---- e.g., more compact: ["▸ ", ""] ---- Note: this option only works for the kind renderer, not the tree renderer -g.vista_icon_indent = '["╰─▸ ", "├─▸ "]' - --- Executive used when opening vista sidebar without specifying it. ---- See all the avaliable executives via `:echo g:vista#executives`. -g.vista_default_executive = 'ctags' - --- Ensure you have installed some decent font to show these pretty symbols, ---- then you can enable icon for the kind. -cmd [[let g:vista#renderer#enable_icon = 1]] -cmd [[let g:vista_enable_markdown_extension = 1]] - - --- Change some default icons ---- see: https://github.com/slavfox/Cozette/blob/master/img/charmap.txt -cmd [[ - let g:vista#renderer#icons = { - \ "function": "\u0192", - \ "variable": "\uf00d", - \ "prototype": "\uf013", - \ "macro": "\uf00b", - \ } -]] -