Javascript indentation in VIM

前端 未结 7 1011
遇见更好的自我
遇见更好的自我 2021-02-02 15:46

I\'m trying to get VIM to indent Javascript with the \'=\' and related commands. When I try to auto indent the following, for example:

   new function($) {
              


        
7条回答
  •  [愿得一人]
    2021-02-02 16:12

    Oh man, I just spent a couple of hours figuring out the same problem.

    If you have filetype indent on (which you do), then a few different indent settings may be set by a file somewhere. If you use verbose set you can see where it's being set and what it's set to:

    :verbose set autoindent?
    :verbose set cindent?
    :verbose set smartindent?
    :verbose set indentexpr?
    

    By default, you'd only expect to see cindent set by the default indent file:

    cindent
    Last set from $VIMRUNTIME/indent/javascript.vim
    

    Where $VIMRUNTIME is the path you get when you run :echo $VIMRUNTIME.

    All of the others wouldn't be set unless you enable them (in your vimrc or a plugin).

    For me, I had a plugin (eclim) that was setting identexpr and causing this issue:

    identexpr=EclimGetJavascriptIndent(V:lnum)
    Last set from ~/.vim/bundle/eclim/indent/javascript.vim
    

提交回复
热议问题