indentLine icon indicating copy to clipboard operation
indentLine copied to clipboard

json syntax file conflicts?

Open Fity opened this issue 9 years ago • 34 comments

I don't install vim-json, but json file syntax seems to be affected. when indentLine is loaded: image when not loaded: image

Need help.

Fity avatar Nov 25 '15 06:11 Fity

+1

jiajunhuang avatar Dec 17 '15 02:12 jiajunhuang

can not reproduce. Maybe you have installed other plugin. image

Yggdroot avatar Dec 18 '15 05:12 Yggdroot

I've test for it in VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul 24 2015 02:23:23), and NVIM v0.1.0-155-g78e7c40 (compiled Dec 2 2015 20:44:32), use this config:

call plug#begin('~/.config/nvim/plugged')

" basic plugins
Plug 'Yggdroot/indentLine'

call plug#end()

neovim still have the problem:

image

here is the raw format json:

{
    "haha": "xixi",
    "this": "that"
}

jiajunhuang avatar Dec 18 '15 06:12 jiajunhuang

This issue is caused by the builtin json.vim which also uses the conceal feature. see here for some related discussion. I use these settings to walk around.

autocmd InsertEnter *.json setlocal concealcursor=
autocmd InsertLeave *.json setlocal concealcursor=inc

Fity avatar Dec 19 '15 05:12 Fity

Thanks

jiajunhuang avatar Dec 19 '15 12:12 jiajunhuang

I prefer the solution suggested in the linked thread from @Fity.

Plugin 'elzr/vim-json'
let g:vim_json_syntax_conceal = 0

Leandros avatar Jan 22 '16 10:01 Leandros

let g:vim_json_syntax_conceal = 0 does not work for the vim-json bundled with Ubuntu's vim package. It's an older version and does not have this option yet. However the vim-json docs suggest:

The specially overeager indentLine, plugin would require yet an additional let g:indentLine_noConcealCursor="" in your .vimrc as detailed here.

Which does work on Ubuntu 16.04. For me, at least.

EDIT: Actually you need to set let g:indentLine_concealcursor='nc'.

romanlevin avatar Jun 13 '16 16:06 romanlevin

Same issue here on neovim-0.1.5-dev.

@Leandros : you suggestion works, but is really annoying to install an unwanted plugin to get things work

caneta avatar Jul 07 '16 12:07 caneta

let g:vim_json_syntax_conceal = 0 does not work for the vim-json bundled with Ubuntu's vim package. It's an older version and does not have this option yet.

Thank you for posting that. I just ran into this issue today on Ubuntu 16.04 and was trying to figure out why the setting wasn't working. I had incorrectly assumed that because the last update to vim-json was in the middle of 2015, Ubuntu 16.04 would have the latest version. Installing the master version of https://github.com/elzr/vim-json fixed it for me.

richardxia avatar Jan 10 '17 02:01 richardxia

None of these fixes work anymore, at least not in neovim. I have this in my init.vim:

let g:indentLine_enabled = 1
let g:vim_json_syntax_conceal = 0
let g:indentLine_noConcealCursor='nc'
let g:vim_json_syntax_conceal = 0

No combinations of these variables does anything at all. My only choice is to disable the plugin. I don't have any additional JSON plugins installed.

mattolenik avatar Oct 04 '17 21:10 mattolenik

@mattolenik, @Leandros answer worked for me.

Fenkiou avatar Nov 05 '17 11:11 Fenkiou

This issue is because the author of json's syntax file thought people like the quotes being concealed. To fix the issue, you can do like this:

  1. enter vim
  2. :e $VIMRUNTIME/syntax/json.vim
  3. :g/if has('conceal')/s//& \&\& 0/
  4. :wq

Yggdroot avatar Jan 15 '18 09:01 Yggdroot

issue solved

Fity avatar Jul 02 '18 07:07 Fity

This issue is old but just FYI, default json syntax file is updated and after patch 8.1.2060, you can disable json's concealment selectively. :help json.vim It has the same effect as the above solution.

hayatogh avatar Sep 29 '19 10:09 hayatogh

let g:vim_json_syntax_conceal = 0 does not work for the vim-json bundled with Ubuntu's vim package. It's an older version and does not have this option yet. However the vim-json docs suggest:

The specially overeager indentLine, plugin would require yet an additional let g:indentLine_noConcealCursor="" in your .vimrc as detailed here.

Which does work on Ubuntu 16.04. For me, at least.

EDIT: Actually you need to set let g:indentLine_concealcursor='nc'.

The edit line worked for me with Debian. Thank you!

hueftl avatar Oct 22 '19 13:10 hueftl

What I did was make a ~/.vim/after/syntax/json.vim and put this in it:

syn region  jsonKeyword matchgroup=jsonQuote start=/"/  end=/"\ze[[:blank:]\r\n]*\:/ contained
syn region  jsonString oneline matchgroup=jsonQuote start=/"/  skip=/\\\\\|\\"/  end=/"/ contains=jsonEscape contained

You'll note those are the lines in the if statement in $VIMRUNTIME/syntax/json.vim.

alertedsnake avatar Oct 31 '19 13:10 alertedsnake

I tested these ones and none of them worked

let g:vim_json_conceal = 0
let g:indentLine_concealcursor='nc'

rlopzc avatar Feb 28 '20 14:02 rlopzc

enter vim
:e $VIMRUNTIME/syntax/json.vim
:g/if has('conceal')/s//& \&\& 0/
:wq

This also didn't worked for me

rlopzc avatar Feb 28 '20 15:02 rlopzc

From vimhelporg:

JSON json.vim ft-json-syntax

The json syntax file provides syntax highlighting with conceal support by default. To disable concealment: let g:vim_json_conceal = 0

The setting it in my .vimrc solved the problem on VIM 8.2.24 json-Indent.png

dagolinuxoid avatar Mar 25 '20 06:03 dagolinuxoid

I tested these ones and none of them worked

let g:vim_json_conceal = 0
let g:indentLine_concealcursor='nc'

@romariolopezc setting the one liner : let g:vim_json_conceal = 0 in your .vimrc file should be enough (are you using VIM 8.2.24 or above ?)

dagolinuxoid avatar Mar 25 '20 06:03 dagolinuxoid

I still cannot get this to work. Running latest stable neovim v0.4.3 on macOS 10.15.4. I think I've tested all mentioned configurations in this post so there's only the final one in my config in this post. Any help would be appreciated!

Configuration

call plug#begin( '~/.local/share/nvim/plugged')
Plug 'Yggdroot/indentLine'
call plug#end()

set shiftwidth=4

let g:vim_json_conceal = 0
let g:indentLine_concealcursor = 'nc' " Also tested with empty ('')

Example JSON file

{
  "data": [
    {
      "hello": "world",
      "foo": 1,
      "bar": {
        "biz": "baz"
      }
    }
  ]
}

Result with config above

image

Result with conceallevel set to 0

image

bombsimon avatar Apr 28 '20 07:04 bombsimon

@bombsimon setting of let g:vim_json_conceal = 0 should be enough. According to your screenshot it looks like indent lines are disabled. Try to enable it manually by executing :IndentLinesEnable. If there are no difference idk how to help ( I've switched back from neovim to just vim).

dagolinuxoid avatar Apr 28 '20 07:04 dagolinuxoid

@dagolinuxoid Thanks for your reply!

Yeah, the indent lines gets hidden when setting conceallevel=0. Which I knew since it's stated in the readme, it was just to show how to get the quotes to show. The screenshots were taken in the same buffer just toggling conceallevel so the plugin is enabled.

Just setting let g:vim_json_conceal = 0 does not help.

Config

call plug#begin('~/.local/share/nvim/plugged')
Plug 'Yggdroot/indentLine'
call plug#end()

set shiftwidth=4
let g:vim_json_conceal = 0

Result image

bombsimon avatar Apr 28 '20 08:04 bombsimon

So basically neovim config doesn't respect the variable whatsoever. There are three solutions:

  1. wait till someone can solve it for neovim
  2. switch to vim
  3. disable indentlines for json files - honestly it's not that helpful to have them in json files, at least you can live without them =)

dagolinuxoid avatar Apr 28 '20 08:04 dagolinuxoid

@dagolinuxoid Thanks for your replies and help!

I was just curious since people in the thread, now latest https://github.com/Yggdroot/indentLine/issues/140#issuecomment-596280543, said they got this to work with neovim without any additional plugins. Because of that I felt like I was doing something wrong byt perhaps I'm not(?)

I think number 3 is most appealing. A fourth solution to actually be able to use neovim and indentlines and not conceal data is the solution posted back in 2016, https://github.com/Yggdroot/indentLine/issues/140#issuecomment-173867054. This works as expected. An extra plugin but personally I don't mind that much.

Config

call plug#begin('~/.local/share/nvim/plugged')
Plug 'Yggdroot/indentLine'
Plug 'elzr/vim-json'
call plug#end()

set shiftwidth=4
let g:vim_json_syntax_conceal = 0

Result

image

bombsimon avatar Apr 28 '20 08:04 bombsimon

I did install nvim (not the lates version though 0.2.2) for testing. My ~/.config/nvim/init.vim has

call plug#begin( '~/.local/share/nvim/plugged')
Plug 'Yggdroot/indentLine'
call plug#end()

set shiftwidth=4

you can totally get rid of let g:vim_json_conceal = 0 because for nvim it doesn't do a damn thing. nvim without any additional plugins ('elzr/vim-json') designed to treat json files like this: With IndentLinesDisabled - it shows the raw json files with quotes, and with IndentLInesEnable there are no indent lines too but quotes are gone in normal mode. As soon as you're trying to edit a word by pressing ciw (change inner word) quotes show up and disappear while editing - I found the funny behavior as a pretty cool one. It's not 'overwhelm' you with quotes making it looks cleaner - the downside it's a bit confusing.

dagolinuxoid avatar Apr 28 '20 09:04 dagolinuxoid

I'm curious why there are still so many people bothered by this issue, the root cause and the solution have already been posted above.

  1. If your vim is 8.1.2060+, let g:vim_json_conceal = 0 should be enough.
  2. otherwise,
    :e $VIMRUNTIME/syntax/json.vim
    :g/if has('conceal')/s//& \&\& 0/
    :wq
    
  3. If you are using other syntax plugin for json, please turn to that plugin for help. e.g.
    Plugin 'elzr/vim-json'
    let g:vim_json_syntax_conceal = 0
    

Yggdroot avatar May 06 '20 13:05 Yggdroot

This behavior is fixed for me in the latest commit. Perhaps we can close this issue and point to the commit where it's fixed? Otherwise I guess it's just https://github.com/Yggdroot/indentLine/commit/43dbd7092801637972b1d9fcecaaeee11f8e00cf

chrissound avatar Jul 05 '20 16:07 chrissound

I'm curious why there are still so many people bothered by this issue, the root cause and the solution have already been posted above.

  1. doesn't appear to work for Neovim users (there are many)
  2. isn't portable, has to be redone (remembered, looked up)
  3. requires installing yet another plugin (which has its own issues) to fix a plugin-related issue.

@chrissound Doesn't appear to fix things on Neovim.

adrian5 avatar Aug 09 '20 15:08 adrian5

1. doesn't appear to work for Neovim users (there are many)

~~NVIM v0.4.2 works well without any settings.~~ NVIM v0.4.2 works well with the following operation:

:e $VIMRUNTIME/syntax/json.vim
:g/if has('conceal')/s//& \&\& 0/
:wq
2. isn't portable, has to be redone (remembered, looked up)

It's the responsibility of json's syntax file.

3. requires installing yet another plugin (which has its own [issues](https://github.com/elzr/vim-json/issues)) to fix a plugin-related issue.

You don't have to.

Yggdroot avatar Aug 10 '20 02:08 Yggdroot

NVIM v0.4.2 works well without any settings.

If so they've reverted it because like I stated in https://github.com/Yggdroot/indentLine/issues/140#issuecomment-620424114 it's not working with NVIM v0.4.3, can still reproduce with example and config from linked post.

bombsimon avatar Aug 10 '20 06:08 bombsimon

Installing elzr/vim-json plugin and adding let g:vim_json_syntax_conceal = 0 eventually worked for me. Thanks @Leandros Leandros

lethargosapatheia avatar Sep 13 '21 19:09 lethargosapatheia

My workaround in Neovim: create a json.vim file in ~/.config/nvim/after/ftdetect There I have the following: au! BufAdd,BufRead,BufNew,BufEnter *.json let g:indentLine_conceallevel=1 au! BufLeave,BufUnload,BufDelete,BufHidden *.json let g:indentLine_conceallevel=2

It's working for me!

BBoal avatar Sep 15 '21 21:09 BBoal