From 5299ae1e84e81496af21f47d786ca9867bf5dfd6 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Sun, 17 Jul 2022 09:28:46 -0400 Subject: [PATCH] add neovim config --- .config/nvim/init.vim | 144 +++++++++++++++++++++++++++++++++ .config/nvim/lua/lsp-setup.lua | 105 ++++++++++++++++++++++++ 2 files changed, 249 insertions(+) create mode 100644 .config/nvim/init.vim create mode 100644 .config/nvim/lua/lsp-setup.lua diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim new file mode 100644 index 0000000..9937448 --- /dev/null +++ b/.config/nvim/init.vim @@ -0,0 +1,144 @@ +set nocompatible + +" download vim-plug if missing +if empty(glob("~/.local/share/nvim/site/autoload/plug.vim")) + silent! execute '!curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' + autocmd VimEnter * silent! PlugInstall +endif + +call plug#begin(stdpath('data') . '/plugged') + Plug 'tpope/vim-sensible' + Plug 'tpope/vim-surround' + Plug 'tpope/vim-commentary' + Plug 'tpope/vim-repeat' + Plug 'tpope/vim-dispatch' + Plug 'tpope/vim-abolish' + + Plug 'tpope/vim-fugitive' + Plug 'tpope/vim-rhubarb' + + Plug 'christoomey/vim-sort-motion' + + Plug 'kana/vim-textobj-user' + Plug 'kana/vim-textobj-indent' + Plug 'kana/vim-textobj-line' + + Plug 'kyazdani42/nvim-web-devicons' + + Plug 'christoomey/vim-tmux-navigator' + + Plug 'preservim/nerdtree' + + Plug 'tversteeg/registers.nvim' + + Plug 'neovim/nvim-lspconfig' + Plug 'williamboman/nvim-lsp-installer' + Plug 'hrsh7th/cmp-nvim-lsp' + Plug 'hrsh7th/cmp-buffer' + Plug 'hrsh7th/cmp-path' + Plug 'hrsh7th/cmp-cmdline' + Plug 'hrsh7th/nvim-cmp' + + Plug 'duane9/nvim-rg' + + Plug 'tversteeg/registers.nvim' + + Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } + Plug 'ibhagwan/fzf-lua' + + Plug 'elixir-editors/vim-elixir' + + Plug 'dracula/vim', { 'as': 'dracula' } +call plug#end() + + +syntax enable +filetype plugin indent on + +if !exists('g:vscode') + colorscheme dracula +endif + +set number +set relativenumber + +set tabstop=2 +set shiftwidth=2 +set expandtab + +set mouse=a + +set cmdheight=2 + +set nobackup +set nowritebackup + +set spell + +let mapleader=',' + +nnoremap ; : +nnoremap q; q: +vnoremap ; : +vnoremap q; q: + +if exists('g:vscode') + nnoremap w :Write + nnoremap wq :Write:q +else + nnoremap w :w + nnoremap wq :wq +endif + +nnoremap q :q + +nnoremap :nohlsearch + +nnoremap :NERDTreeToggle + +" Copy to clipboard +vnoremap y "+y +nnoremap Y "+yg_ +nnoremap y "+y + +" Paste from clipboard +nnoremap p "+p +nnoremap P "+P +vnoremap p "+p +vnoremap P "+P + +nnoremap ~ :split ~/.config/nvim/init.vim +nnoremap so :so % + +nnoremap f lua require('fzf-lua').files() +nnoremap a lua require('fzf-lua').grep_project() + +" nnoremap gs :Git +nnoremap gs :Git +nnoremap gp :Git push --force-with-lease -u origin head +nnoremap gf :Git fetch +nnoremap gr :Git rebase origin/main +nnoremap gb :Git checkout -b + +if !exists('g:vscode') + luafile ~/.config/nvim/lua/lsp-setup.lua +endif + +" lua require('gitsigns').setup() + +lua << EOF + require("trouble").setup { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + } +EOF + +nnoremap o :only + +" Terminal mode +tnoremap +tnoremap h +tnoremap j +tnoremap k +tnoremap l diff --git a/.config/nvim/lua/lsp-setup.lua b/.config/nvim/lua/lsp-setup.lua new file mode 100644 index 0000000..96d1ade --- /dev/null +++ b/.config/nvim/lua/lsp-setup.lua @@ -0,0 +1,105 @@ +local lsp_installer = require("nvim-lsp-installer") + +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + -- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + -- buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + -- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + -- buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + -- buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + -- buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + -- buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + -- buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + -- buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) + -- buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) + -- buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) + -- buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) + -- buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + + if client.resolved_capabilities.document_formatting then + vim.cmd([[ + augroup LspFormatting + autocmd! * + autocmd BufWritePre lua vim.lsp.buf.formatting_sync() + augroup END + ]]) + end + + + -- Setup 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. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, + }, + mapping = { + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [''] = 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 = 'buffer' }, + }) + }) + + -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } + }) + + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) +end + +-- Register a handler that will be called for all installed servers. +-- Alternatively, you may also register handlers on specific server instances instead (see example below). +lsp_installer.on_server_ready(function(server) + local opts = { + on_attach = on_attach + } + + -- (optional) Customize the options passed to the server + -- if server.name == "tsserver" then + -- opts.root_dir = function() ... end + -- end + + -- This setup() function is exactly the same as lspconfig's setup function. + -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + server:setup(opts) +end)