-- vim.opt.runtimepath:append(',~/.config/nvim/lua') require "plugin" -- Automatically source and re-compile packer whenever you save this init.lua local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true }) vim.api.nvim_create_autocmd('BufWritePost', { command = 'source | silent! LspStop | silent! LspStart | PackerCompile', group = packer_group, pattern = vim.fn.expand '$MYVIMRC', }) require "option" -- file explorer setup require("nvim-tree").setup() -- bufferline setup require("bufferline").setup{ options = { offsets = { { filetype = "NvimTree", text = "File Explorer", highlight = "Directory", separator = true -- use a "true" to enable the default, or set your own character } }, } } -- lastplace setup require("nvim-lastplace").setup{ lastplace_ignore_buftype = { "quickfix", "nofile", "help" }, lastplace_ignore_filetype = { "gitcommit", "gitrebase", "svn", "hgcommit", }, lastplace_open_folds = true, } -- Set lualine as statusline -- See `:help lualine.txt` require('lualine').setup { options = { icons_enabled = false, theme = 'sonokai', component_separators = '|', section_separators = '', }, } -- Enable Comment.nvim require('Comment').setup{ opleader = { ---Line-comment keymap line = '/', ---Block-comment keymap block = 'gb', }, } -- Enable `lukas-reineke/indent-blankline.nvim` -- See `:help indent_blankline.txt` require('ibl').setup { indent = {char = '┊'}, -- show_trailing_blankline_indent = false, } -- Gitsigns -- See `:help gitsigns.txt` require('gitsigns').setup { signs = { add = { text = '+' }, change = { text = '~' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, }, on_attach = function(bufnr) local gs = package.loaded.gitsigns local function map(mode, l, r, opts) opts = opts or {} opts.buffer = bufnr vim.keymap.set(mode, l, r, opts) end -- Navigation map({ 'n', 'v' }, ']c', function() if vim.wo.diff then return ']c' end vim.schedule(function() gs.next_hunk() end) return '' end, { expr = true, desc = 'Jump to next hunk' }) map({ 'n', 'v' }, '[c', function() if vim.wo.diff then return '[c' end vim.schedule(function() gs.prev_hunk() end) return '' end, { expr = true, desc = 'Jump to previous hunk' }) -- Actions -- visual mode map('v', 'gs', function() gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'stage git hunk' }) map('v', 'gr', function() gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'reset git hunk' }) -- normal mode map('n', 'gs', gs.stage_hunk, { desc = 'git stage hunk' }) map('n', 'gr', gs.reset_hunk, { desc = 'git reset hunk' }) map('n', 'gS', gs.stage_buffer, { desc = 'git Stage buffer' }) map('n', 'gu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) map('n', 'gR', gs.reset_buffer, { desc = 'git Reset buffer' }) map('n', 'gp', gs.preview_hunk, { desc = 'preview git hunk' }) map('n', 'gb', function() gs.blame_line { full = false } end, { desc = 'git blame line' }) map('n', 'gd', gs.diffthis, { desc = 'git diff against index' }) map('n', 'gD', function() gs.diffthis '~' end, { desc = 'git diff against last commit' }) -- Toggles map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) -- Text object map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) end, } -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` require('telescope').setup { defaults = { mappings = { i = { [''] = false, [''] = false, }, }, }, } require "keymap" -- LSP settings. -- This function gets run when an LSP connects to a particular buffer. local on_attach = function(_, bufnr) -- NOTE: Remember that lua is a real programming language, and as such it is possible -- to define small helper and utility functions so you don't have to repeat yourself -- many times. -- -- In this case, we create a function that lets us more easily define mappings specific -- for LSP related items. It sets the mode, buffer and description for us each time. local nmap = function(keys, func, desc) -- if desc then -- desc = 'LSP: ' .. desc -- end vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) end nmap('lr', vim.lsp.buf.rename, 'Rename') nmap('lc', vim.lsp.buf.code_action, 'Code Action') nmap('gd', vim.lsp.buf.definition, 'Goto Definition') nmap('gr', require('telescope.builtin').lsp_references, 'Goto References') nmap('gI', vim.lsp.buf.implementation, 'Goto Implementation') nmap('D', vim.lsp.buf.type_definition, 'Type Definition') nmap('gl', vim.diagnostic.open_float, 'Current line diagnostics') nmap('ls', require('telescope.builtin').lsp_document_symbols, 'Document Symbols') nmap('lw', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Workspace Symbols') -- See `:help K` for why this keymap nmap('K', vim.lsp.buf.hover, 'Hover Documentation') nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') -- Lesser used LSP functionality nmap('gD', vim.lsp.buf.declaration, 'Goto Declaration') -- nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') -- nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') -- nmap('wl', function() -- print(vim.inspect(vim.lsp.buf.list_workspace_folders())) -- end, '[W]orkspace [L]ist Folders') -- -- Create a command `:Format` local to the LSP buffer vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() end, { desc = 'Format current buffer with LSP' }) end -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter ensure_installed = { 'c', 'cpp', 'rust', 'go', 'lua', 'python', 'rust', 'typescript', 'tsx', 'help', 'vim', }, autotag = { enable = true, enable_close = true, enable_close_on_slash = true, }, highlight = { enable = true }, indent = { enable = true, disable = { 'python', 'c', 'cpp' } }, incremental_selection = { enable = true, keymaps = { init_selection = '', node_incremental = '', scope_incremental = '', node_decremental = '', }, }, textobjects = { select = { enable = true, lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim keymaps = { -- You can use the capture groups defined in textobjects.scm ['aa'] = '@parameter.outer', ['ia'] = '@parameter.inner', ['af'] = '@function.outer', ['if'] = '@function.inner', ['ac'] = '@class.outer', ['ic'] = '@class.inner', }, }, move = { enable = true, set_jumps = true, -- whether to set jumps in the jumplist goto_next_start = { [']m'] = '@function.outer', [']]'] = '@class.outer', }, goto_next_end = { [']M'] = '@function.outer', [']['] = '@class.outer', }, goto_previous_start = { ['[m'] = '@function.outer', ['[['] = '@class.outer', }, goto_previous_end = { ['[M'] = '@function.outer', ['[]'] = '@class.outer', }, }, swap = { enable = true, swap_next = { ['a'] = '@parameter.inner', }, swap_previous = { ['A'] = '@parameter.inner', }, }, }, } -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- -- Add any additional override configuration in the following tables. They will be passed to -- the `settings` field of the server config. You must look up that documentation yourself. local servers = { clangd = {}, gopls = {}, -- pyright = {}, rust_analyzer = {}, -- tsserver = {}, lua_ls = { Lua = { workspace = { checkThirdParty = false }, telemetry = { enable = false }, }, }, } local rainbow_delimiters = require 'rainbow-delimiters' vim.g.rainbow_delimiters = { strategy = { [''] = rainbow_delimiters.strategy['global'], vim = rainbow_delimiters.strategy['local'], }, query = { [''] = 'rainbow-delimiters', lua = 'rainbow-blocks', }, highlight = { 'RainbowDelimiterRed', 'RainbowDelimiterYellow', 'RainbowDelimiterBlue', 'RainbowDelimiterOrange', 'RainbowDelimiterGreen', 'RainbowDelimiterViolet', 'RainbowDelimiterCyan', }, } -- Setup neovim lua configuration require('neodev').setup() -- -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -- Setup mason so it can manage external tooling require('mason').setup() -- Ensure the servers above are installed local mason_lspconfig = require 'mason-lspconfig' mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers), } mason_lspconfig.setup_handlers { function(server_name) require('lspconfig')[server_name].setup { capabilities = capabilities, on_attach = on_attach, settings = servers[server_name], } end, } -- Turn on lsp status information -- require('fidget').setup() -- highlight trailing whitespace vim.cmd([[ autocmd VimEnter * autocmd WinEnter * let w:created=1 autocmd VimEnter * let w:created=1 highlight WhitespaceEOL ctermbg=red ctermfg=white guibg=#592929 autocmd BufWritePost * \ if !exists('w:created') | call matchadd('WhitespaceEOL', '\s\+$') | endif call matchadd('WhitespaceEOL', '\s\+$') ]]) local hop = require('hop') local directions = require('hop.hint').HintDirection vim.keymap.set('n', 'f', function() hop.hint_words({ direction = directions.AFTER_CURSOR, current_line_only = false }) end, {remap=true}) vim.keymap.set('n', 'F', function() hop.hint_words({ direction = directions.BEFORE_CURSOR, current_line_only = false }) end, {remap=true}) local tabnine = require('cmp_tabnine.config') tabnine:setup({ max_lines = 1000, max_num_results = 20, sort = true, run_on_every_keystroke = true, snippet_placeholder = '..', ignored_file_types = { -- default is not to ignore -- uncomment to ignore in lua: -- lua = true }, show_prediction_strength = false }) -- nvim-cmp setup local cmp = require 'cmp' local luasnip = require 'luasnip' -- load luasnip snippets -- require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/luasnip/"}) cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() else fallback() end end, { 'i', 's' }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end, { 'i', 's' }), }, sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'cmp_tabnine' }, }, } -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et