Help debugging my beloved settings!

Hi everyone,

Fist time posting here, so sorry if I am doing anything wrong.

I have this old vim setup for R data science, that evolved into a nvim setup and which was updated to a PERFECT partially lua setup. It has everything the way I wanted. But somehow, with some upstream change it stopped working after I updated my packages.

The error is:

Error detected while processing /home/luis/.config/nvim/init.vim:
line  201:
E5108: Error executing lua ...are/nvimvimplug/nvim-lspconfig/lua/lspconfig/configs.lua:10: attempt to index local 'config_def' (a nil value)
stack traceback:
        ...are/nvimvimplug/nvim-lspconfig/lua/lspconfig/configs.lua:10: in function '__newindex'
        ...hare/nvimvimplug/nvim-lspinstall/lua/lspinstall/util.lua:15: in function 'extract_config'
        ...mplug/nvim-lspinstall/lua/lspinstall/servers/angular.lua:1: in main chunk
        [C]: in function 'require'
        ...e/nvimvimplug/nvim-lspinstall/lua/lspinstall/servers.lua:2: in main chunk
        [C]: in function 'require'
        ...cal/share/nvimvimplug/nvim-lspinstall/lua/lspinstall.lua:1: in main chunk
        [C]: in function 'require'
        /home/luis/.config/nvim/lua/lsp.lua:85: in function 'setup_servers'
        /home/luis/.config/nvim/lua/lsp.lua:113: in main chunk
        [C]: in function 'require'
        [string ":lua"]:1: in main chunk
Error detected while processing /home/luis/.local/share/nvimvimplug/vim-mucomplete/plugin/mucomplete.vim:
line   26:
E227: mapping already exists for ^I

it complains of a setup_server function within my lsp.lua file. See below:

local nvim_lsp = require('lspconfig')

-- lsp setup
-- Set Default Prefix.
-- Note: You can set a prefix per lsp server in the lv-globals.lua file
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    virtual_text = false,
    -- {
    --   prefix = "",
    --   spacing = 0,
    -- },
    signs = true,
    underline = true
  }
)


-- symbols for autocomplete
vim.lsp.protocol.CompletionItemKind = {
    "   (Text) ",
    "   (Method)",
    "   (Function)",
    "   (Constructor)",
    " ﴲ  (Field)",
    "[] (Variable)",
    "   (Class)",
    " ﰮ  (Interface)",
    "   (Module)",
    " 襁 (Property)",
    "   (Unit)",
    "   (Value)",
    " 練 (Enum)",
    "   (Keyword)",
    "   (Snippet)",
    "   (Color)",
    "   (File)",
    "   (Reference)",
    "   (Folder)",
    "   (EnumMember)",
    " ﲀ  (Constant)",
    " ﳤ  (Struct)",
    "   (Event)",
    "   (Operator)",
    "   (TypeParameter)"
}

local function documentHighlight(client, bufnr)
    -- Set autocommands conditional on server_capabilities
    if client.resolved_capabilities.document_highlight then
        vim.api.nvim_exec(
            [[
      hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
      hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
      hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
      augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]],
            false
        )
    end
end

local lsp_config = {}

function lsp_config.common_on_attach(client, bufnr)
    documentHighlight(client, bufnr)
end
function lsp_config.tsserver_on_attach(client, bufnr)
    lsp_config.common_on_attach(client, bufnr)
    client.resolved_capabilities.document_formatting = false
end

local function make_config()
    return {
        -- map buffer local keybindings when the language server attaches
        on_attach = on_attach,
    }
end

local function setup_servers()
    require'lspinstall'.setup()
    local servers = require'lspinstall'.installed_servers()
    table.insert(servers, "r_language_server")
    for _, server in pairs(servers) do
        local config = make_config()
        -- language specific config
        if server == "html" then
            config.filetypes = {"html", "blade"};
        end
        if server == "php" then
            config.init_options = {
                licenceKey = "/Users/fabianmundt/iCloud/Documents/Sicherheitscodes/intelephense.txt";
            };
        end
        if server == "lua" then
            config.settings = {
                Lua = {
                    diagnostics = {
                        -- Get the language server to recognize the `vim` global
                        globals = {'vim'},
                    }
                }
            }
        end
        nvim_lsp[server].setup(config)
    end
end

setup_servers()

-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
require'lspinstall'.post_install_hook = function ()
    setup_servers() -- reload installed servers
    vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
end


-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
require'lspinstall'.post_install_hook = function ()
  setup_servers() -- reload installed servers
  vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
end



-- LSP omnifunc sync version for MUComplete chains
local omnifunc_cache
function _G.omnifunc_sync(findstart, base)
  local pos = vim.api.nvim_win_get_cursor(0)
  local line = vim.api.nvim_get_current_line()

  if findstart == 1 then
    -- Cache state of cursor line and position due to the fact that it will
    -- change at the second call to this function (with `findstart = 0`). See:
    -- https://github.com/vim/vim/issues/8510.
    -- This is needed because request to LSP server is made on second call.
    -- If not done, server's completion mechanics will operate on different
    -- document and position.
    omnifunc_cache = {pos = pos, line = line}

    -- On first call return column of completion start
    local line_to_cursor = line:sub(1, pos[2])
    return vim.fn.match(line_to_cursor, '\\k*$')
  end

  -- Restore cursor line and position to the state of first call
  vim.api.nvim_set_current_line(omnifunc_cache.line)
  vim.api.nvim_win_set_cursor(0, omnifunc_cache.pos)

  -- Make request
  local bufnr = vim.api.nvim_get_current_buf()
  local params = vim.lsp.util.make_position_params()
  local result = vim.lsp.buf_request_sync(bufnr, 'textDocument/completion', params, 2000)
  if not result then return {} end

  -- Transform request answer to list of completion matches
  local items = {}
  for _, item in pairs(result) do
    if not item.err then
      local matches = vim.lsp.util.text_document_completion_list_to_complete_items(item.result, base)
      vim.list_extend(items, matches)
    end
  end

  -- Restore back cursor line and position to the state of this call's start
  -- (avoids outcomes of Vim's internal line postprocessing)
  vim.api.nvim_set_current_line(line)
  vim.api.nvim_win_set_cursor(0, pos)

  return items
end
  • What on earth is wrong? I am not well versed in lua and I cant figure out what these error messages are trying to tell me.

My init.vim file:

" Installation  {{{
call plug#begin(stdpath('data') . 'vimplug')
  Plug 'prabirshrestha/asyncomplete.vim'
  Plug 'xianzhon/vim-code-runner'
  " Plug 'folke/which-key.nvim'
  Plug 'EdenEast/nightfox.nvim'
  Plug 'RishabhRD/popfix'
  Plug 'RishabhRD/nvim-cheat.sh'
  "Plug 'kristijanhusak/orgmode.nvim'
  Plug 'scrooloose/nerdtree'
  Plug 'github/copilot.vim'
  Plug 'skywind3000/asynctasks.vim'
  Plug 'skywind3000/asyncrun.vim'
  Plug 'jistr/vim-nerdtree-tabs'
  Plug 'nvim-lua/plenary.nvim'
  Plug 'nvim-lua/popup.nvim'
  Plug 'nvim-telescope/telescope.nvim'
  Plug 'neovim/nvim-lspconfig'
  Plug 'kabouzeid/nvim-lspinstall'
  Plug 'glepnir/lspsaga.nvim'
  Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
  Plug 'nvim-treesitter/nvim-treesitter-textobjects'
  Plug 'lifepillar/vim-mucomplete'
  " Plug 'itchyny/lightline.vim'
" Plug 'nvim-lualine/lualine.nvim'
  Plug 'glepnir/galaxyline.nvim'
  Plug 'kyazdani42/nvim-web-devicons'  " needed for galaxyline icons
  Plug 'tpope/vim-ragtag'
  Plug 'tpope/vim-surround'
  Plug 'tpope/vim-unimpaired'
  Plug 'imkmf/ctrlp-branches'
  Plug 'hara/ctrlp-colorscheme'
  Plug 'simplenote-vim/simplenote.vim'
  Plug 'tpope/vim-eunuch'
  Plug 'tpope/vim-fugitive'
  Plug 'rhysd/vim-grammarous'
  Plug 'yegappan/greplace'
  Plug 'tomtom/tcomment_vim'
  Plug 'ompugao/ctrlp-locate'
  Plug 'endel/ctrlp-filetype.vim'
  Plug 'suy/vim-ctrlp-commandline'
  Plug 'mbbill/desertex'
  Plug 'mhinz/vim-startify'
  Plug 'jalvesaq/Nvim-R'
  Plug 'metakirby5/codi.vim'
  Plug 'ctrlpvim/ctrlp.vim'
  Plug 'ryanoasis/vim-devicons'
  Plug 'tacahiroy/ctrlp-funky'
  Plug 'dbeecham/ctrlp-commandpalette.vim'
  Plug 'dense-analysis/ale'
  " Plug 'https://github.com/prashanthellina/follow-markdown-links'
  Plug 'phongnh/ctrlp-fzy-matcher'
  Plug 'halkn/ripgrep.vim'
call plug#end()
" }}}

" General settings {{{
if exists('+termguicolors')
  let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
  set termguicolors
endif

colorscheme duskfox

set guifont=Iosevka:h12
let g:molokai_original=1
let g:blamer_enabled = 1
let g:webdevicons_enable_ctrlp = 1
let g:disco_nobright = 1
let g:disco_red_error_only = 1
set bg=dark
let g:yui_comments = "fade"
let g:mapleader = "\<Space>"
let maplocalleader = "\<Space>"

set autochdir
set sessionoptions-=blank " This fixes a problem with nerdtree and sessions
set modelines=1
" set spell
" set spelllang=en
set mouse=a                   " Enable mouse support in insert mode.
set clipboard+=unnamedplus    " Use clipboard
set guioptions+=a
set backspace=indent,eol,start  " To make backscape work in all conditions.
set ma                          " To set mark a at current cursor location.
" set number                      " To switch the line numbers on.
set expandtab                   " To enter spaces when tab is pressed.
set smarttab                    " To use smart tabs.
set tabstop=2                   " Two chars for a tab
set shiftwidth=2
set autoindent                  " To copy indentation from current line
set si                          " To switch on smart indentation.
set ignorecase                  " To ignore case when searching.
set smartcase                   " When searching try to be smart about cases.
set hlsearch                    " To highlight search results.
set incsearch                   " To make search act like search in modern browsers.
set magic                       " For regular expressions turn magic on.
set showmatch                   " To show matching brackets when text indicator
set mat=2                       " How many tenths of a second to blink
syntax enable                   " Enable syntax highlighting.
set encoding=utf-8 fileencodings=ucs-bom,utf-8,gbk,gb18030,latin1 termencoding=utf-8
set nobackup                     " Turn off backup.
set nowb                         " Don't backup before overwriting a file.
set noswapfile                   " Don't create a swap file.
"set ffs=unix,dos,mac             " Use Unix as the standard file type.
"au! BufWritePost $MYVIMRC source %      " auto source when writing to init.vm alternatively you can run :source $MYVIMRC
" autocmd CursorHoldI * update " Saves when changing from insert mode

set undofile " Maintain undo history between sessions
set undodir=~/.vim/undodir


" Return to last edit position when opening files
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" Reload vimrc on save
" au BufWritePost ~/.config/nvim/*.{vim,lua} so $MYVIMRC
"map q :quit<CR>                 " Quit with q

" FIXME: (broken) ctrl s to save
noremap  <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <Esc>:update<CR>

" exit insert mode
" inoremap <C-c> <Esc>

" Find
map <C-f> /

" indent / deindent after selecting the text with (⇧ v), (.) to repeat.
vnoremap <Tab> >
vnoremap <S-Tab> <

" Cut, Paste, Copy
vmap <C-x> d
vmap <C-v> p
vmap <C-c> y

" Undo, Redo (broken)
nnoremap <C-z>  :undo<CR>
inoremap <C-z>  <Esc>:undo<CR>
nnoremap <C-y>  :redo<CR>
inoremap <C-y>  <Esc>:redo<CR>


" This mapping makes Ctrl-Tab switch between tabs.
" Ctrl-Shift-Tab goes the other way.
noremap <C-Tab> :tabnext<CR>
noremap <C-S-Tab> :tabprev<CR>

map <C-t> :tabnew<cr>

" switch between tabs with cmd+1, cmd+2,..."
map <C-1> 1gt
map <C-2> 2gt
map <C-3> 3gt
map <C-4> 4gt
map <C-5> 5gt
map <C-6> 6gt
map <C-7> 7gt
map <C-8> 8gt
map <C-9> 9gt

" until we have default MacVim shortcuts this is the only way to use it in
" insert mode
imap <C-1> <esc>1gt
imap <C-2> <esc>2gt
imap <C-3> <esc>3gt
imap <C-4> <esc>4gt
imap <C-5> <esc>5gt
imap <C-6> <esc>6gt
imap <C-7> <esc>7gt
imap <C-8> <esc>8gt
imap <C-9> <esc>9gt


set completeopt=noselect,noinsert,menuone,preview

" >> Lsp key bindings
nnoremap <silent> gd    <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> <C-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gD    <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> gr    <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gi    <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> K     <cmd>Lspsaga hover_doc<CR>
nnoremap <silent> <C-l> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> <C-k> <cmd>Lspsaga diagnostic_jump_prev<CR>
nnoremap <silent> <C-j> <cmd>Lspsaga diagnostic_jump_next<CR>
nnoremap <silent> gf    <cmd>lua vim.lsp.buf.formatting()<CR>
nnoremap <silent> gn    <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap <silent> ga    <cmd>Lspsaga code_action<CR>
xnoremap <silent> ga    <cmd>Lspsaga range_code_action<CR>
nnoremap <silent> gs    <cmd>Lspsaga signature_help<CR>

lua <<EOF
require("lsp")
require("treesitter")
require("statusbar")
EOF

" }}}

" R configuration - Nvim-R {{{
let g:rout_follow_colorscheme = 1 " R output is highlighted with current colorscheme
let g:Rout_more_colors = 1 " R commands in R output are highlighted
let g:R_pdfviewer="evince"
let g:R_objbr_opendf = 0
let g:R_objbr_openlist = 0


autocmd VimLeave * if exists("g:SendCmdToR") && string(g:SendCmdToR) != "function('SendCmdToR_fake')" | call RQuit("nosave") | endif " exit R when you exit the vim
autocmd FileType rmd set foldmarker=```{,```
autocmd FileType rmd setlocal foldmethod=marker


vmap <Space><Space> <Plug>RDSendSelection
nmap <Space><Space> <Plug>RDSendLine
" }}}

" CtrlP interface {{{
if executable('rg')
  let g:ctrlp_user_command = 'rg --files %s'
  let g:ctrlp_use_caching = 0
  let g:ctrlp_working_path_mode = 'rw'
endif

let g:ctrlp_match_func = { 'match': 'fzy_matcher#match' }


let g:ctrlp_map = '<C-p>'
let g:ctrlp_cmd = 'CtrlPCommandPalette'
let g:ctrlp_extensions = ['mixed',  'line', 'filetype', 'commandline', 'colorscheme', 'funky', 'branches']
let g:ripgrep_options='--hidden
                      \ -g "!/cache/*"
                      \ -g "!/data/*"
                      \ -g "!/reports/*"
                      \ -g "!/.git/*"
                      \ -- '

let g:commandPalette = {
    \ 'Ignorecase: Toggle': 'set ignorecase!',
    \ 'File: save and close': 'wq',
    \ 'Start R':  'call StartR("R")',
    \ 'Start Object Browser': 'call RObjBrowser()',
    \ 'Start Inim':  'T inim',
    \ 'Search files': 'CtrlPMixed',
    \ 'MRU': 'CtrlPMRU',
    \ 'Search within project': 'call feedkeys(":CtrlPRg ")',
    \ 'Search in this file': 'CtrlPLine',
    \ 'Commend lines': 'TComment',
    \ 'Check grammar': 'GrammarousCheck',
    \ 'Set filetype': 'CtrlPFiletype',
    \ 'Bye!': 'qa!',
    \ 'Command history': 'call ctrlp#init(ctrlp#commandline#id())',
    \ 'Find file anywhere in system': 'CtrlPLocate',
    \ 'Colorschemes': 'CtrlPColorscheme',
    \ 'Unfold all lines': 'call feedkeys("\<Space>zR\<CR>")',
    \ 'Fold all lines': 'call feedkeys("\<Space>zM\<CR>")',
    \ 'Unfold here': 'call feedkeys("\<Space>zo\<CR>")',
    \ 'Navigate sections of this file': 'CtrlPFunkyMulti',
    \ 'Run!': 'call feedkeys("\<Space>B\<CR>")',
    \ 'More!': 'Telescope builtin',
    \ 'Branches': 'CtrlPBranches'}
let g:ctrlp_match_window = 'results:100'



set wildignore+=*/.git/*,*/.hg/*,*/.svn/*
" }}}

" Startify {{{
function! s:gitModified()
    let files = systemlist('git ls-files -m 2>/dev/null')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

" same as above, but show untracked files, honouring .gitignore
function! s:gitUntracked()
    let files = systemlist('git ls-files -o --exclude-standard 2>/dev/null')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

let g:startify_lists = [
        \ { 'type': 'files',     'header': ['   MRU']            },
        \ { 'type': 'sessions',  'header': ['   Sessions']       },
        \ ]
" }}}

" Nerdtree {{{
nnoremap <C-n> :NERDTreeTabsToggle<CR>
" Start NERDTree when Vim starts with a directory argument.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
    \ execute 'NERDTree' argv()[0] | wincmd p | enew | execute 'cd '.argv()[0] | endif

"autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
    \ quit | endif
let g:NERDTreeChDirMode       = 2
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
    \ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
autocmd BufWinEnter * silent NERDTreeMirror " Open the existing NERDTree on each new tab.

" }}}

" ALE {{{
let g:ale_linters = {
\   'nim': ['nimlsp', 'nimcheck'],
\   'sh': ['shellcheck']
\}

let g:ale_fixers = {
\   '*': ['remove_trailing_lines', 'trim_whitespace'],
\   'rmd': ['styler'],
\   'nim': ['nimpretty'],
\}

let g:ale_fix_on_save = 1
let g:ale_linters_explicit = 1
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_insert_leave = 0
let g:ale_fix_on_save = 1
let g:ale_sign_error = '✖✖'
let g:ale_sign_warning = '⚠⚠'
highlight ALEErrorSign guifg=Red
highlight ALEWarningSign guifg=Yellow



" }}}

" Nim configuration - asyncomplete {{{
au User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'nim',
    \ 'whitelist': ['nim'],
    \ 'completor': {opt, ctx -> nim#suggest#sug#GetAllCandidates({start, candidates -> asyncomplete#complete(opt['name'], ctx, start, candidates)})}
    \ })
" }}}

" Nim configuration - CodeRunner and TREPL {{{
let g:CodeRunnerCommandMap = {
      \ 'nim' : 'nim c -r $fileName'
      \}

let g:code_runner_save_before_execute = 1

let g:neoterm_callbacks = {}
function! g:neoterm_callbacks.before_new()
  if winwidth('.') > 100
    let g:neoterm_default_mod = 'botright vertical'
  else
    let g:neoterm_default_mod = 'botright'
  end
endfunction

nmap <silent><leader>B <plug>CodeRunner
autocmd FileType nim nmap <leader>d :TREPLSendLine<CR>
" }}}

" Grammarous {{{
let $PATH.=':/usr/lib64/openjdk-11/bin/'
let $MYVIMRC='/home/luis/.config/nvim/init.vim'
" }}}

" MUCOMPLETE {{{
let g:mucomplete#enable_auto_at_startup = 1
let g:mucomplete#chains = {
            \ 'default' : ['omni', 'path', 'c-n'],
            \ }

let g:mucomplete#chains['rmd'] = {
            \ 'default' : ['user', 'path', 'uspl'],
            \ 'rmdrChunk' : ['omni', 'path'],
            \ }

" }}}

" Async Run {{{
augroup renderRmd | au!
    autocmd BufWritePost *.Rmd call Render()
  augroup end

function! Render() abort
  :AsyncTask render
endfunction



let g:asyncrun_open = 6
" }}}



" Vim Script
let g:lightline = {'colorscheme': 'nightfox'}

" vim:foldmethod=marker:foldlevel=0

The log file shows that the key combination Ctrl-I is assigned several times by the plug-ins. Both in LSP-Config and in mucomplete.vim the key combination seems to be entered. Deactivate one of these plugins and if the error is gone, you have certainty.
If that does not have the desired success, check which plugin was updated last. Then you can also disable it and find out step by step where exactly the error is caused.
Also, I recommend taking LSP server for auto-completion. For R there is e.g. GitHub - REditorSupport/languageserver: An implementation of the Language Server Protocol for R

1 Like

Thank you! The reason why I use mucomplete is because this was the only way I found to have completions for the function arguments as well. Will try what you suggested.

Yeah, unfortunately the error with the I disappears, but not the other ones:

I disabled several of my plugins, will keep disabling them to see if I can locate what is causing the problem.

there were some breaking changes quite some time ago in nvim-lspconfig
and because nvim-lspinstall isn’t maintained it won’t get fixed there
so you can no longer use it