Skip to main content
1 of 7

Trying to share nvim and vim config, but something isn't right: LSP isn't working in nvim, but in vim

now user, please bear over with me.

I'm trying to share my ~/.vimrc config by sourcing it from ~/.config/nvim/init.vim. I notice that "neoclide/coc.nvim" works for vim, but not for nvim. I think I need to understand why, before I continue messing around too much. Let's start simple, the ~/.config/nvim/init.vim is simple and shown here:

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath=&runtimepath
source ~/.vimrc

The ~/.vimrc file was made earlier, so it's bigger and shown here:

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Config only for VIM - not nvim:
if !has('nvim')
  " Get the defaults that most users want. VIMRUNTIME=/usr/share/vim/vim82
  source $VIMRUNTIME/defaults.vim
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")
  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!
  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78
  augroup END

else
  set autoindent        " always set autoindenting on
endif " has("autocmd")


" Add optional packages.
if has('syntax') && has('eval')
  packadd! matchit
endif

" Automatically refresh file, if saved/updated from outside:
set autoread

:set number relativenumber
:augroup numbertoggle
:  autocmd!
:  autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
:  autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
:augroup END

" Do not wrap long lines, onto the following line:
:set nowrap
set clipboard=unnamedplus

let g:xml_syntax_folding=1
au FileType xml setlocal foldmethod=syntax
" Press F9 to toggle folds - from: https://vim.fandom.com/wiki/Folding
inoremap <F9> <C-O>za
nnoremap <F9> za
onoremap <F9> <C-C>za
vnoremap <F9> zf
set foldlevel=2

:set ignorecase

" --- Vim plugin manager: ---
" See: /usr/share/vim-plug/vimrc.sample for more!
call plug#begin('~/.vim/plugged')
" From: https://vimawesome.com/plugin/coc-nvim ==> Use release branch (recommend)
Plug 'neoclide/coc.nvim', {'branch': 'release'}

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'rudrab/vimf90' 
call plug#end()

" Get LSP support for Fortran:
let g:coc_start_at_startup = 0
augroup coc
  autocmd!
  autocmd VimEnter * :silent CocStart
augroup end

" From: https://github.com/neoclide/coc.nvim
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
"
" GoTo code navigation.
" CTRL+O to go back + use ":jumps" to see what's in the jump stack! 
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
" WARNING: "gr" is super powerful, but wait up to around 4-5 seconds before
" results show up!
nmap <silent> gr <Plug>(coc-references)
  1. If I open a source code file using vim, after around 10 seconds in the lower left corner it says: "[coc.nvim] FORTLS initialization complete", which tells that the LSP/language server is now running, it's working and I can use the "coc-definition" etc commands to jump around.
  2. If I open exactly the same file using nvim, LSP doesn't work: I wait and wait, it never says "initialization complete" and also the "gd" or "coc-definition" commands won't work, so I can't jump around. However, the "F9" toggle folding does work...

I was suspecting it had something to do with the "plugged"/plugin manager stuff. In neovim I then typed ":PlugInstall" and it replied with "Finishing ... Done!" followed by "Already installed" to nerdtree, vimf90 and coc.nvim. But after restarting, same thing happens, seems like it isn't loading the FORTLS (language server)? Why, I don't understand? How can I debug this or understand what is wrong? Thanks for any ideas!