HOME = os.getenv("HOME") -- Configure the clipboard to access the \"+ and \"* registers -- (not sure why I need this now and didn't before) vim.opt.clipboard = "unnamedplus,unnamed" -- Spaces indentation vim.opt.expandtab = true vim.opt.tabstop = 2 vim.opt.shiftwidth = 2 -- Show whitespace vim.opt.listchars = "eol:¬,tab:>-,trail:~,extends:>,precedes:<,space:·" -- Show line numbers vim.opt.number = true -- Default: split right vim.opt.splitright = true -- Highlight cursor line vim.opt.cursorline = true -- Enable folding vim.opt.foldmethod = "indent" vim.opt.foldlevel = 99 -- Terminal colors vim.opt.termguicolors = true -- Cursor line context vim.opt.scrolloff = 5 -- netrw vim.g.netrw_winsize = 25 vim.g.netrw_liststyle = 3 -- tree style listing -- Escape exits terminal mode vim.api.nvim_set_keymap("t", "", "", { noremap = true }) -- Sane vim split naviagation (via Gaslight blog) vim.api.nvim_set_keymap("n", "", "j", { noremap = true }) vim.api.nvim_set_keymap("n", "", "k", { noremap = true }) vim.api.nvim_set_keymap("n", "", "h", { noremap = true }) vim.api.nvim_set_keymap("n", "", "l", { noremap = true }) vim.api.nvim_set_keymap("t", "", "j", { noremap = true }) vim.api.nvim_set_keymap("t", "", "k", { noremap = true }) vim.api.nvim_set_keymap("t", "", "h", { noremap = true }) vim.api.nvim_set_keymap("t", "", "l", { noremap = true }) -- vim-plug vim.cmd([[ if empty(glob('~/.vim/autoload/plug.vim')) silent !curl -fLo ~/.config/local/share/nvim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall --sync | source $MYVIMRC endif function! Cond(cond, ...) let opts = get(a:000, 0, {}) return a:cond ? extend(opts, { 'on': [], 'for': [] }) endfunction call plug#begin('~/.config/nvim/plugged') Plug 'williamboman/mason.nvim' Plug 'williamboman/mason-lspconfig.nvim' Plug 'neovim/nvim-lspconfig' Plug 'nvimdev/lspsaga.nvim' Plug 'nvim-lualine/lualine.nvim' Plug 'nvim-tree/nvim-web-devicons' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim', { 'branch': '0.1.x' } Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' } Plug 'neovim/nvim-lspconfig' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-cmdline' Plug 'hrsh7th/nvim-cmp' Plug 'hrsh7th/cmp-vsnip' Plug 'hrsh7th/vim-vsnip' Plug 'tpope/vim-fugitive' Plug 'lewis6991/gitsigns.nvim' Plug 'dracula/vim', { 'as': 'dracula' } Plug 'tpope/vim-surround' call plug#end() ]]) require('mason').setup() require('mason-lspconfig').setup() require('lualine').setup { options = { theme = 'dracula' }, tabline = { lualine_a = { 'buffers' }, } } local builtin = require('telescope.builtin') vim.keymap.set('n', 'ff', builtin.find_files, {}) vim.keymap.set('n', 'fg', builtin.live_grep, {}) vim.keymap.set('n', 'fb', builtin.buffers, {}) vim.keymap.set('n', 'fh', builtin.help_tags, {}) -------------------- -- nvim-lspconfig -- -------------------- -- Setup language servers. local lua_ls_setup = { settings = { Lua = { runtime = { -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) version = "LuaJIT", }, diagnostics = { -- Get the language server to recognize the `vim` global globals = { "vim" }, }, workspace = { -- Make the server aware of Neovim runtime files library = vim.api.nvim_get_runtime_file("", true), checkThirdParty = false, }, -- Do not send telemetry data containing a randomized but unique identifier telemetry = { enable = false, }, }, }, } local capabilities = require('cmp_nvim_lsp').default_capabilities() local lspconfig = require('lspconfig') lspconfig.gopls.setup {capabilities = capabilities} lspconfig.lua_ls.setup(lua_ls_setup) lspconfig.pyright.setup {capabilities = capabilities} lspconfig.tsserver.setup {capabilities = capabilities} lspconfig.rust_analyzer.setup { -- Server-specific settings. See `:help lspconfig-setup` capabilities = capabilities, settings = { ['rust-analyzer'] = {}, }, } -- Global mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions vim.keymap.set('n', 'e', vim.diagnostic.open_float) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) vim.keymap.set('n', ']d', vim.diagnostic.goto_next) vim.keymap.set('n', 'q', vim.diagnostic.setloclist) -- Use LspAttach autocommand to only map the following keys -- after the language server attaches to the current buffer vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function(ev) -- Enable completion triggered by vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local opts = { buffer = ev.buf } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) -- This setting steps on my split navigation setting, so I changed it -- to the probably harmless F9. -- vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts) vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, opts) end, }) -- Set up nvim-cmp. local cmp = require'cmp' cmp.setup({ snippet = { -- REQUIRED - you must specify a snippet engine expand = function(args) vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. end, }, window = { -- completion = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'vsnip' }, -- For vsnip users. }, { { name = 'buffer' }, }) }) -- Set configuration for specific filetype. cmp.setup.filetype('gitcommit', { sources = cmp.config.sources({ { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). }, { { name = 'buffer' }, }) }) -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) require('gitsigns').setup({ signs = { add = { text = '│' }, change = { text = '│' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, untracked = { text = '┆' }, }, signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` numhl = false, -- Toggle with `:Gitsigns toggle_numhl` linehl = false, -- Toggle with `:Gitsigns toggle_linehl` word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` watch_gitdir = { follow_files = true }, attach_to_untracked = true, current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` current_line_blame_opts = { virt_text = true, virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' delay = 1000, ignore_whitespace = false, }, current_line_blame_formatter = ', - ', sign_priority = 6, update_debounce = 100, status_formatter = nil, -- Use default max_file_length = 40000, -- Disable if file is longer than this (in lines) preview_config = { -- Options passed to nvim_open_win border = 'single', style = 'minimal', relative = 'cursor', row = 0, col = 1 }, yadm = { enable = false }, 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', ']c', function() if vim.wo.diff then return ']c' end vim.schedule(function() gs.next_hunk() end) return '' end, {expr=true}) map('n', '[c', function() if vim.wo.diff then return '[c' end vim.schedule(function() gs.prev_hunk() end) return '' end, {expr=true}) -- Actions map('n', 'hs', gs.stage_hunk) map('n', 'hr', gs.reset_hunk) map('v', 'hs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) map('v', 'hr', function() gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) map('n', 'hS', gs.stage_buffer) map('n', 'hu', gs.undo_stage_hunk) map('n', 'hR', gs.reset_buffer) map('n', 'hp', gs.preview_hunk) map('n', 'hb', function() gs.blame_line{full=true} end) map('n', 'tb', gs.toggle_current_line_blame) map('n', 'hd', gs.diffthis) map('n', 'hD', function() gs.diffthis('~') end) map('n', 'td', gs.toggle_deleted) end }) require('lspsaga').setup() -- Switch syntax highlighting on vim.cmd("syntax enable") -- Set color scheme vim.cmd("colorscheme dracula") -- Temporary file locations vim.opt.backupdir = ".backup/," .. HOME .. "/.backup/,/tmp//" vim.opt.directory = ".swp/," .. HOME .. "/.swp/,/tmp//"