From 1b98f91de913f62f0844c7efb2349501cbb6bc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Fri, 1 Jul 2022 23:29:26 +0200 Subject: [PATCH] Add Neovim config --- .config/nvim/init.vim | 4 + .nvimrc | 308 ++++++++++++++++++++++++++++++++++++++++++ .vimrc | 17 ++- 3 files changed, 320 insertions(+), 9 deletions(-) create mode 100644 .config/nvim/init.vim create mode 100644 .nvimrc diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim new file mode 100644 index 0000000..f32e141 --- /dev/null +++ b/.config/nvim/init.vim @@ -0,0 +1,4 @@ +set runtimepath^=~/.nvim runtimepath+=~/.nvim/after +let &packpath=&runtimepath +source ~/.nvimrc +set undodir=~/.nvim/neovim/undodir/ diff --git a/.nvimrc b/.nvimrc new file mode 100644 index 0000000..49825e1 --- /dev/null +++ b/.nvimrc @@ -0,0 +1,308 @@ +set nocompatible +syntax on +let VIMHOME = split(&rtp, ",")[0] +let $VIMHOME = VIMHOME + +" vim-plug +call plug#begin(VIMHOME."/plugs") +" Plug 'Valloric/YouCompleteMe' +Plug 'williamboman/nvim-lsp-installer' +Plug 'nixprime/cpsm', {'do': './install.sh'} +Plug 'kien/ctrlp.vim' +Plug 'prabirshrestha/asyncomplete.vim' +Plug 'prabirshrestha/vim-lsp' +Plug 'prabirshrestha/asyncomplete-lsp.vim' +Plug 'ConradIrwin/vim-bracketed-paste' +Plug 'NLKNguyen/papercolor-theme' +Plug 'Shougo/deoplete.nvim' +Plug 'christoomey/vim-tmux-navigator' +Plug 'cohama/lexima.vim', {'do': 'sed -i \"s/has(.nvim.) && //\" autoload/lexima/insmode.vim'} +Plug 'editorconfig/editorconfig-vim' +Plug 'gmarik/Vundle.vim' +Plug 'hdima/python-syntax' +Plug 'jeetsukumaran/vim-buffergator' +Plug 'kristijanhusak/vim-hybrid-material' +Plug 'lambdalisue/fern.vim' +Plug 'lervag/vimtex' +Plug 'neovimhaskell/haskell-vim' +Plug 'nvie/vim-flake8' +Plug 'octol/vim-cpp-enhanced-highlight' +Plug 'pangloss/vim-javascript' +Plug 'posva/vim-vue' +Plug 'rhysd/vim-grammarous' +Plug 'roxma/nvim-yarp' +Plug 'ervandew/supertab' +Plug 'roxma/vim-hug-neovim-rpc' +Plug 'tmux-plugins/vim-tmux' +Plug 'tmux-plugins/vim-tmux-focus-events' +Plug 'tomtom/tcomment_vim' +Plug 'vim-airline/vim-airline' +Plug 'vim-airline/vim-airline-themes' +Plug 'vim-scripts/indentpython.vim' +Plug 'vimwiki/vimwiki' +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' +call plug#end() + +let mapleader="," + + +:command W w +:command Q q +:command WQ wq +:command Wq wq +nnoremap j gj +nnoremap k gk +nnoremap +nnoremap + +" don't store .swp files in the file's own directory +" neither for .ext~ files +set directory=/home/user/.nvim/tmp/ +set backupdir=/home/user/.nvim/tmp/ + +" VimWiki +let g:vimwiki_key_mappings = { 'table_mappings': 0 } +let g:vimwiki_markdown_link_ext = 1 +autocmd FileType vimwiki setlocal shiftwidth=2 softtabstop=2 expandtab + + " Autoindent for filetype +filetype plugin indent on +set autoindent + +set encoding=utf-8 +set scrolloff=5 +set sidescrolloff=10 + +set completeopt-=preview + +set backspace=indent,eol,start + +" Splits +set splitbelow +set splitright + +" CtrlP +let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch'} +nnoremap :CtrlPBuffer +let g:cpsm_unicode=1 +let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] + +" Unsaved buffer switching +set hidden + +" Line numbering +set number +set numberwidth=4 +:set mouse=a + +" Allow xterm-key usage inside tmux +execute "set =\e[1;*A" +execute "set =\e[1;*B" +execute "set =\e[1;*C" +execute "set =\e[1;*D" + +" Persistent undo +set undodir=~/.nvim/undodir/ +set undofile +set undolevels=1000 +set undoreload=10000 + +" Searching +set ignorecase +set smartcase +set incsearch +set hlsearch +nnoremap :noh + +" Text wrapping +set lbr + +" Vimtex + +let g:tex_flavor = 'latex' + +" Tabs +if has("autocmd") + filetype plugin indent on + autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab +endif + +" Terminal colors +set t_Co=256 +set background=dark +let g:airline_theme="solarized" +let g:airline_solarized_bg="dark" + +set tabstop=4 +set shiftwidth=4 +set softtabstop=4 +set expandtab + +" Commenting +nnoremap c :TComment +nnoremap C :TCommentBlock +vnoremap c :TCommentInline +vnoremap C :TCommentBlock + +" Tab completion +set wildmode=longest,list +set wildmenu + +set guifont=Ubuntu\ Mono\ derivative\ Powerline\ 13 +let g:airline_powerline_fonts = 1 +set laststatus=2 +set ttimeoutlen=50 + +" Color scheme +syntax enable +let python_highlight_all=1 +let g:solarized_termcolors=256 +colorscheme hybrid_material + +" Remap u to y +vnoremap u y + +" Save clipboard on quit +autocmd VimLeave * call system("xsel -ib", getreg('+')) + +" Automatically remove trailing spaces +let blacklist = ['vimwiki'] +autocmd BufWritePre * if index(blacklist, &ft) < 0 | :%s/\s\+$//e + +" Use deoplete. +autocmd FileType python let g:deoplete#enable_at_startup = 1 + +" VPW: set filetype for .py3 +autocmd BufRead,BufNewFile *.py3 set filetype=python + +" Vue indent +autocmd FileType vue setlocal shiftwidth=2 softtabstop=2 expandtab +autocmd FileType javascript setlocal shiftwidth=2 softtabstop=2 expandtab +autocmd FileType vue syntax sync fromstart + +" Disable shift+k for manual lookup +map + +" Prolog: set filetype for .pl +autocmd BufRead,BufNewFile *.pl set filetype=prolog + +" Disable modelines, fix CVE +set modelines=0 +set nomodeline + +" Tab for completion +let g:SuperTabContextDefaultCompletionType = "" +let g:SuperTabDefaultCompletionType = "" + +lua <'] = 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. + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, { "i", "s" }), + + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s"}), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + }) +}) + + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = 'buffer' }, + }) + }) + + -- Use buffer source for `/` (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' } + }) + }) + + -- Setup lspconfig. + local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + require("nvim-lsp-installer").setup({ + automatic_installation = true, -- automatically detect which servers to install (based on which servers are set up via lspconfig) + }) + -- Replace with each lsp server you've enabled. + require('lspconfig')['pyright'].setup { + capabilities = capabilities + } + require('lspconfig')['texlab'].setup { + capabilities = capabilities + } + require('lspconfig')['ltex'].setup { + capabilities = capabilities + } +EOF + +" Lanuage server +nnoremap gd :lua vim.lsp.buf.definition() +set updatetime=300 +set signcolumn=number + +nmap n :lua vim.lsp.diagnostic.goto_next() +nmap p :lua vim.lsp.diagnostic.goto_prev() +nmap f :lua vim.lsp.buf.code_action() diff --git a/.vimrc b/.vimrc index 6b98c9a..dd15070 100644 --- a/.vimrc +++ b/.vimrc @@ -6,8 +6,8 @@ let $VIMHOME = VIMHOME " vim-plug call plug#begin(VIMHOME."/plugs") " Plug 'Valloric/YouCompleteMe' -" Plug 'kien/ctrlp.vim' -" Plug 'nixprime/cpsm', {'do': './install.sh'} +Plug 'nixprime/cpsm', {'do': './install.sh'} +Plug 'kien/ctrlp.vim' Plug 'prabirshrestha/asyncomplete.vim' Plug 'prabirshrestha/vim-lsp' Plug 'prabirshrestha/asyncomplete-lsp.vim' @@ -83,10 +83,10 @@ set splitbelow set splitright " CtrlP -" let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch'} -" nnoremap :CtrlPBuffer -" let g:cpsm_unicode=1 -" let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] +let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch'} +nnoremap :CtrlPBuffer +let g:cpsm_unicode=1 +let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] " Unsaved buffer switching set hidden @@ -207,6 +207,8 @@ nmap p (coc-diagnostic-prev) nmap n (coc-diagnostic-next) nmap f (coc-codeaction-line) vmap f (coc-codeaction-line) +nmap gd (lsp-definition) + nnoremap p :CocList yank vnoremap p :CocList yank @@ -232,8 +234,6 @@ Ext 'coc-yank' " FZF Preview nnoremap / :CocCommand fzf-preview.Lines --add-fzf-arg=--no-sort --add-fzf-arg=--query="'" -nnoremap :CocCommand fzf-preview.FromResources project_mru git buffer -nnoremap :CocCommand fzf-preview.Buffers nnoremap :CocCommand fzf-preview.ProjectGrepRecall nnoremap d :CocCommand fzf-preview.CocCurrentDiagnostics nnoremap d :CocCommand fzf-preview.CocCurrentDiagnostics @@ -255,7 +255,6 @@ function! s:on_lsp_buffer_enabled() abort setlocal omnifunc=lsp#complete setlocal signcolumn=yes if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif - nmap gd (lsp-definition) nmap gs (lsp-document-symbol-search) nmap gS (lsp-workspace-symbol-search) nmap gr (lsp-references)