diff options
| -rw-r--r-- | alias | 2 | ||||
| -rw-r--r-- | init.lua | 486 |
2 files changed, 487 insertions, 1 deletions
| @@ -33,7 +33,7 @@ vll() { | |||
| 33 | [ -n "$file" ] && eval vim $file; | 33 | [ -n "$file" ] && eval vim $file; |
| 34 | } | 34 | } |
| 35 | #alias vl="vim $(sed -n '/^[^#]/{p;q}' ~/.vim_mru_files)" | 35 | #alias vl="vim $(sed -n '/^[^#]/{p;q}' ~/.vim_mru_files)" |
| 36 | alias ve="vim ~/.config/nvim/init.vim" | 36 | alias ve="vim ~/.config/nvim/init.lua" |
| 37 | alias vro='vim -R' | 37 | alias vro='vim -R' |
| 38 | alias vu='vim -u NONE' | 38 | alias vu='vim -u NONE' |
| 39 | alias vq='vim ~/buffer' | 39 | alias vq='vim ~/buffer' |
diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..f7aafe0 --- /dev/null +++ b/init.lua | |||
| @@ -0,0 +1,486 @@ | |||
| 1 | --[[ | ||
| 2 | |||
| 3 | ===================================================================== | ||
| 4 | ==================== READ THIS BEFORE CONTINUING ==================== | ||
| 5 | ===================================================================== | ||
| 6 | |||
| 7 | Kickstart.nvim is *not* a distribution. | ||
| 8 | |||
| 9 | Kickstart.nvim is a template for your own configuration. | ||
| 10 | The goal is that you can read every line of code, top-to-bottom, and understand | ||
| 11 | what your configuration is doing. | ||
| 12 | |||
| 13 | Once you've done that, you should start exploring, configuring and tinkering to | ||
| 14 | explore Neovim! | ||
| 15 | |||
| 16 | If you don't know anything about Lua, I recommend taking some time to read through | ||
| 17 | a guide. One possible example: | ||
| 18 | - https://learnxinyminutes.com/docs/lua/ | ||
| 19 | |||
| 20 | And then you can explore or search through `:help lua-guide` | ||
| 21 | |||
| 22 | |||
| 23 | Kickstart Guide: | ||
| 24 | |||
| 25 | I have left several `:help X` comments throughout the init.lua | ||
| 26 | You should run that command and read that help section for more information. | ||
| 27 | |||
| 28 | In addition, I have some `NOTE:` items throughout the file. | ||
| 29 | These are for you, the reader to help understand what is happening. Feel free to delete | ||
| 30 | them once you know what you're doing, but they should serve as a guide for when you | ||
| 31 | are first encountering a few different constructs in your nvim config. | ||
| 32 | |||
| 33 | I hope you enjoy your Neovim journey, | ||
| 34 | - TJ | ||
| 35 | |||
| 36 | P.S. You can delete this when you're done too. It's your config now :) | ||
| 37 | --]] | ||
| 38 | |||
| 39 | vim.cmd('source ' .. '~/helper/vimrc') | ||
| 40 | |||
| 41 | |||
| 42 | -- Set comma as the leader key | ||
| 43 | -- See `:help mapleader` | ||
| 44 | -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) | ||
| 45 | vim.g.mapleader = ',' | ||
| 46 | vim.g.maplocalleader = ',' | ||
| 47 | |||
| 48 | -- Install package manager | ||
| 49 | -- https://github.com/folke/lazy.nvim | ||
| 50 | -- `:help lazy.nvim.txt` for more info | ||
| 51 | local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' | ||
| 52 | if not vim.loop.fs_stat(lazypath) then | ||
| 53 | vim.fn.system { | ||
| 54 | 'git', | ||
| 55 | 'clone', | ||
| 56 | '--filter=blob:none', | ||
| 57 | 'https://github.com/folke/lazy.nvim.git', | ||
| 58 | '--branch=stable', -- latest stable release | ||
| 59 | lazypath, | ||
| 60 | } | ||
| 61 | end | ||
| 62 | vim.opt.rtp:prepend(lazypath) | ||
| 63 | |||
| 64 | -- NOTE: Here is where you install your plugins. | ||
| 65 | -- You can configure plugins using the `config` key. | ||
| 66 | -- | ||
| 67 | -- You can also configure plugins after the setup call, | ||
| 68 | -- as they will be available in your neovim runtime. | ||
| 69 | require('lazy').setup({ | ||
| 70 | -- NOTE: First, some plugins that don't require any configuration | ||
| 71 | |||
| 72 | -- Detect tabstop and shiftwidth automatically | ||
| 73 | 'tpope/vim-sleuth', | ||
| 74 | |||
| 75 | -- NOTE: This is where your plugins related to LSP can be installed. | ||
| 76 | -- The configuration is done below. Search for lspconfig to find it below. | ||
| 77 | { -- LSP Configuration & Plugins | ||
| 78 | 'neovim/nvim-lspconfig', | ||
| 79 | dependencies = { | ||
| 80 | -- Automatically install LSPs to stdpath for neovim | ||
| 81 | { 'williamboman/mason.nvim', config = true }, | ||
| 82 | 'williamboman/mason-lspconfig.nvim', | ||
| 83 | |||
| 84 | -- Useful status updates for LSP | ||
| 85 | -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` | ||
| 86 | { 'j-hui/fidget.nvim', opts = {} }, | ||
| 87 | |||
| 88 | -- Additional lua configuration, makes nvim stuff amazing! | ||
| 89 | 'folke/neodev.nvim', | ||
| 90 | }, | ||
| 91 | }, | ||
| 92 | |||
| 93 | { -- Autocompletion | ||
| 94 | 'hrsh7th/nvim-cmp', | ||
| 95 | dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, | ||
| 96 | }, | ||
| 97 | |||
| 98 | -- Useful plugin to show you pending keybinds. | ||
| 99 | { 'folke/which-key.nvim', opts = {} }, | ||
| 100 | { -- Adds git releated signs to the gutter, as well as utilities for managing changes | ||
| 101 | 'lewis6991/gitsigns.nvim', | ||
| 102 | opts = { | ||
| 103 | -- See `:help gitsigns.txt` | ||
| 104 | signs = { | ||
| 105 | add = { text = '+' }, | ||
| 106 | change = { text = '~' }, | ||
| 107 | delete = { text = '_' }, | ||
| 108 | topdelete = { text = '‾' }, | ||
| 109 | changedelete = { text = '~' }, | ||
| 110 | }, | ||
| 111 | }, | ||
| 112 | }, | ||
| 113 | |||
| 114 | { -- Set lualine as statusline | ||
| 115 | 'nvim-lualine/lualine.nvim', | ||
| 116 | -- See `:help lualine.txt` | ||
| 117 | opts = { | ||
| 118 | options = { | ||
| 119 | icons_enabled = false, | ||
| 120 | theme = 'onedark', | ||
| 121 | component_separators = '|', | ||
| 122 | section_separators = '', | ||
| 123 | }, | ||
| 124 | }, | ||
| 125 | }, | ||
| 126 | |||
| 127 | { -- Add indentation guides even on blank lines | ||
| 128 | 'lukas-reineke/indent-blankline.nvim', | ||
| 129 | -- Enable `lukas-reineke/indent-blankline.nvim` | ||
| 130 | -- See `:help indent_blankline.txt` | ||
| 131 | opts = { | ||
| 132 | char = '┊', | ||
| 133 | show_trailing_blankline_indent = false, | ||
| 134 | }, | ||
| 135 | }, | ||
| 136 | |||
| 137 | -- "gc" to comment visual regions/lines | ||
| 138 | { 'numToStr/Comment.nvim', opts = {} }, | ||
| 139 | |||
| 140 | -- Fuzzy Finder (files, lsp, etc) | ||
| 141 | { 'nvim-telescope/telescope.nvim', version = '*', dependencies = { 'nvim-lua/plenary.nvim' } }, | ||
| 142 | |||
| 143 | -- Fuzzy Finder Algorithm which requires local dependencies to be built. | ||
| 144 | -- Only load if `make` is available. Make sure you have the system | ||
| 145 | -- requirements installed. | ||
| 146 | { | ||
| 147 | 'nvim-telescope/telescope-fzf-native.nvim', | ||
| 148 | -- NOTE: If you are having trouble with this installation, | ||
| 149 | -- refer to the README for telescope-fzf-native for more instructions. | ||
| 150 | build = 'make', | ||
| 151 | cond = function() | ||
| 152 | return vim.fn.executable 'make' == 1 | ||
| 153 | end, | ||
| 154 | }, | ||
| 155 | |||
| 156 | { -- Highlight, edit, and navigate code | ||
| 157 | 'nvim-treesitter/nvim-treesitter', | ||
| 158 | dependencies = { | ||
| 159 | 'nvim-treesitter/nvim-treesitter-textobjects', | ||
| 160 | }, | ||
| 161 | build = ":TSUpdate", | ||
| 162 | }, | ||
| 163 | |||
| 164 | -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart | ||
| 165 | -- These are some example plugins that I've included in the kickstart repository. | ||
| 166 | -- Uncomment any of the lines below to enable them. | ||
| 167 | -- require 'kickstart.plugins.autoformat', | ||
| 168 | -- require 'kickstart.plugins.debug', | ||
| 169 | |||
| 170 | -- NOTE: The import below automatically adds your own plugins, configuration, etc from `lua/custom/plugins/*.lua` | ||
| 171 | -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping | ||
| 172 | -- up-to-date with whatever is in the kickstart repo. | ||
| 173 | -- | ||
| 174 | -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins | ||
| 175 | -- | ||
| 176 | -- An additional note is that if you only copied in the `init.lua`, you can just comment this line | ||
| 177 | -- to get rid of the warning telling you that there are not plugins in `lua/custom/plugins/`. | ||
| 178 | { import = 'custom.plugins' }, | ||
| 179 | }, {}) | ||
| 180 | |||
| 181 | -- [[ Setting options ]] | ||
| 182 | -- See `:help vim.o` | ||
| 183 | |||
| 184 | -- Set highlight on search | ||
| 185 | vim.o.hlsearch = false | ||
| 186 | |||
| 187 | -- Make line numbers default | ||
| 188 | vim.wo.number = true | ||
| 189 | |||
| 190 | -- Enable mouse mode | ||
| 191 | vim.o.mouse = 'a' | ||
| 192 | |||
| 193 | -- Sync clipboard between OS and Neovim. | ||
| 194 | -- Remove this option if you want your OS clipboard to remain independent. | ||
| 195 | -- See `:help 'clipboard'` | ||
| 196 | vim.o.clipboard = 'unnamedplus' | ||
| 197 | |||
| 198 | -- Enable break indent | ||
| 199 | vim.o.breakindent = true | ||
| 200 | |||
| 201 | -- Save undo history | ||
| 202 | vim.o.undofile = true | ||
| 203 | |||
| 204 | -- Case insensitive searching UNLESS /C or capital in search | ||
| 205 | vim.o.ignorecase = true | ||
| 206 | vim.o.smartcase = true | ||
| 207 | |||
| 208 | -- Keep signcolumn on by default | ||
| 209 | vim.wo.signcolumn = 'yes' | ||
| 210 | |||
| 211 | -- Decrease update time | ||
| 212 | vim.o.updatetime = 250 | ||
| 213 | vim.o.timeout = true | ||
| 214 | vim.o.timeoutlen = 300 | ||
| 215 | |||
| 216 | -- Set completeopt to have a better completion experience | ||
| 217 | vim.o.completeopt = 'menuone,noselect' | ||
| 218 | |||
| 219 | -- NOTE: You should make sure your terminal supports this | ||
| 220 | vim.o.termguicolors = true | ||
| 221 | |||
| 222 | -- [[ Basic Keymaps ]] | ||
| 223 | |||
| 224 | -- Keymaps for better default experience | ||
| 225 | -- See `:help vim.keymap.set()` | ||
| 226 | vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) | ||
| 227 | |||
| 228 | -- Remap for dealing with word wrap | ||
| 229 | vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) | ||
| 230 | vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) | ||
| 231 | |||
| 232 | -- [[ Highlight on yank ]] | ||
| 233 | -- See `:help vim.highlight.on_yank()` | ||
| 234 | local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) | ||
| 235 | vim.api.nvim_create_autocmd('TextYankPost', { | ||
| 236 | callback = function() | ||
| 237 | vim.highlight.on_yank() | ||
| 238 | end, | ||
| 239 | group = highlight_group, | ||
| 240 | pattern = '*', | ||
| 241 | }) | ||
| 242 | |||
| 243 | -- [[ Configure Telescope ]] | ||
| 244 | -- See `:help telescope` and `:help telescope.setup()` | ||
| 245 | require('telescope').setup { | ||
| 246 | defaults = { | ||
| 247 | mappings = { | ||
| 248 | i = { | ||
| 249 | ['<C-u>'] = false, | ||
| 250 | ['<C-d>'] = false, | ||
| 251 | }, | ||
| 252 | }, | ||
| 253 | }, | ||
| 254 | } | ||
| 255 | |||
| 256 | -- Enable telescope fzf native, if installed | ||
| 257 | pcall(require('telescope').load_extension, 'fzf') | ||
| 258 | |||
| 259 | -- See `:help telescope.builtin` | ||
| 260 | vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) | ||
| 261 | vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) | ||
| 262 | vim.keymap.set('n', '<leader>/', function() | ||
| 263 | -- You can pass additional configuration to telescope to change theme, layout, etc. | ||
| 264 | require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { | ||
| 265 | winblend = 10, | ||
| 266 | previewer = false, | ||
| 267 | }) | ||
| 268 | end, { desc = '[/] Fuzzily search in current buffer' }) | ||
| 269 | |||
| 270 | vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) | ||
| 271 | vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
| 272 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
| 273 | vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) | ||
| 274 | vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) | ||
| 275 | vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) | ||
| 276 | |||
| 277 | -- [[ Configure Treesitter ]] | ||
| 278 | -- See `:help nvim-treesitter` | ||
| 279 | require('nvim-treesitter.configs').setup { | ||
| 280 | -- Add languages to be installed here that you want installed for treesitter | ||
| 281 | ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, | ||
| 282 | |||
| 283 | -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | ||
| 284 | auto_install = false, | ||
| 285 | |||
| 286 | highlight = { enable = true }, | ||
| 287 | indent = { enable = true, disable = { 'python' } }, | ||
| 288 | incremental_selection = { | ||
| 289 | enable = true, | ||
| 290 | keymaps = { | ||
| 291 | init_selection = '<c-space>', | ||
| 292 | node_incremental = '<c-space>', | ||
| 293 | scope_incremental = '<c-s>', | ||
| 294 | node_decremental = '<M-space>', | ||
| 295 | }, | ||
| 296 | }, | ||
| 297 | textobjects = { | ||
| 298 | select = { | ||
| 299 | enable = true, | ||
| 300 | lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim | ||
| 301 | keymaps = { | ||
| 302 | -- You can use the capture groups defined in textobjects.scm | ||
| 303 | ['aa'] = '@parameter.outer', | ||
| 304 | ['ia'] = '@parameter.inner', | ||
| 305 | ['af'] = '@function.outer', | ||
| 306 | ['if'] = '@function.inner', | ||
| 307 | ['ac'] = '@class.outer', | ||
| 308 | ['ic'] = '@class.inner', | ||
| 309 | }, | ||
| 310 | }, | ||
| 311 | move = { | ||
| 312 | enable = true, | ||
| 313 | set_jumps = true, -- whether to set jumps in the jumplist | ||
| 314 | goto_next_start = { | ||
| 315 | [']m'] = '@function.outer', | ||
| 316 | [']]'] = '@class.outer', | ||
| 317 | }, | ||
| 318 | goto_next_end = { | ||
| 319 | [']M'] = '@function.outer', | ||
| 320 | [']['] = '@class.outer', | ||
| 321 | }, | ||
| 322 | goto_previous_start = { | ||
| 323 | ['[m'] = '@function.outer', | ||
| 324 | ['[['] = '@class.outer', | ||
| 325 | }, | ||
| 326 | goto_previous_end = { | ||
| 327 | ['[M'] = '@function.outer', | ||
| 328 | ['[]'] = '@class.outer', | ||
| 329 | }, | ||
| 330 | }, | ||
| 331 | swap = { | ||
| 332 | enable = true, | ||
| 333 | swap_next = { | ||
| 334 | ['<leader>a'] = '@parameter.inner', | ||
| 335 | }, | ||
| 336 | swap_previous = { | ||
| 337 | ['<leader>A'] = '@parameter.inner', | ||
| 338 | }, | ||
| 339 | }, | ||
| 340 | }, | ||
| 341 | } | ||
| 342 | |||
| 343 | -- Diagnostic keymaps | ||
| 344 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" }) | ||
| 345 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" }) | ||
| 346 | vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = "Open floating diagnostic message" }) | ||
| 347 | vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = "Open diagnostics list" }) | ||
| 348 | |||
| 349 | -- LSP settings. | ||
| 350 | -- This function gets run when an LSP connects to a particular buffer. | ||
| 351 | local on_attach = function(_, bufnr) | ||
| 352 | -- NOTE: Remember that lua is a real programming language, and as such it is possible | ||
| 353 | -- to define small helper and utility functions so you don't have to repeat yourself | ||
| 354 | -- many times. | ||
| 355 | -- | ||
| 356 | -- In this case, we create a function that lets us more easily define mappings specific | ||
| 357 | -- for LSP related items. It sets the mode, buffer and description for us each time. | ||
| 358 | local nmap = function(keys, func, desc) | ||
| 359 | if desc then | ||
| 360 | desc = 'LSP: ' .. desc | ||
| 361 | end | ||
| 362 | |||
| 363 | vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) | ||
| 364 | end | ||
| 365 | |||
| 366 | nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') | ||
| 367 | nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') | ||
| 368 | |||
| 369 | nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') | ||
| 370 | nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') | ||
| 371 | nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') | ||
| 372 | nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') | ||
| 373 | nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') | ||
| 374 | nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') | ||
| 375 | |||
| 376 | -- See `:help K` for why this keymap | ||
| 377 | nmap('K', vim.lsp.buf.hover, 'Hover Documentation') | ||
| 378 | nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') | ||
| 379 | |||
| 380 | -- Lesser used LSP functionality | ||
| 381 | nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') | ||
| 382 | nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') | ||
| 383 | nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') | ||
| 384 | nmap('<leader>wl', function() | ||
| 385 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||
| 386 | end, '[W]orkspace [L]ist Folders') | ||
| 387 | |||
| 388 | -- Create a command `:Format` local to the LSP buffer | ||
| 389 | vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | ||
| 390 | vim.lsp.buf.format() | ||
| 391 | end, { desc = 'Format current buffer with LSP' }) | ||
| 392 | end | ||
| 393 | |||
| 394 | -- Enable the following language servers | ||
| 395 | -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
| 396 | -- | ||
| 397 | -- Add any additional override configuration in the following tables. They will be passed to | ||
| 398 | -- the `settings` field of the server config. You must look up that documentation yourself. | ||
| 399 | local servers = { | ||
| 400 | -- clangd = {}, | ||
| 401 | -- gopls = {}, | ||
| 402 | -- pyright = {}, | ||
| 403 | -- rust_analyzer = {}, | ||
| 404 | -- tsserver = {}, | ||
| 405 | |||
| 406 | lua_ls = { | ||
| 407 | Lua = { | ||
| 408 | workspace = { checkThirdParty = false }, | ||
| 409 | telemetry = { enable = false }, | ||
| 410 | }, | ||
| 411 | }, | ||
| 412 | } | ||
| 413 | |||
| 414 | -- Setup neovim lua configuration | ||
| 415 | require('neodev').setup() | ||
| 416 | |||
| 417 | -- nvim-cmp supports additional completion capabilities, so broadcast that to servers | ||
| 418 | local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
| 419 | capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | ||
| 420 | |||
| 421 | -- Ensure the servers above are installed | ||
| 422 | local mason_lspconfig = require 'mason-lspconfig' | ||
| 423 | |||
| 424 | mason_lspconfig.setup { | ||
| 425 | ensure_installed = vim.tbl_keys(servers), | ||
| 426 | } | ||
| 427 | |||
| 428 | mason_lspconfig.setup_handlers { | ||
| 429 | function(server_name) | ||
| 430 | require('lspconfig')[server_name].setup { | ||
| 431 | capabilities = capabilities, | ||
| 432 | on_attach = on_attach, | ||
| 433 | settings = servers[server_name], | ||
| 434 | } | ||
| 435 | end, | ||
| 436 | } | ||
| 437 | |||
| 438 | -- nvim-cmp setup | ||
| 439 | local cmp = require 'cmp' | ||
| 440 | local luasnip = require 'luasnip' | ||
| 441 | |||
| 442 | luasnip.config.setup {} | ||
| 443 | |||
| 444 | cmp.setup { | ||
| 445 | snippet = { | ||
| 446 | expand = function(args) | ||
| 447 | luasnip.lsp_expand(args.body) | ||
| 448 | end, | ||
| 449 | }, | ||
| 450 | mapping = cmp.mapping.preset.insert { | ||
| 451 | ['<C-n>'] = cmp.mapping.select_next_item(), | ||
| 452 | ['<C-p>'] = cmp.mapping.select_prev_item(), | ||
| 453 | ['<C-d>'] = cmp.mapping.scroll_docs(-4), | ||
| 454 | ['<C-f>'] = cmp.mapping.scroll_docs(4), | ||
| 455 | ['<C-Space>'] = cmp.mapping.complete {}, | ||
| 456 | ['<CR>'] = cmp.mapping.confirm { | ||
| 457 | behavior = cmp.ConfirmBehavior.Replace, | ||
| 458 | select = true, | ||
| 459 | }, | ||
| 460 | ['<Tab>'] = cmp.mapping(function(fallback) | ||
| 461 | if cmp.visible() then | ||
| 462 | cmp.select_next_item() | ||
| 463 | elseif luasnip.expand_or_jumpable() then | ||
| 464 | luasnip.expand_or_jump() | ||
| 465 | else | ||
| 466 | fallback() | ||
| 467 | end | ||
| 468 | end, { 'i', 's' }), | ||
| 469 | ['<S-Tab>'] = cmp.mapping(function(fallback) | ||
| 470 | if cmp.visible() then | ||
| 471 | cmp.select_prev_item() | ||
| 472 | elseif luasnip.jumpable(-1) then | ||
| 473 | luasnip.jump(-1) | ||
| 474 | else | ||
| 475 | fallback() | ||
| 476 | end | ||
| 477 | end, { 'i', 's' }), | ||
| 478 | }, | ||
| 479 | sources = { | ||
| 480 | { name = 'nvim_lsp' }, | ||
| 481 | { name = 'luasnip' }, | ||
| 482 | }, | ||
| 483 | } | ||
| 484 | |||
| 485 | -- The line beneath this is called `modeline`. See `:help modeline` | ||
| 486 | -- vim: ts=2 sts=2 sw=2 et | ||