diff --git a/init.lua b/init.lua index 13727202e80..9143bd47d87 100644 --- a/init.lua +++ b/init.lua @@ -188,6 +188,7 @@ vim.diagnostic.config { } vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) +vim.diagnostic.config { virtual_text = false } -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which @@ -230,6 +231,17 @@ vim.api.nvim_create_autocmd('TextYankPost', { callback = function() vim.hl.on_yank() end, }) +vim.api.nvim_create_autocmd('BufWritePre', { + desc = 'Remove trailing whitespace on save', + group = vim.api.nvim_create_augroup('kickstart-trim-whitespace', { clear = true }), + pattern = '*', + callback = function() + local save_cursor = vim.fn.getpos(".") + vim.cmd([[%s/\s\+$//e]]) + vim.fn.setpos(".", save_cursor) + end, +}) + -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' @@ -253,22 +265,116 @@ rtp:prepend(lazypath) -- To update plugins you can run -- :Lazy update -- +local projectionist_config = function () + vim.cmd [[ + let g:projectionist_heuristics ={ + \ "spec/*.rb": { + \ "app/*.rb": { "alternate": "spec/{}_spec.rb", "type": "source"}, + \ "app/javascript/src/*.js": { "alternate": "spec/javascript/{}.test.js", "type": "source"}, + \ "app/javascript/src/*.jsx": { "alternate": "spec/javascript/{}.test.js", "type": "source"}, + \ "lib/*.rb": { "alternate": "spec/{}_spec.rb", "type": "source"}, + \ "spec/*_spec.rb": { "alternate": ["app/{}.rb","lib/{}.rb"], "type": "test"}, + \ "spec/javascript/*.test.js": { "alternate": ["app/javascript/src/{}.js", "app/javascript/src/{}.jsx"], "type": "test"}, + \ }, + \ "*_test.go": { + \ "*.go": { "alternate": "{}_test.go", "type": "test" }, + \ "*_test.go": { "alternate": "{}.go", "type": "source" }, + \ }, + \ "*.erb": { + \ "*.html.erb": { "alternate": "{}.text.erb", "type": "text" }, + \ "*.text.erb": { "alternate": "{}.html.erb", "type": "html" }, + \ } + \} +]] +end + -- NOTE: Here is where you install your plugins. require('lazy').setup({ - -- NOTE: Plugins can be added via a link or github org/name. To run setup automatically, use `opts = {}` - { 'NMAC427/guess-indent.nvim', opts = {} }, - - -- Alternatively, use `config = function() ... end` for full control over the configuration. - -- If you prefer to call `setup` explicitly, use: - -- { - -- 'lewis6991/gitsigns.nvim', - -- config = function() - -- require('gitsigns').setup({ - -- -- Your gitsigns configuration here - -- }) - -- end, - -- } + -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). -- + 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically + 'nvim-lua/plenary.nvim', + 'nvim-pack/nvim-spectre', + { + 'ruifm/gitlinker.nvim', + dependencies = 'nvim-lua/plenary.nvim', + event = 'VeryLazy', + opts = { mapping = 'gl' }, + }, + +{ + -- Map tools and actions based on the project + "tpope/vim-projectionist", + config = projectionist_config, + event = "VeryLazy", + }, + { + 'ruanyl/vim-gh-line', + }, + { + 'klen/nvim-test', + config = function() + -- NOTE: Plugins can also be added by using a table, + -- with the first argument being the link and the following + -- keys can be used to configure plugin behavior/loading/etc. + -- + -- Use `opts = {}` to force a plugin to be loaded. + -- + -- This is equivalent to: + -- require('Comment').setup({}) + require('nvim-test').setup { + run = true, -- run tests (using for debug) + commands_create = true, -- create commands (TestFile, TestLast, ...) + filename_modifier = ':.', -- modify filenames before tests run(:h filename-modifiers) + silent = false, -- less notifications + term = 'terminal', -- a terminal to run ("terminal"|"toggleterm") + termOpts = { + direction = 'vertical', -- terminal's direction ("horizontal"|"vertical"|"float") + width = 96, -- terminal's width (for vertical|float) + height = 24, -- terminal's height (for horizontal|float) + go_back = false, -- return focus to original window after executing + stopinsert = 'auto', -- exit from insert mode (true|false|"auto") + keep_one = true, -- keep only one terminal for testing + }, + runners = { -- setup tests runners + cs = 'nvim-test.runners.dotnet', + go = 'nvim-test.runners.go-test', + haskell = 'nvim-test.runners.hspec', + javascriptreact = 'nvim-test.runners.jest', + javascript = 'nvim-test.runners.jest', + lua = 'nvim-test.runners.busted', + python = 'nvim-test.runners.pytest', + ruby = 'nvim-test.runners.rspec', + rust = 'nvim-test.runners.cargo-test', + typescript = 'nvim-test.runners.jest', + typescriptreact = 'nvim-test.runners.jest', + }, + + require('nvim-test.runners.jest'):setup { + command = '~/node_modules/.bin/jest', -- a command to run the test runner + args = { '--collectCoverage=false' }, -- default arguments + env = { CUSTOM_VAR = 'value' }, -- custom environment variables + + file_pattern = '\\v(__tests__/.*|(spec|test))\\.(js|jsx|coffee|ts|tsx)$', -- determine whether a file is a testfile + find_files = { '{name}.test.{ext}', '{name}.spec.{ext}' }, -- find testfile for a file + + filename_modifier = ':.', -- modify filename before tests run (:h filename-modifiers) + working_directory = nil, -- set working directory (cwd by default) + }, + require('nvim-test.runners.rspec'):setup { + command = 'bundle', + }, + } + end, + }, + -- "gc" to comment visual regions/lines + { 'numToStr/Comment.nvim', opts = {} }, + { + 'stevearc/oil.nvim', + opts = {}, + -- Optional dependencies + dependencies = { 'nvim-tree/nvim-web-devicons' }, + }, -- Here is a more advanced example where we pass configuration -- options to `gitsigns.nvim`. -- @@ -315,13 +421,22 @@ require('lazy').setup({ icons = { mappings = vim.g.have_nerd_font }, -- Document existing key chains - spec = { - { 's', group = '[S]earch', mode = { 'n', 'v' } }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first - { 'gr', group = 'LSP Actions', mode = { 'n' } }, - }, - }, + require('which-key').register { + ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + -- ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + ['t'] = { 'TestFile', 'TestFile' }, + ['T'] = { 'TestNearest', 'TestNearest' }, + } + -- visual mode + require('which-key').register({ + ['h'] = { 'Git [H]unk' }, + }, { mode = 'v' }) + end, }, -- NOTE: Plugins can specify dependencies. @@ -358,7 +473,12 @@ require('lazy').setup({ cond = function() return vim.fn.executable 'make' == 1 end, }, { 'nvim-telescope/telescope-ui-select.nvim' }, - + { + "nvim-telescope/telescope-live-grep-args.nvim" , + -- This will not install any breaking changes. + -- For major updates, this must be adjusted manually. + version = "^1.0.0", + }, -- Useful for getting pretty icons, but requires a Nerd Font. { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, @@ -402,20 +522,34 @@ require('lazy').setup({ -- Enable Telescope extensions if they are installed pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'ui-select') + pcall(require('telescope').load_extension "live_grep_args") -- See `:help telescope.builtin` local builtin = require 'telescope.builtin' vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', 'f', builtin.find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set({ 'n', 'v' }, 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'gd', builtin.grep_string, { desc = '[G] to [D]efinition' }) + vim.keymap.set('n', 'F', builtin.live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', 'sc', builtin.commands, { desc = '[S]earch [C]ommands' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', 'S', 'lua require("spectre").toggle()', { + desc = "Toggle Spectre" + }) + vim.keymap.set('n', 'sw', 'lua require("spectre").open_visual({select_word=true})', { + desc = "Search current word" + }) + vim.keymap.set('v', 'sw', 'lua require("spectre").open_visual()', { + desc = "Search current word" + }) + vim.keymap.set('n', 'sp', 'lua require("spectre").open_file_search({select_word=true})', { + desc = "Search on current file" + }) -- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, -- it is better explained there). This allows easily switching between pickers if you prefer using something else! @@ -595,6 +729,41 @@ require('lazy').setup({ end, }) + local hardmode = true + if hardmode then + -- Show an error message if a disabled key is pressed + local msg = [[echohl Error | echo "KEY DISABLED" | echohl None]] + + -- Disable arrow keys in insert mode with a styled message + vim.api.nvim_set_keymap('i', '', '' .. msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('i', '', '' .. msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('i', '', '' .. msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('i', '', '' .. msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('i', '', '' .. msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('i', '', '' .. msg, { noremap = true, silent = false }) + + -- Disable arrow keys in normal mode with a styled message + vim.api.nvim_set_keymap('n', '', msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('n', '', msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('n', '', msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('n', '', msg, { noremap = true, silent = false }) + vim.api.nvim_set_keymap('n', '', msg, { noremap = true, silent = false }) + end + vim.api.nvim_create_autocmd('LspDetach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), + callback = function(event) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event.buf } + end, + }) + + -- LSP servers and clients are able to communicate to each other what features they support. + -- By default, Neovim doesn't support everything that is in the LSP specification. + -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities. + -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers. + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) + -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- See `:help lsp-config` for information about keys and how to configure @@ -602,6 +771,7 @@ require('lazy').setup({ local servers = { -- clangd = {}, -- gopls = {}, + solargraph = {}, -- pyright = {}, -- rust_analyzer = {}, -- @@ -609,9 +779,8 @@ require('lazy').setup({ -- https://github.com/pmizio/typescript-tools.nvim -- -- But for many setups, the LSP (`ts_ls`) will work just fine - -- ts_ls = {}, - - stylua = {}, -- Used to format Lua code + ts_ls = {}, + -- -- Special Lua Config, as recommended by neovim help docs lua_ls = { @@ -662,10 +831,18 @@ require('lazy').setup({ require('mason-tool-installer').setup { ensure_installed = ensure_installed } - for name, server in pairs(servers) do - vim.lsp.config(name, server) - vim.lsp.enable(name) - end + 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 ts_ls) + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + require('lspconfig')[server_name].setup(server) + end, + }, + } end, }, @@ -686,16 +863,10 @@ require('lazy').setup({ opts = { notify_on_error = false, format_on_save = function(bufnr) - -- You can specify filetypes to autoformat on save here: - local enabled_filetypes = { - -- lua = true, - -- python = true, - } - if enabled_filetypes[vim.bo[bufnr].filetype] then - return { timeout_ms = 500 } - else - return nil - end + -- 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. + return end, default_format_opts = { lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely. @@ -948,9 +1119,9 @@ require('lazy').setup({ -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.indent_line', -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', + require 'kickstart.plugins.autopairs', -- require 'kickstart.plugins.neo-tree', -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommended keymaps diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index b3ddcfdd3aa..b57ed97b225 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -1,4 +1,44 @@ --- You can add your own plugins here or in other files in this directory! +-local vim = vim +local Plug = vim.fn['plug#'] + +vim.call('plug#begin') + +-- Shorthand notation for GitHub; translates to https://github.com/junegunn/vim-easy-align +Plug('junegunn/vim-easy-align') + +-- Any valid git URL is allowed +Plug('https://github.com/junegunn/seoul256.vim.git') + +-- Using a tagged release; wildcard allowed (requires git 1.9.2 or above) +Plug('fatih/vim-go', { ['tag'] = '*' }) + +-- Using a non-default branch +Plug('neoclide/coc.nvim', { ['branch'] = 'release' }) + +-- Use 'dir' option to install plugin in a non-default directory +Plug('junegunn/fzf', { ['dir'] = '~/.fzf' }) + +-- Post-update hook: run a shell command after installing or updating the plugin +Plug('junegunn/fzf', { ['dir'] = '~/.fzf', ['do'] = './install --all' }) + +-- Post-update hook can be a lambda expression +Plug('junegunn/fzf', { ['do'] = function() + vim.fn['fzf#install']() +end }) + +-- If the vim plugin is in a subdirectory, use 'rtp' option to specify its path +Plug('nsf/gocode', { ['rtp'] = 'vim' }) + +-- On-demand loading: loaded when the specified command is executed +Plug('preservim/nerdtree', { ['on'] = 'NERDTreeToggle' }) + +-- On-demand loading: loaded when a file with a specific file type is opened +Plug('tpope/vim-fireplace', { ['for'] = 'clojure' }) + +-- Unmanaged plugin (manually installed and updated) +Plug('~/my-prototype-plugin') + +vim.call('plug#end')- You can add your own plugins here or in other files in this directory! -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information diff --git a/lua/kickstart/plugins/autopairs.lua b/lua/kickstart/plugins/autopairs.lua index 351dad86cd5..3a305a885c0 100644 --- a/lua/kickstart/plugins/autopairs.lua +++ b/lua/kickstart/plugins/autopairs.lua @@ -6,5 +6,18 @@ return { 'windwp/nvim-autopairs', event = 'InsertEnter', - opts = {}, + -- Optional dependency + dependencies = { 'hrsh7th/nvim-cmp', 'RRethy/nvim-treesitter-endwise' }, + config = function() + require('nvim-autopairs').setup {} + -- If you want to automatically add `(` after selecting a function or method + local cmp_autopairs = require 'nvim-autopairs.completion.cmp' + local cmp = require 'cmp' + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) + require('nvim-treesitter.configs').setup { + endwise = { + enable = true, + }, + } + end, }