Vim + elm-vim无法识别.elm文件

时间:2019-12-17 00:58:42

标签: vim elm

我刚开始在Elm中编程,我正在用vim设置配置,但是遇到了一些麻烦。

我已经下载了elm-vim,但是当我创建.elm文件时,我没有语法高亮显示,Ale不起作用(它没有显示任何建议/错误)...就像我没有Elm插件已安装。

我安装了以下全局elm软件包:

$ npm list -g | grep elm
├─┬ elm@0.19.1-3
├─┬ elm-format@0.8.2
├── elm-oracle@1.1.1
├─┬ elm-test@0.19.1-revision2
│ ├─┬ elmi-to-json@1.3.0
│ ├─┬ node-elm-compiler@5.0.4
│ │ ├─┬ find-elm-dependencies@2.0.2

这是我的.vimrc:

set nocompatible
filetype off
filetype plugin on
filetype indent on

set autoread
au FocusGained,BufEnter * checktime

let mapleader=","

set so=7

set showcmd
set wildmenu
set ruler
set backspace=eol,start,indent

set smartcase
set hlsearch
set incsearch
set lazyredraw
set magic

" number + relative number
set number
set relativenumber

" Always display the status line
set laststatus=2

" swap files with unique names in this directory:
set directory=$HOME/Conf/vim/swp//

" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
set background=dark

syntax enable

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
set expandtab

" Be smart when using tabs ;)
set smarttab

" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4

" Linebreak on 500 characters
set lbr
set tw=500

set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines

""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>


inoremap jj <esc>
nmap ; :

" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

" Copy from vim with CTRL+C
noremap <C-c> "+y

" avoid scanning useless folders
set wildignore+=*/tmp/*,*/node_modules/*,*.so,*.swp,*.zip

function! VisualSelection(direction, extra_filter) range
    let l:saved_reg = @"
    execute "normal! vgvy"

    let l:pattern = escape(@", "\\/.*'$^~[]")
    let l:pattern = substitute(l:pattern, "\n$", "", "")

    if a:direction == 'gv'
        call CmdLine("Ack '" . l:pattern . "' " )
    elseif a:direction == 'replace'
        call CmdLine("%s" . '/'. l:pattern . '/')
    endif

    let @/ = l:pattern
    let @" = l:saved_reg
endfunction

" set the runtime path to include Vundle and initialize
set rtp+=~/Conf/vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim' " required
Plugin 'vim-airline/vim-airline'
Plugin 'pangloss/vim-javascript'
Plugin 'maxmellon/vim-jsx-pretty'
Plugin 'scrooloose/nerdtree'
" NERDTree: shortcut for nerdtree toggle
map <F7> :NERDTreeToggle<CR>
let g:NERDTreeNodeDelimiter = "\u00a0"

" NERDTREE git plugin:
let NERDTreeMinimalUI = 1
let g:NERDTreeIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ 'Ignored'   : '☒',
    \ "Unknown"   : "?"
    \ }

Plugin 'valloric/youcompleteme'
Plugin 'dense-analysis/ale'
let g:ale_linters = {
\   'javascript': ['prettier', 'eslint']
\}
let g:airline#extensions#ale#enabled = 1

Plugin 'elmcast/elm-vim'

call vundle#end()            " required
filetype plugin indent on    " required

au FileType javascript set sw=2 sts=2 et
au FileType html set sw=4 sts=4 et
au FileType css set sw=4 sts=4 et

au FileType *.py
    \ set tabstop=4
    \ set softtabstop=4
    \ set shiftwidth=4
    \ set textwidth=79
    \ set expandtab
    \ set autoindent
    \ set fileformat=unix

我想念什么?

编辑:评论后的更新信息:

:filetype的输出:

filetype detection:ON  plugin:ON  indent:ON  

:scriptnames的输出

1: /usr/share/vim/vimrc                                                                                                  
  2: /usr/share/vim/vim81/debian.vim
  3: /usr/share/vim/vim81/syntax/syntax.vim
  4: /usr/share/vim/vim81/syntax/synload.vim
  5: /usr/share/vim/vim81/syntax/syncolor.vim
  6: /usr/share/vim/vim81/filetype.vim
  7: ~/.vimrc
  8: /usr/share/vim/vim81/ftoff.vim
  9: /usr/share/vim/vim81/syntax/nosyntax.vim
 10: ~/Conf/vim/bundle/Vundle.vim/autoload/vundle.vim
 11: ~/Conf/vim/bundle/Vundle.vim/autoload/vundle/config.vim
 12: /usr/share/vim/vim81/ftplugin.vim
 13: /usr/share/vim/vim81/indent.vim
 14: ~/.vim/bundle/vim-airline/plugin/airline.vim
 15: ~/.vim/bundle/vim-airline/autoload/airline/init.vim
 16: ~/.vim/bundle/vim-airline/autoload/airline/parts.vim
 17: ~/.vim/bundle/vim-airline/autoload/airline/util.vim
 18: ~/.vim/bundle/nerdtree/plugin/NERD_tree.vim
 19: ~/.vim/bundle/nerdtree/autoload/nerdtree.vim
 20: ~/.vim/bundle/nerdtree/lib/nerdtree/path.vim
 21: ~/.vim/bundle/nerdtree/lib/nerdtree/menu_controller.vim
 22: ~/.vim/bundle/nerdtree/lib/nerdtree/menu_item.vim
 23: ~/.vim/bundle/nerdtree/lib/nerdtree/key_map.vim
 24: ~/.vim/bundle/nerdtree/lib/nerdtree/bookmark.vim
 25: ~/.vim/bundle/nerdtree/lib/nerdtree/tree_file_node.vim
 26: ~/.vim/bundle/nerdtree/lib/nerdtree/tree_dir_node.vim
 27: ~/.vim/bundle/nerdtree/lib/nerdtree/opener.vim
 28: ~/.vim/bundle/nerdtree/lib/nerdtree/creator.vim
 29: ~/.vim/bundle/nerdtree/lib/nerdtree/flag_set.vim
 30: ~/.vim/bundle/nerdtree/lib/nerdtree/nerdtree.vim
 31: ~/.vim/bundle/nerdtree/lib/nerdtree/ui.vim
 32: ~/.vim/bundle/nerdtree/lib/nerdtree/event.vim
 33: ~/.vim/bundle/nerdtree/lib/nerdtree/notifier.vim
 34: ~/.vim/bundle/nerdtree/autoload/nerdtree/ui_glue.vim
 35: ~/.vim/bundle/nerdtree/nerdtree_plugin/exec_menuitem.vim
 36: ~/.vim/bundle/nerdtree/nerdtree_plugin/fs_menu.vim
 37: ~/.vim/bundle/nerdtree/nerdtree_plugin/vcs.vim
 38: ~/.vim/bundle/elm-vim/plugin/elm.vim
 39: ~/.vim/bundle/youcompleteme/plugin/youcompleteme.vim
 40: ~/.vim/bundle/ale/plugin/ale.vim
 41: ~/.vim/bundle/ale/autoload/ale/events.vim
 42: /usr/share/vim/vim81/plugin/getscriptPlugin.vim
 43: /usr/share/vim/vim81/plugin/gzip.vim
 44: /usr/share/vim/vim81/plugin/logiPat.vim
 45: /usr/share/vim/vim81/plugin/manpager.vim
 46: /usr/share/vim/vim81/plugin/matchparen.vim
 47: /usr/share/vim/vim81/plugin/netrwPlugin.vim
 48: /usr/share/vim/vim81/plugin/rrhelper.vim
 49: /usr/share/vim/vim81/plugin/spellfile.vim
 50: /usr/share/vim/vim81/plugin/tarPlugin.vim
 51: /usr/share/vim/vim81/plugin/tohtml.vim
 52: /usr/share/vim/vim81/plugin/vimballPlugin.vim
 53: /usr/share/vim/vim81/plugin/zipPlugin.vim
 54: /usr/share/vim/vim81/scripts.vim
 55: ~/.vim/bundle/vim-airline/autoload/airline/extensions.vim
 56: ~/.vim/bundle/vim-airline/autoload/airline/extensions/quickfix.vim
 57: ~/.vim/bundle/vim-airline/autoload/airline.vim
 58: ~/.vim/bundle/vim-airline/autoload/airline/extensions/netrw.vim
 59: ~/.vim/bundle/vim-airline/autoload/airline/extensions/term.vim
 60: ~/.vim/bundle/vim-airline/autoload/airline/section.vim
 61: ~/.vim/bundle/vim-airline/autoload/airline/highlighter.vim
 62: ~/.vim/bundle/vim-airline/autoload/airline/extensions/vista.vim
 63: ~/.vim/bundle/vim-airline/autoload/airline/extensions/ale.vim
 64: ~/.vim/bundle/vim-airline/autoload/airline/extensions/whitespace.vim
 65: ~/.vim/bundle/vim-airline/autoload/airline/extensions/wordcount.vim
 66: ~/.vim/bundle/vim-airline/autoload/airline/extensions/keymap.vim
 67: ~/.vim/bundle/vim-airline/autoload/airline/themes/dark.vim
 68: ~/.vim/bundle/vim-airline/autoload/airline/themes.vim
 69: ~/.vim/bundle/vim-airline/autoload/airline/builder.vim
 70: ~/.vim/bundle/vim-airline/autoload/airline/extensions/default.vim
 71: ~/.vim/bundle/ale/autoload/ale.vim
 72: ~/.vim/bundle/youcompleteme/autoload/youcompleteme.vim
 73: ~/.vim/bundle/ale/autoload/ale/engine.vim
 74: ~/.vim/bundle/ale/autoload/ale/statusline.vim
 75: ~/.vim/bundle/ale/autoload/ale/cursor.vim

2 个答案:

答案 0 :(得分:3)

TL; DR:从vimrc文件的顶部删除以下行:

filetype plugin on
filetype indent on

那应该可以解决问题。


您遇到的问题是,即使已成功注册插件本身,也无法加载将filetype=elm*.elm文件相关联的elm-vim的文件类型检测。 / p>

Elm中的文件类型检测是通过设置中的~/.vim/bundle/elm-vim/ftdetect/elm.vim脚本完成的,但是该脚本从未加载过。

ftdetect脚本在执行$VIMRUNTIME/filetype.vim的过程中被加载到Vim中,其中包含comment by Nico Schertler

" Use the filetype detect plugins.  They may overrule any of the previously
" detected filetypes.
runtime! ftdetect/*.vim

filetype.vim文件作为:filetype on命令的一部分运行,因此这就是创建所有autocmd进行文件类型检测的原因。

但是,filetype.vim还包括this snippet

" Listen very carefully, I will say this only once
if exists("did_load_filetypes")
  finish
endif
let did_load_filetypes = 1

这意味着在启用文件类型检测时,此文件将仅获得一次。如果要重新运行它,则需要禁用它(使用运行:filetype off的{​​{1}},它会取消设置$VIMRUNTIME/ftoff.vim全局变量),然后再次重新启用它。

这就是为什么Vundle会告诉您在调用did_load_filetypes之后立即运行filetype plugin indent on,因为届时vundle#end()将被调整为包括插件路径和所有{{从插件中找到1}}目录。它还会告诉您在'runtimepath'之前运行ftdetect以确保它已被禁用(很可能已从filetype off或系统范围内的vimrc文件启用了它。)请参阅{{3 }},其中列出了两个步骤。

因此,简而言之,仅 在Vundle插件设置后 之后使用vundle#begin()命令(或更具体地说,是defaults.vim)做完了。如果您以前也这样做,则很可能会错过插件的:filetype on,因为这些脚本将不会被获得。

答案 1 :(得分:0)

@filebrander 的回答对我不起作用,所以我找到了另一种方法:

    1. 创建以下文件夹:~/.vim/ftdetect/
    1. 在此文件夹中创建文件 elm.vim

你必须把以下内容放进去:

au BufRead,BufNewFile *.elm set filetype=elm
    1. 重启vim

这将覆盖 .elm 文件的默认文件检测

我希望这对你有用!