mxw / vim-jsx

React JSX syntax highlighting and indenting for vim.
1.59k stars 95 forks source link

Breaks JS indenting #10

Closed imiric closed 10 years ago

imiric commented 10 years ago

Hey, sorry to be a pest, but I noticed that with this plugin installed, the indenting on all JS files (.js and .jsx) is broken.

Here's what I mean:

The cursor always returns to the beginning of the line, both in Normal mode and with o or in Insert mode and with Enter. This is with set filetype=javascript and set nopaste.

The JSX syntax highlighting works great, it's just that I really can't work with the indenting broken. Removing this plugin fixes the issue.

Thanks for your work!

mxw commented 10 years ago

I'm unable to repro this. My best guess is that you aren't using pangloss's https://github.com/pangloss/vim-javascript syntax and indentation, which is a dependency specified in the README.

If you aren't, including that bundle should fix your issue. If you are, can you give me a list of the bundles you are using, and possibly a link or paste to your .vimrc?

mxw commented 10 years ago

Oh, but if you aren't using vim-javascript, I would expect the syntax to break, too... hm.

imiric commented 10 years ago

Yeah, I was definitely using vim-javascript. I've uninstalled both plugins now, but here's my .vimrc (sorry, it's a mess).

mxw commented 10 years ago

Would you mind seeing what happens if you comment out all your plugins except for vim-javascript and vim-jsx? If indenting in a new vim session still doesn't work right, then something is very wrong—vim-jsx should definitely be indenting both JSX and regular JS correctly.

If commenting out all the other plugins fixes the issue, you can try adding back each plugin individually to see which one commits, at which point I can take a look. No guarantees though in that case—plugin conflicts are sort of just par for the course when you have a lot of plugins though (especially one like mine which tries to reach into existing language plugins and muck around with things).

imiric commented 10 years ago

Uff, that sounds like a lot of work, and I was only using this plugin for highlighting HTML in JSX files, which I can live without. Is there any way you can make the syntax highlighting a separate plugin?

mxw commented 10 years ago

Just the first of those (i.e., commenting out your other plugins) should be pretty quick, right? If it's still broken after that, it's probably vim-jsx's fault, and I'll give you a fix.

Also, just noticed this—I don't actually know how Vundle works, but in their README, they have filetype off before the vundle#rc() or vundle#begin() invocation and list of plugins. If you move that line to the top of the file, do things get better?

If neither of these reveals the issue and it's just a plugin conflict you don't want to dig into, I don't want to split off the syntax and indentation (especially since one relies on the other)—your best be in that case is just to wipe away the after/indent directory locally.

imiric commented 10 years ago

I'll look into it when I have some free time and let you know. If I don't reply to this issue in a week or two, feel free to close it. :)

Thanks for your help!

julienaubert commented 10 years ago

I had the same issue, and.. had missed pangloss/javascript - works fine.

blast-hardcheese commented 10 years ago

Same here, somehow pangloss/javascript had gotten commented out-- putting it back resolved this issue for me.

mxw commented 10 years ago

@imiric—If you figure out the conflicting bundle, let me know and I can try to fix things for you. Closing for now.

jarodtaylor commented 9 years ago

I'm having this same issue and I have pangloss/vim-javascript loaded.

mxw commented 9 years ago

@jarodtaylor—Can you send me a paste or a gist of your ~/.vimrc?

jarodtaylor commented 9 years ago

I'm using a dotfiles config so I am using .local on my configs. So this is just "my" vimrc.local file.

set number
set t_ti= t_te=
set ts=2

set smarttab
set nolist
set tabstop=2
set expandtab
set shiftwidth=2
set softtabstop=2

set background=dark
let g:solarized_visibility = "high"
let g:solarized_contrast = "high"
colorscheme solarized

let g:user_emmet_expandabbr_key = '<C-g>'
let g:use_zen_complete_tag = 1

let g:jsx_ext_required = 0
mxw commented 9 years ago

@jarodtaylor—If that's your entire config, you don't have this package included...

musically-ut commented 9 years ago

The reason for my woes along similar lines turned out to be a stray javascript.vim file in my local computer's .vim/indent folder. Removing that file did the trick for me.

It is a little surprising that a file took precedence over the plugins I had installed (using vim-plug). I wonder if vundle and pathogen also yield precedence in similar ways or whether this is hard-coded within vim.

Goblinlordx commented 9 years ago

Had this same issue and removed the /indent/javascript file to resolve this.

xream commented 9 years ago

If you use vim-plug, this may help: Plug 'mxw/vim-jsx', { 'do': 'rm ~/.vim/plugged/vim-jsx/after/indent/jsx.vim' }

musically-ut commented 9 years ago

@xream But that will remove the indentation-aid for XML embedded in the Javascript.

patreeceeo commented 9 years ago

I was having the same issue, then I commented out the entire contents of ~/.vim/plugged/vim-jsx/after/indent/jsx.vim, restarted vim then autoindent was working again in my javascript (but not in the embedded html, of course). I think that's good evidence that the problem is with that file.

mxw commented 9 years ago

...or it conflicts with some other file from some other package.

webOS101 commented 8 years ago

I'm also having the same issue with the broken indent. Happy to help trace this down. I don't seem to have a stray .vim/indent folder. Am using vim-javascript.

webOS101 commented 8 years ago

As a followup, I disabled all add-ons except vim-javascript and vim-jsx and i still have the issue. This is running on MacVim with pathogen, if that's relevant.

webOS101 commented 8 years ago

In debugging further I discovered I had somehow deleted the contents of my vim-javascript folder. Once I restored the contents of the folder, it was all good again. 😭

micheleb commented 8 years ago

I also had a javascript.vim file (in my ~/.vim/syntax folder) which prevented vim-jsx from working, but what fooled me was that I was using js as FileType in my .vimrc to set 2-space tabs for javascript files, when I should have used javascript.jsx. This is the correct line:

au FileType javascript.jsx setlocal sw=2 sts=2 et
mxw commented 8 years ago

javascript should be fine there. Are you sure there wasn't another intervening file that was setting up a different autocmd?

micheleb commented 8 years ago

javascript works, too, thanks. But I wrote js, which didn't.

wincent commented 8 years ago

Was broken for me too, fixed by updating from d0ad98cf0e5a0 to eb656ed96435. (Didn't bother to bisect.)

JofArnold commented 8 years ago

I had this issue. Turns out it was conflicting with sheerun/vim-polyglot. Removed that plugin and everything is fine.

For anyone else having this issue, grep for javascript.vim and see where it appears. Then selectively remove those which aren't vim-jsx, vim-javascript

StandardNerd commented 7 years ago

I removed (respectively renamed) vim-jsx/after/indent/jsx.vim - file and got proper indentation in jsx again.

ObserverZero commented 7 years ago

I am having this problem as well. I'm currently using NeoVim, is that a problem? Here is my init.vim:

[deprecated]

mxw commented 7 years ago

@ObserverZero—Do you really need everything in that config in order to repro? Could you try to trim down until you have a minimal repo ~/.vimrc?

ObserverZero commented 7 years ago

Ok, I've taken out what must be irrelevant.

"-----------------------LOADING PACKAGES-------------------- source ~/.config/nvim/autoload/autoclose.vim source ~/.config/nvim/autoload/plug.vim source ~/.config/nvim/autoload/pathogen.vim source ~/.config/nvim/autoload/common-functions.vim source ~/.config/nvim/autoload/indent-object.vim source ~/.config/nvim/autoload/type_helpers.vim source ~/.config/nvim/autoload/kwbd.vim source ~/.config/nvim/autoload/syntastic-conf.vim source ~/.config/nvim/autoload/restore_view.vim source ~/.config/nvim/bundle/vim-slime/plugin/slime.vim "-----------------------------------------------------------

"----------SETS VIM LANGUAGE AND MINIMAL INTERFACE---------- lan en_US set nosmd set noru set noshowmode set laststatus=0 set linebreak set fo+=t set cmdheight=1 set ignorecase set autoindent set smartindent set incsearch set fillchars=" " set nocompatible set hidden set t_Co=256 set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab|retab set clipboard=unnamed execute 'highlight FoldColumn ctermbg=0' let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 filetype plugin on "-----------------------------------------------------------

" ------------------JS SYNTAX AND REACT NATIVE-------------- let g:jsx_ext_required = 0 set conceallevel=1 filetype plugin indent on filetype off "-----------------------------------------------------------

"------------------------PLUG MODULES----------------------- call plug#begin('~/.config/nvim/plugged')

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'justinmk/vim-sneak' Plug 'tpope/vim-surround' Plug 'junegunn/fzf.vim' Plug 'altercation/vim-colors-solarized' Plug 'critiqjo/lldb.nvim' Plug 'honza/vim-snippets' Plug 'chrisbra/NrrwRgn' Plug 'wellle/targets.vim' Plug 'flazz/vim-colorschemes' Plug 'kana/vim-textobj-user' Plug 'pangloss/vim-javascript' Plug 'mxw/vim-jsx' call plug#end() "-----------------------------------------------------------

mxw commented 7 years ago

So your issue only repros when you have all those plugins enabled? If not, please disable them until you figure out the minimal possible ~/.vimrc which repros.

mvattuone commented 6 years ago

I've noticed that if I have let g:jsx_ext_required = 0 in my ~/.vimrc, this issue occurs.

As soon as I comment it out, I am able to indent again.

rogeriopvl commented 5 years ago

I used a customized version of @xream 's suggestion:

Plug 'sheerun/vim-polyglot', { 'do': 'rm ~/.vim/plugged/vim-polyglot/after/indent/javascript.vim' }

This fixed the problem. The vim-polyglot indent file should be irrelevant enough for not having a noticeable impact.