首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vim + elm-vim无法识别.elm文件

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

Stack Overflow用户
提问于 2019-12-17 08:58:43
回答 2查看 215关注 0票数 3

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

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

我安装了以下全局elm包:

代码语言:javascript
复制
$ 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:

代码语言:javascript
复制
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:

代码语言:javascript
复制
filetype detection:ON  plugin:ON  indent:ON  

输出:scriptname

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2019-12-18 03:01:14

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

代码语言:javascript
复制
filetype plugin on
filetype indent on

这应该可以解决问题。

您遇到的问题是,elm-vim的文件类型检测(将filetype=elm*.elm文件相关联)没有被加载,即使插件本身已经成功注册。

Elm中的文件类型检测是由设置中的~/.vim/bundle/elm-vim/ftdetect/elm.vim脚本完成的,但该脚本永远不会被加载。

作为$VIMRUNTIME/filetype.vim执行的一部分,ftdetect脚本被加载到Vim中,其中包含this snippet

代码语言:javascript
复制
" 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

代码语言:javascript
复制
" Listen very carefully, I will say this only once
if exists("did_load_filetypes")
  finish
endif
let did_load_filetypes = 1

这意味着在启用文件类型检测时,此文件将只有一次来源。如果您想重新运行它,则需要禁用它(使用:filetype off,它运行$VIMRUNTIME/ftoff.vim,它取消设置did_load_filetypes全局变量),然后再次重新启用它。

这就是为什么Vundle会在调用vundle#end()之后立即告诉您运行filetype plugin indent on,因为到那时,'runtimepath'将被调整为包含插件路径,并且插件中的所有ftdetect目录都将被找到。它还会告诉您在运行vundle#begin()之前先运行filetype off,以确保禁用它(它可能是从defaults.vim或系统范围的vimrc文件中启用的)。请参阅Vundle's quick start,其中根据需要列出了这两个步骤。

因此,简而言之,只有在Vundle插件安装完成后才使用:filetype on命令(或者更具体地说,使用filetype plugin indent on)。如果您以前也这样做过,那么您很可能会错过插件的ftdetect,因为这些脚本将不会获得源代码。

票数 5
EN

Stack Overflow用户

发布于 2021-04-13 01:13:38

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

对以下文件夹执行

    1. Create操作:~/.vim/ftdetect/

在此folder.中

    1. Create文件elm.vim

您必须在其中放入以下内容:

代码语言:javascript
复制
au BufRead,BufNewFile *.elm set filetype=elm

    1. Restart vim

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

我希望这对你有用!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59366239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档