diff options
Diffstat (limited to 'vim')
| -rw-r--r-- | vim/init.vim | 44 | ||||
| -rw-r--r-- | vim/kickstarter.lua | 665 |
2 files changed, 709 insertions, 0 deletions
diff --git a/vim/init.vim b/vim/init.vim new file mode 100644 index 0000000..6a2373e --- /dev/null +++ b/vim/init.vim | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | " Avoid load this script twice | ||
| 2 | if get(s:, 'loaded', 0) != 0 | ||
| 3 | finish | ||
| 4 | else | ||
| 5 | let s:loaded = 1 | ||
| 6 | endif | ||
| 7 | |||
| 8 | " Get current dir | ||
| 9 | " let s:home = fnamemodify(resolve(expand('<sfile>:p')), ':h') | ||
| 10 | let s:home = '~/.vim/vim-init' | ||
| 11 | |||
| 12 | " Load script in current dir | ||
| 13 | " command! -nargs=1 LoadScript exec 'source '.s:home.'/'.'<args>' | ||
| 14 | |||
| 15 | " Add current dir into runtimepath | ||
| 16 | execute 'set runtimepath+='.s:home | ||
| 17 | |||
| 18 | |||
| 19 | "---------------------------------------------------------------------- | ||
| 20 | " Locad Modules | ||
| 21 | "---------------------------------------------------------------------- | ||
| 22 | |||
| 23 | " Basic configuration | ||
| 24 | source ~/.vim/vim-init/init/init-basic.vim | ||
| 25 | |||
| 26 | " Key mappings | ||
| 27 | source ~/.vim/vim-init/init/init-keymaps.vim | ||
| 28 | |||
| 29 | " UI | ||
| 30 | " source ~/.vim/vim-init/init/init-style.vim | ||
| 31 | |||
| 32 | " Extra config for different contexts | ||
| 33 | source ~/.vim/vim-init/init/init-config.vim | ||
| 34 | |||
| 35 | " Set tabsize | ||
| 36 | source ~/.vim/vim-init/init/init-tabsize.vim | ||
| 37 | |||
| 38 | if has('nvim') | ||
| 39 | " For nvim | ||
| 40 | source ~/.config/nvim/kickstarter.lua | ||
| 41 | else | ||
| 42 | " Plugin | ||
| 43 | source ~/.vim/vim-init/init/init-plugins.vim | ||
| 44 | endif | ||
diff --git a/vim/kickstarter.lua b/vim/kickstarter.lua new file mode 100644 index 0000000..d5a2036 --- /dev/null +++ b/vim/kickstarter.lua | |||
| @@ -0,0 +1,665 @@ | |||
| 1 | --[[ | ||
| 2 | |||
| 3 | ===================================================================== | ||
| 4 | ==================== READ THIS BEFORE CONTINUING ==================== | ||
| 5 | ===================================================================== | ||
| 6 | ======== .-----. ======== | ||
| 7 | ======== .----------------------. | === | ======== | ||
| 8 | ======== |.-""""""""""""""""""-.| |-----| ======== | ||
| 9 | ======== || || | === | ======== | ||
| 10 | ======== || KICKSTART.NVIM || |-----| ======== | ||
| 11 | ======== || || | === | ======== | ||
| 12 | ======== || || |-----| ======== | ||
| 13 | ======== ||:Tutor || |:::::| ======== | ||
| 14 | ======== |'-..................-'| |____o| ======== | ||
| 15 | ======== `"")----------------(""` ___________ ======== | ||
| 16 | ======== /::::::::::| |::::::::::\ \ no mouse \ ======== | ||
| 17 | ======== /:::========| |==hjkl==:::\ \ required \ ======== | ||
| 18 | ======== '""""""""""""' '""""""""""""' '""""""""""' ======== | ||
| 19 | ======== ======== | ||
| 20 | ===================================================================== | ||
| 21 | ===================================================================== | ||
| 22 | |||
| 23 | What is Kickstart? | ||
| 24 | |||
| 25 | Kickstart.nvim is *not* a distribution. | ||
| 26 | |||
| 27 | Kickstart.nvim is a starting point for your own configuration. | ||
| 28 | The goal is that you can read every line of code, top-to-bottom, understand | ||
| 29 | what your configuration is doing, and modify it to suit your needs. | ||
| 30 | |||
| 31 | Once you've done that, you can start exploring, configuring and tinkering to | ||
| 32 | make Neovim your own! That might mean leaving Kickstart just the way it is for a while | ||
| 33 | or immediately breaking it into modular pieces. It's up to you! | ||
| 34 | |||
| 35 | If you don't know anything about Lua, I recommend taking some time to read through | ||
| 36 | a guide. One possible example which will only take 10-15 minutes: | ||
| 37 | - https://learnxinyminutes.com/docs/lua/ | ||
| 38 | |||
| 39 | After understanding a bit more about Lua, you can use `:help lua-guide` as a | ||
| 40 | reference for how Neovim integrates Lua. | ||
| 41 | - :help lua-guide | ||
| 42 | - (or HTML version): https://neovim.io/doc/user/lua-guide.html | ||
| 43 | |||
| 44 | Kickstart Guide: | ||
| 45 | |||
| 46 | TODO: The very first thing you should do is to run the command `:Tutor` in Neovim. | ||
| 47 | |||
| 48 | If you don't know what this means, type the following: | ||
| 49 | - <escape key> | ||
| 50 | - : | ||
| 51 | - Tutor | ||
| 52 | - <enter key> | ||
| 53 | |||
| 54 | (If you already know the Neovim basics, you can skip this step.) | ||
| 55 | |||
| 56 | Once you've completed that, you can continue working through **AND READING** the rest | ||
| 57 | of the kickstart init.lua. | ||
| 58 | |||
| 59 | Next, run AND READ `:help`. | ||
| 60 | This will open up a help window with some basic information | ||
| 61 | about reading, navigating and searching the builtin help documentation. | ||
| 62 | |||
| 63 | This should be the first place you go to look when you're stuck or confused | ||
| 64 | with something. It's one of my favorite Neovim features. | ||
| 65 | |||
| 66 | MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation, | ||
| 67 | which is very useful when you're not exactly sure of what you're looking for. | ||
| 68 | |||
| 69 | I have left several `:help X` comments throughout the init.lua | ||
| 70 | These are hints about where to find more information about the relevant settings, | ||
| 71 | plugins or Neovim features used in Kickstart. | ||
| 72 | |||
| 73 | NOTE: Look for lines like this | ||
| 74 | |||
| 75 | Throughout the file. These are for you, the reader, to help you understand what is happening. | ||
| 76 | Feel free to delete them once you know what you're doing, but they should serve as a guide | ||
| 77 | for when you are first encountering a few different constructs in your Neovim config. | ||
| 78 | |||
| 79 | If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. | ||
| 80 | |||
| 81 | I hope you enjoy your Neovim journey, | ||
| 82 | - TJ | ||
| 83 | |||
| 84 | P.S. You can delete this when you're done too. It's your config now! :) | ||
| 85 | --]] | ||
| 86 | |||
| 87 | -- Install package manager | ||
| 88 | -- https://github.com/folke/lazy.nvim | ||
| 89 | -- `:help lazy.nvim.txt` for more info | ||
| 90 | local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' | ||
| 91 | if not vim.loop.fs_stat(lazypath) then | ||
| 92 | vim.fn.system { | ||
| 93 | 'git', | ||
| 94 | 'clone', | ||
| 95 | '--filter=blob:none', | ||
| 96 | 'https://github.com/folke/lazy.nvim.git', | ||
| 97 | '--branch=stable', -- latest stable release | ||
| 98 | lazypath, | ||
| 99 | } | ||
| 100 | end | ||
| 101 | vim.opt.runtimepath:prepend(lazypath) | ||
| 102 | |||
| 103 | -- NOTE: Here is where you install your plugins. | ||
| 104 | -- You can configure plugins using the `config` key. | ||
| 105 | -- | ||
| 106 | -- You can also configure plugins after the setup call, | ||
| 107 | -- as they will be available in your neovim runtime. | ||
| 108 | require('lazy').setup({ | ||
| 109 | -- NOTE: First, some plugins that don't require any configuration | ||
| 110 | -- Git related plugins | ||
| 111 | 'tpope/vim-fugitive', | ||
| 112 | 'tpope/vim-rhubarb', | ||
| 113 | |||
| 114 | -- Detect tabstop and shiftwidth automatically | ||
| 115 | 'tpope/vim-sleuth', | ||
| 116 | |||
| 117 | -- Use sudo in command mode | ||
| 118 | 'lambdalisue/suda.vim', | ||
| 119 | |||
| 120 | -- For beancount | ||
| 121 | 'nathangrigg/vim-beancount', | ||
| 122 | |||
| 123 | -- For surrounding | ||
| 124 | 'tpope/vim-surround', | ||
| 125 | |||
| 126 | -- From vim plugin | ||
| 127 | 'junegunn/goyo.vim', | ||
| 128 | 'itchyny/lightline.vim', | ||
| 129 | 'preservim/nerdtree', | ||
| 130 | |||
| 131 | |||
| 132 | -- NOTE: This is where your plugins related to LSP can be installed. | ||
| 133 | -- The configuration is done below. Search for lspconfig to find it below. | ||
| 134 | { | ||
| 135 | -- LSP Configuration & Plugins | ||
| 136 | 'neovim/nvim-lspconfig', | ||
| 137 | dependencies = { | ||
| 138 | -- Automatically install LSPs to stdpath for neovim | ||
| 139 | { 'williamboman/mason.nvim', config = true }, | ||
| 140 | 'williamboman/mason-lspconfig.nvim', | ||
| 141 | |||
| 142 | -- Useful status updates for LSP | ||
| 143 | -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` | ||
| 144 | { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, | ||
| 145 | |||
| 146 | -- Additional lua configuration, makes nvim stuff amazing! | ||
| 147 | 'folke/neodev.nvim', | ||
| 148 | }, | ||
| 149 | }, | ||
| 150 | |||
| 151 | { | ||
| 152 | -- Autocompletion | ||
| 153 | 'hrsh7th/nvim-cmp', | ||
| 154 | dependencies = { | ||
| 155 | -- Snippet Engine & its associated nvim-cmp source | ||
| 156 | 'L3MON4D3/LuaSnip', | ||
| 157 | 'saadparwaiz1/cmp_luasnip', | ||
| 158 | |||
| 159 | -- Adds LSP completion capabilities | ||
| 160 | 'hrsh7th/cmp-nvim-lsp', | ||
| 161 | |||
| 162 | -- Adds a number of user-friendly snippets | ||
| 163 | 'rafamadriz/friendly-snippets', | ||
| 164 | }, | ||
| 165 | }, | ||
| 166 | |||
| 167 | -- Useful plugin to show you pending keybinds. | ||
| 168 | { | ||
| 169 | 'folke/which-key.nvim', | ||
| 170 | opts = { | ||
| 171 | plugins = { | ||
| 172 | spelling = { | ||
| 173 | enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions | ||
| 174 | suggestions = 20, -- how many suggestions should be shown in the list? | ||
| 175 | }, | ||
| 176 | } | ||
| 177 | } | ||
| 178 | }, | ||
| 179 | { | ||
| 180 | -- Adds git related signs to the gutter, as well as utilities for managing changes | ||
| 181 | 'lewis6991/gitsigns.nvim', | ||
| 182 | opts = { | ||
| 183 | -- See `:help gitsigns.txt` | ||
| 184 | signs = { | ||
| 185 | add = { text = '+' }, | ||
| 186 | change = { text = '~' }, | ||
| 187 | delete = { text = '_' }, | ||
| 188 | topdelete = { text = '‾' }, | ||
| 189 | changedelete = { text = '~' }, | ||
| 190 | }, | ||
| 191 | on_attach = function(bufnr) | ||
| 192 | vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk, | ||
| 193 | { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) | ||
| 194 | vim.keymap.set('n', '<leader>gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' }) | ||
| 195 | vim.keymap.set('n', '<leader>ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) | ||
| 196 | end, | ||
| 197 | }, | ||
| 198 | }, | ||
| 199 | |||
| 200 | { | ||
| 201 | -- Theme inspired by Atom | ||
| 202 | 'navarasu/onedark.nvim', | ||
| 203 | priority = 1000, | ||
| 204 | config = function() | ||
| 205 | -- vim.cmd.colorscheme 'onedark' | ||
| 206 | vim.cmd.colorscheme 'koehler' | ||
| 207 | vim.api.nvim_command('highlight ExtraWhitespaces ctermbg=red guibg=red') | ||
| 208 | vim.fn.matchadd('ExtraWhitespaces', '\\s\\+$') | ||
| 209 | end, | ||
| 210 | }, | ||
| 211 | |||
| 212 | --{ | ||
| 213 | -- -- Set lualine as statusline | ||
| 214 | -- 'nvim-lualine/lualine.nvim', | ||
| 215 | -- -- See `:help lualine.txt` | ||
| 216 | -- opts = { | ||
| 217 | -- options = { | ||
| 218 | -- icons_enabled = false, | ||
| 219 | -- theme = 'onedark', | ||
| 220 | -- component_separators = '|', | ||
| 221 | -- section_separators = { left = '', right = '' }, | ||
| 222 | -- }, | ||
| 223 | -- }, | ||
| 224 | --}, | ||
| 225 | |||
| 226 | { | ||
| 227 | -- Add indentation guides even on blank lines | ||
| 228 | 'lukas-reineke/indent-blankline.nvim', | ||
| 229 | -- Enable `lukas-reineke/indent-blankline.nvim` | ||
| 230 | -- See `:help ibl` | ||
| 231 | main = "ibl", | ||
| 232 | opts = { | ||
| 233 | indent = { char = "┊" }, | ||
| 234 | whitespace = { highlight = { "Whitespace", "NonText" } }, | ||
| 235 | }, | ||
| 236 | }, | ||
| 237 | |||
| 238 | -- "gc" to comment visual regions/lines | ||
| 239 | --{ 'numToStr/Comment.nvim', opts = {} }, | ||
| 240 | -- Another config | ||
| 241 | { | ||
| 242 | 'numToStr/Comment.nvim', | ||
| 243 | opts = { | ||
| 244 | opleader = { | ||
| 245 | ---Line-comment keymap | ||
| 246 | line = 'gc', | ||
| 247 | ---Block-comment keymap | ||
| 248 | block = 'gb', | ||
| 249 | }, | ||
| 250 | } | ||
| 251 | }, | ||
| 252 | |||
| 253 | |||
| 254 | -- Fuzzy Finder (files, lsp, etc) | ||
| 255 | { | ||
| 256 | 'nvim-telescope/telescope.nvim', | ||
| 257 | branch = '0.1.x', | ||
| 258 | dependencies = { | ||
| 259 | 'nvim-lua/plenary.nvim', | ||
| 260 | -- Fuzzy Finder Algorithm which requires local dependencies to be built. | ||
| 261 | -- Only load if `make` is available. Make sure you have the system | ||
| 262 | -- requirements installed. | ||
| 263 | { | ||
| 264 | 'nvim-telescope/telescope-fzf-native.nvim', | ||
| 265 | -- NOTE: If you are having trouble with this installation, | ||
| 266 | -- refer to the README for telescope-fzf-native for more instructions. | ||
| 267 | build = 'make', | ||
| 268 | cond = function() | ||
| 269 | return vim.fn.executable 'make' == 1 | ||
| 270 | end, | ||
| 271 | }, | ||
| 272 | }, | ||
| 273 | }, | ||
| 274 | |||
| 275 | { | ||
| 276 | -- Highlight, edit, and navigate code | ||
| 277 | 'nvim-treesitter/nvim-treesitter', | ||
| 278 | dependencies = { | ||
| 279 | 'nvim-treesitter/nvim-treesitter-textobjects', | ||
| 280 | }, | ||
| 281 | build = ':TSUpdate', | ||
| 282 | }, | ||
| 283 | |||
| 284 | -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart | ||
| 285 | -- These are some example plugins that I've included in the kickstart repository. | ||
| 286 | -- Uncomment any of the lines below to enable them. | ||
| 287 | -- require 'kickstart.plugins.autoformat', | ||
| 288 | -- require 'kickstart.plugins.debug', | ||
| 289 | |||
| 290 | -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` | ||
| 291 | -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping | ||
| 292 | -- up-to-date with whatever is in the kickstart repo. | ||
| 293 | -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. | ||
| 294 | -- | ||
| 295 | -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins | ||
| 296 | -- { import = 'custom.plugins' }, | ||
| 297 | -- install without yarn or npm | ||
| 298 | { | ||
| 299 | "iamcco/markdown-preview.nvim", | ||
| 300 | cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, | ||
| 301 | ft = { "markdown" }, | ||
| 302 | build = function() vim.fn["mkdp#util#install"]() end, | ||
| 303 | }, | ||
| 304 | }, {}) | ||
| 305 | |||
| 306 | -- [[ Setting options ]] | ||
| 307 | -- See `:help vim.o` | ||
| 308 | |||
| 309 | -- Sync clipboard between OS and Neovim. | ||
| 310 | -- Remove this option if you want your OS clipboard to remain independent. | ||
| 311 | -- See `:help 'clipboard'` | ||
| 312 | |||
| 313 | -- vim.o.clipboard = 'unnamedplus' | ||
| 314 | |||
| 315 | -- Enable break indent | ||
| 316 | vim.o.breakindent = true | ||
| 317 | |||
| 318 | -- Save undo history | ||
| 319 | vim.o.undofile = true | ||
| 320 | |||
| 321 | -- Case-insensitive searching UNLESS \C or capital in search | ||
| 322 | vim.o.ignorecase = true | ||
| 323 | vim.o.smartcase = true | ||
| 324 | |||
| 325 | -- Keep signcolumn on by default | ||
| 326 | vim.wo.signcolumn = 'yes' | ||
| 327 | |||
| 328 | -- Decrease update time | ||
| 329 | vim.o.updatetime = 250 | ||
| 330 | vim.o.timeout = true | ||
| 331 | vim.o.timeoutlen = 300 | ||
| 332 | |||
| 333 | -- Set completeopt to have a better completion experience | ||
| 334 | vim.o.completeopt = 'menuone,noselect' | ||
| 335 | |||
| 336 | -- NOTE: You should make sure your terminal supports this | ||
| 337 | vim.o.termguicolors = true | ||
| 338 | |||
| 339 | -- [[ Basic Keymaps ]] | ||
| 340 | |||
| 341 | -- Keymaps for better default experience | ||
| 342 | -- See `:help vim.keymap.set()` | ||
| 343 | -- vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) | ||
| 344 | |||
| 345 | -- Use suda.vim to run sudo, or terminal prompt fails | ||
| 346 | -- See more details at https://github.com/neovim/neovim/issue | ||
| 347 | vim.cmd("command! W execute 'SudaWrite %'") | ||
| 348 | |||
| 349 | |||
| 350 | -- [[ Configure lualine ]] | ||
| 351 | -- Change the background of lualine_b section for normal mode | ||
| 352 | -- local custom_wombat = require 'lualine.themes.wombat' | ||
| 353 | -- custom_wombat.normal.b.bg = '#a8a8a8' | ||
| 354 | -- custom_wombat.normal.b.fg = '#444444' | ||
| 355 | -- require('lualine').setup { | ||
| 356 | -- options = { theme = custom_wombat }, | ||
| 357 | -- } | ||
| 358 | -- [[ Configure lightline ]] | ||
| 359 | vim.cmd("let g:lightline = { 'colorscheme': 'wombat' }") | ||
| 360 | |||
| 361 | -- [[ Configure Goyo ]] | ||
| 362 | vim.cmd("nnoremap <silent> <leader>z :Goyo<CR>") | ||
| 363 | |||
| 364 | -- [[ Configure NERDTree ]] | ||
| 365 | vim.g.NERDTreeWinPos = 'left' | ||
| 366 | vim.g.NERDTreeShowHidden = 0 | ||
| 367 | vim.g.NERDTreeQuitOnOpen = 1 | ||
| 368 | vim.api.nvim_set_var('NERDTreeWinSize', 35) | ||
| 369 | vim.cmd("map <C-n> :NERDTreeToggle<cr>") | ||
| 370 | vim.cmd("map <leader>nb :NERDTreeFromBookmark<Space>") | ||
| 371 | vim.cmd("map <leader>nf :NERDTreeFind<cr>") | ||
| 372 | -- vim.cmd("autocmd BufWinEnter * if &buftype != 'quickfix' && getcmdwintype() == '' | silent NERDTreeMirror | endif") | ||
| 373 | |||
| 374 | -- [[ Highlight on yank ]] | ||
| 375 | -- See `:help vim.highlight.on_yank()` | ||
| 376 | local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) | ||
| 377 | vim.api.nvim_create_autocmd('TextYankPost', { | ||
| 378 | callback = function() | ||
| 379 | vim.highlight.on_yank() | ||
| 380 | end, | ||
| 381 | group = highlight_group, | ||
| 382 | pattern = '*', | ||
| 383 | }) | ||
| 384 | |||
| 385 | -- [[ Configure Telescope ]] | ||
| 386 | -- See `:help telescope` and `:help telescope.setup()` | ||
| 387 | require('telescope').setup { | ||
| 388 | defaults = { | ||
| 389 | mappings = { | ||
| 390 | i = { | ||
| 391 | ["<c-j>"] = "move_selection_next", | ||
| 392 | ["<c-k>"] = "move_selection_previous", | ||
| 393 | ["<C-w>"] = require("telescope.actions.layout").toggle_preview, | ||
| 394 | }, | ||
| 395 | }, | ||
| 396 | layout_config = { | ||
| 397 | vertical = { height = 0.8 }, | ||
| 398 | -- other layout configuration here | ||
| 399 | preview_cutoff = 0, | ||
| 400 | }, | ||
| 401 | }, | ||
| 402 | pickers = { | ||
| 403 | buffers = { | ||
| 404 | show_all_buffers = true, | ||
| 405 | sort_lastused = true, | ||
| 406 | theme = "dropdown", | ||
| 407 | previewer = false, | ||
| 408 | mappings = { | ||
| 409 | i = { | ||
| 410 | ["<c-d>"] = "delete_buffer", | ||
| 411 | }, | ||
| 412 | n = { | ||
| 413 | ["<c-d>"] = "delete_buffer", | ||
| 414 | } | ||
| 415 | } | ||
| 416 | } | ||
| 417 | } | ||
| 418 | } | ||
| 419 | |||
| 420 | -- Enable telescope fzf native, if installed | ||
| 421 | pcall(require('telescope').load_extension, 'fzf') | ||
| 422 | |||
| 423 | -- See `:help telescope.builtin` | ||
| 424 | vim.keymap.set('n', '<leader>f', require('telescope.builtin').oldfiles, { desc = '[f] Find recently opened files' }) | ||
| 425 | vim.keymap.set('n', '<leader>q', require('telescope.builtin').buffers, { desc = '[q] Find existing buffers' }) | ||
| 426 | vim.keymap.set('n', '<leader>/', function() | ||
| 427 | -- You can pass additional configuration to telescope to change theme, layout, etc. | ||
| 428 | require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { | ||
| 429 | --winblend = 10, | ||
| 430 | previewer = false, | ||
| 431 | }) | ||
| 432 | end, { desc = '[/] Fuzzily search in current buffer' }) | ||
| 433 | |||
| 434 | vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) | ||
| 435 | vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
| 436 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
| 437 | vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) | ||
| 438 | vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) | ||
| 439 | vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) | ||
| 440 | |||
| 441 | -- [[ Configure Treesitter ]] | ||
| 442 | -- See `:help nvim-treesitter` | ||
| 443 | require('nvim-treesitter.configs').setup { | ||
| 444 | -- Add languages to be installed here that you want installed for treesitter | ||
| 445 | ensure_installed = { 'html', 'css', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, | ||
| 446 | |||
| 447 | -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | ||
| 448 | auto_install = false, | ||
| 449 | |||
| 450 | highlight = { enable = true }, | ||
| 451 | indent = { enable = true }, | ||
| 452 | incremental_selection = { | ||
| 453 | enable = true, | ||
| 454 | keymaps = { | ||
| 455 | init_selection = '<c-space>', | ||
| 456 | node_incremental = '<c-space>', | ||
| 457 | scope_incremental = '<c-s>', | ||
| 458 | node_decremental = '<M-space>', | ||
| 459 | }, | ||
| 460 | }, | ||
| 461 | textobjects = { | ||
| 462 | select = { | ||
| 463 | enable = true, | ||
| 464 | lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim | ||
| 465 | keymaps = { | ||
| 466 | -- You can use the capture groups defined in textobjects.scm | ||
| 467 | ['aa'] = '@parameter.outer', | ||
| 468 | ['ia'] = '@parameter.inner', | ||
| 469 | ['if'] = '@function.inner', | ||
| 470 | ['af'] = '@function.outer', | ||
| 471 | ['ac'] = '@class.outer', | ||
| 472 | ['ic'] = '@class.inner', | ||
| 473 | }, | ||
| 474 | }, | ||
| 475 | move = { | ||
| 476 | enable = true, | ||
| 477 | set_jumps = true, -- whether to set jumps in the jumplist | ||
| 478 | goto_next_start = { | ||
| 479 | [']m'] = '@function.outer', | ||
| 480 | [']]'] = '@class.outer', | ||
| 481 | }, | ||
| 482 | goto_next_end = { | ||
| 483 | [']M'] = '@function.outer', | ||
| 484 | [']['] = '@class.outer', | ||
| 485 | }, | ||
| 486 | goto_previous_start = { | ||
| 487 | ['[m'] = '@function.outer', | ||
| 488 | ['[['] = '@class.outer', | ||
| 489 | }, | ||
| 490 | goto_previous_end = { | ||
| 491 | ['[M'] = '@function.outer', | ||
| 492 | ['[]'] = '@class.outer', | ||
| 493 | }, | ||
| 494 | }, | ||
| 495 | swap = { | ||
| 496 | enable = true, | ||
| 497 | swap_next = { | ||
| 498 | ['<leader>a'] = '@parameter.inner', | ||
| 499 | }, | ||
| 500 | swap_previous = { | ||
| 501 | ['<leader>A'] = '@parameter.inner', | ||
| 502 | }, | ||
| 503 | }, | ||
| 504 | }, | ||
| 505 | } | ||
| 506 | |||
| 507 | -- Diagnostic keymaps | ||
| 508 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) | ||
| 509 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) | ||
| 510 | vim.keymap.set('n', '<leader>E', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) | ||
| 511 | vim.keymap.set('n', '<leader>Q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) | ||
| 512 | |||
| 513 | -- [[ Configure LSP ]] | ||
| 514 | -- This function gets run when an LSP connects to a particular buffer. | ||
| 515 | local on_attach = function(_, bufnr) | ||
| 516 | -- NOTE: Remember that lua is a real programming language, and as such it is possible | ||
| 517 | -- to define small helper and utility functions so you don't have to repeat yourself | ||
| 518 | -- many times. | ||
| 519 | -- | ||
| 520 | -- In this case, we create a function that lets us more easily define mappings specific | ||
| 521 | -- for LSP related items. It sets the mode, buffer and description for us each time. | ||
| 522 | local nmap = function(keys, func, desc) | ||
| 523 | if desc then | ||
| 524 | desc = 'LSP: ' .. desc | ||
| 525 | end | ||
| 526 | |||
| 527 | vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) | ||
| 528 | end | ||
| 529 | |||
| 530 | nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') | ||
| 531 | nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') | ||
| 532 | |||
| 533 | nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') | ||
| 534 | nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') | ||
| 535 | nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') | ||
| 536 | nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') | ||
| 537 | nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') | ||
| 538 | nmap('<leader><leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') | ||
| 539 | |||
| 540 | -- See `:help K` for why this keymap | ||
| 541 | nmap('K', vim.lsp.buf.hover, 'Hover Documentation') | ||
| 542 | -- nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') | ||
| 543 | |||
| 544 | -- Lesser used LSP functionality | ||
| 545 | nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') | ||
| 546 | nmap('<leader><leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') | ||
| 547 | nmap('<leader><leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') | ||
| 548 | nmap('<leader><leader>wl', function() | ||
| 549 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||
| 550 | end, '[W]orkspace [L]ist Folders') | ||
| 551 | |||
| 552 | -- Create a command `:Format` local to the LSP buffer | ||
| 553 | vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | ||
| 554 | vim.lsp.buf.format() | ||
| 555 | end, { desc = 'Format current buffer with LSP' }) | ||
| 556 | nmap('<leader>F', ':Format<CR>', 'Format code') | ||
| 557 | end | ||
| 558 | |||
| 559 | -- Enable the following language servers | ||
| 560 | -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
| 561 | -- | ||
| 562 | -- Add any additional override configuration in the following tables. They will be passed to | ||
| 563 | -- the `settings` field of the server config. You must look up that documentation yourself. | ||
| 564 | -- | ||
| 565 | -- If you want to override the default filetypes that your language server will attach to you can | ||
| 566 | -- define the property 'filetypes' to the map in question. | ||
| 567 | local servers = { | ||
| 568 | -- clangd = {}, | ||
| 569 | -- gopls = {}, | ||
| 570 | -- pyright = {}, | ||
| 571 | -- rust_analyzer = {}, | ||
| 572 | -- tsserver = {}, | ||
| 573 | -- html = { filetypes = { 'html', 'twig', 'hbs'} }, | ||
| 574 | tsserver = {}, | ||
| 575 | beancount = { | ||
| 576 | filetypes = { "beancount", "bean" }, | ||
| 577 | }, | ||
| 578 | |||
| 579 | lua_ls = { | ||
| 580 | Lua = { | ||
| 581 | workspace = { checkThirdParty = false }, | ||
| 582 | telemetry = { enable = false }, | ||
| 583 | diagnostics = { | ||
| 584 | -- Get the language server to recognize the `vim` global | ||
| 585 | globals = { 'vim' }, | ||
| 586 | }, | ||
| 587 | }, | ||
| 588 | }, | ||
| 589 | } | ||
| 590 | |||
| 591 | -- Setup neovim lua configuration | ||
| 592 | require('neodev').setup() | ||
| 593 | |||
| 594 | -- nvim-cmp supports additional completion capabilities, so broadcast that to servers | ||
| 595 | local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
| 596 | capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | ||
| 597 | |||
| 598 | -- Ensure the servers above are installed | ||
| 599 | local mason_lspconfig = require 'mason-lspconfig' | ||
| 600 | |||
| 601 | mason_lspconfig.setup { | ||
| 602 | ensure_installed = vim.tbl_keys(servers), | ||
| 603 | } | ||
| 604 | |||
| 605 | mason_lspconfig.setup_handlers { | ||
| 606 | function(server_name) | ||
| 607 | require('lspconfig')[server_name].setup { | ||
| 608 | capabilities = capabilities, | ||
| 609 | on_attach = on_attach, | ||
| 610 | settings = servers[server_name], | ||
| 611 | filetypes = (servers[server_name] or {}).filetypes, | ||
| 612 | } | ||
| 613 | end | ||
| 614 | } | ||
| 615 | |||
| 616 | -- [[ Configure nvim-cmp ]] | ||
| 617 | -- See `:help cmp` | ||
| 618 | local cmp = require 'cmp' | ||
| 619 | local luasnip = require 'luasnip' | ||
| 620 | require('luasnip.loaders.from_vscode').lazy_load() | ||
| 621 | luasnip.config.setup {} | ||
| 622 | |||
| 623 | cmp.setup { | ||
| 624 | snippet = { | ||
| 625 | expand = function(args) | ||
| 626 | luasnip.lsp_expand(args.body) | ||
| 627 | end, | ||
| 628 | }, | ||
| 629 | mapping = cmp.mapping.preset.insert { | ||
| 630 | ['<C-n>'] = cmp.mapping.select_next_item(), | ||
| 631 | ['<C-p>'] = cmp.mapping.select_prev_item(), | ||
| 632 | ['<C-d>'] = cmp.mapping.scroll_docs(-4), | ||
| 633 | ['<C-u>'] = cmp.mapping.scroll_docs(4), | ||
| 634 | ['<C-Space>'] = cmp.mapping.complete {}, | ||
| 635 | ['<CR>'] = cmp.mapping.confirm { | ||
| 636 | behavior = cmp.ConfirmBehavior.Replace, | ||
| 637 | select = true, | ||
| 638 | }, | ||
| 639 | ['<Tab>'] = cmp.mapping(function(fallback) | ||
| 640 | if cmp.visible() then | ||
| 641 | cmp.select_next_item() | ||
| 642 | elseif luasnip.expand_or_locally_jumpable() then | ||
| 643 | luasnip.expand_or_jump() | ||
| 644 | else | ||
| 645 | fallback() | ||
| 646 | end | ||
| 647 | end, { 'i', 's' }), | ||
| 648 | ['<S-Tab>'] = cmp.mapping(function(fallback) | ||
| 649 | if cmp.visible() then | ||
| 650 | cmp.select_prev_item() | ||
| 651 | elseif luasnip.locally_jumpable(-1) then | ||
| 652 | luasnip.jump(-1) | ||
| 653 | else | ||
| 654 | fallback() | ||
| 655 | end | ||
| 656 | end, { 'i', 's' }), | ||
| 657 | }, | ||
| 658 | sources = { | ||
| 659 | { name = 'nvim_lsp' }, | ||
| 660 | { name = 'luasnip' }, | ||
| 661 | }, | ||
| 662 | } | ||
| 663 | |||
| 664 | -- The line beneath this is called `modeline`. See `:help modeline` | ||
| 665 | -- vim: ts=2 sts=2 sw=2 et | ||