From 4cbb1f271b5c18a78d4ee8b41cd9fb638150da29 Mon Sep 17 00:00:00 2001 From: Fabian Ising Date: Fri, 19 Jul 2024 14:37:43 +0200 Subject: [PATCH] [NVIM] YCM autoinstall, fix python path --- nvim/init.vim | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/nvim/init.vim b/nvim/init.vim index a973986..00fc469 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -1,10 +1,11 @@ set nocompatible filetype off + " Plugins " Note: on most systems, this will make the plugins reside in \ " ~/.local/share/nvim/plugged/ -let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' +let data_dir = has('nvim') ? stdpath('data') . '/site' : expand('~/.vim') if empty(glob(data_dir . '/autoload/plug.vim')) silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' let &runtimepath = &runtimepath @@ -14,6 +15,19 @@ endif " Disable Perl let g:loaded_perl_provider = 0 +" Find python +if has("macunix") + " Required for virtualenvs + let arch=substitute(system('uname -m'), '\n', '', '') + if arch == 'arm64' + let g:python_interpreter=expand("~/python-envs/neovim/bin/python3") + else + let g:python_interpreter="/usr/local/bin/python3" + endif +else + let g:python_interpreter = 'python3' +endif + call plug#begin() " Warn about plugin updates @@ -44,7 +58,17 @@ Plug 'ConradIrwin/vim-bracketed-paste' Plug 'christoomey/vim-tmux-navigator' " YouCompleteMe -Plug 'Valloric/YouCompleteMe' +function! BuildYCM(info) + " info is a dictionary with 3 fields + " - name: name of the plugin + " - status: 'installed', 'updated', or 'unchanged' + " - force: set on PlugInstall! or PlugUpdate! + if a:info.status == 'installed' || a:info.force + execute '!' . g:python_interpreter . ' ./install.py --all' + endif +endfunction + +Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM') } Plug 'rdnetto/YCM-Generator' " Git @@ -218,9 +242,11 @@ nmap T " YouCompleteMe let g:ycm_collect_identifiers_from_tags_files = 1 " Read from tag files -let g:ycm_global_ycm_extra_conf = '~/.config/nvim/.ycm_extra_conf.py' " Standard conf +let g:ycm_global_ycm_extra_conf = expand('~/.config/nvim/.ycm_extra_conf.py') " Standard conf let g:ycm_enable_diagnostic_signs = 0 " Do not show semantic error bar -let g:ycm_server_python_interpreter = 'python3' +let g:ycm_server_python_interpreter=g:python_interpreter +" Enable virtualenv autocompletion +let g:ycm_python_binary_path = 'python' let g:ycm_key_list_select_completion = ['', '', ''] let g:ycm_key_list_previous_completion = ['', '', ''] @@ -284,13 +310,4 @@ catch endtry let g:tex_flavor = "latex" autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab - -if has("macunix") - " Required for virtualenvs - let arch=substitute(system('uname -m'), '\n', '', '') - if arch == 'arm64' - let g:python3_host_prog="~/python-envs/neovim/bin/python3" - else - let g:python3_host_prog="/usr/local/bin/python3" - endif -endif +let g:python3_host_prog=g:python_interpreter