1

I began to get the error

Error detected while processing BufRead Auto commands for "*.sh":
E117: Unknown function: dist#ft#SetFileTypeSH

when I opened shell scripts (*.sh) I think it happened after updating from a 7.x version to 8.0.

How can it be fixed?

As suggested, I did a search for the function in /usr/share/vim/vim80/autoload/dist/ft.vim

" Called from filetype.vim and scripts.vim.
func dist#ft#SetFileTypeSH(name)
  if expand("<amatch>") =~ g:ft_ignore_pat
    return
  endif
  if a:name =~ '\<csh\>'
    " Some .sh scripts contain #!/bin/csh.
    call dist#ft#SetFileTypeShell("csh")
    return
  elseif a:name =~ '\<tcsh\>'
    " Some .sh scripts contain #!/bin/tcsh.
    call dist#ft#SetFileTypeShell("tcsh")
    return
  elseif a:name =~ '\<zsh\>'
    " Some .sh scripts contain #!/bin/zsh.
    call dist#ft#SetFileTypeShell("zsh")
    return
  elseif a:name =~ '\<ksh\>'
    let b:is_kornshell = 1
    if exists("b:is_bash")
      unlet b:is_bash
    endif
    if exists("b:is_sh")
      unlet b:is_sh
    endif
  elseif exists("g:bash_is_sh") || a:name =~ '\<bash\>' || a:name =~ '\<bash2\>'
    let b:is_bash = 1
    if exists("b:is_kornshell")
      unlet b:is_kornshell
    endif
    if exists("b:is_sh")
      unlet b:is_sh
    endif
  elseif a:name =~ '\<sh\>'
    let b:is_sh = 1
    if exists("b:is_kornshell")
      unlet b:is_kornshell
    endif
    if exists("b:is_bash")
      unlet b:is_bash
    endif
  endif
  call dist#ft#SetFileTypeShell("sh")
endfunc

Is anything wrong with it?

I also noticed that syntax highlighting stopped working too.

I noticed that if I don't use the session file vim can open shell scripts without errors.

I think the session file is the culprit. There must be some backwards compatibility problems between versions 8 and 7 as the session file worked fine in VIM 7. But how to locate the error... I don't want to create the session file from scratch.

  • Launch vim. :e $VIM/vim80/autoload/dist/ft.vim and search for SH—you should find the function. If it’s not there or you are missing the file, you may need to reinstall vim or its runtime files. It may be vim81 if you are using 8.1. – D. Ben Knoble Aug 19 '18 at 20:43
  • 1
    did you install correctly? Sounds like your vim (more exactly the runtime files) was not properly installed – Christian Brabandt Aug 20 '18 at 6:53
  • @ChristianBrabandt Not sure. I only remember that before upgrading Kubuntu from 16.04 to 18.04 there was a 7.x version of vim installed, but after the upgrade it became 8.0. – ka3ak Aug 20 '18 at 8:44
  • Try checking with :echo $VIMRUNTIME – tivn Aug 21 '18 at 7:00
  • @tivn There is no such variable – ka3ak Aug 25 '18 at 8:45
0

The solution was to recreate the session file. As I didn't want to create it from scratch I copied the crucial parts from it - open files/buffers.

0

This happens because your .vimrc file is not upgraded when you upgrade your vim version. It still contain old runtime path. The easiest way to fix it will be to update runtimepath in .vimrc

For example, In vim 8.0 the runtimetimepath should be like

set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after

But if you just upgraded from Vim 7.4 to Vim 8.0 the line will look like:

set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after

In that case changing the vim74 to vim80 will solve the problem

  • First, I solved the issue by recreating the session file and posted the answer before you. Shouldn't it indicate that runtime has nothing to do with the problem? Second, I checked the runtime in my .vimrc. It's - runtime macros/matchit.vim. How should it be obvious that it's "old"? What is "new" version? You haven't written it. – ka3ak Sep 26 '18 at 7:52
  • @ka3ak edited my answer :) – Arun Sep 27 '18 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.