Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color strings differently than other value types #37

Closed
khepler opened this issue Sep 19, 2014 · 7 comments
Closed

Color strings differently than other value types #37

khepler opened this issue Sep 19, 2014 · 7 comments

Comments

@khepler
Copy link

khepler commented Sep 19, 2014

I would like the ability to color values of type string differently than values of other types. This would make obvious which values are strings with concealment enabled.

For example, this is GitHub's JSON highlighting:

{
    "key1":"1.0",
    "key2":1.0
}
@Dr-Emann
Copy link

👍 This is the only thing keeping me from using concealment

@elzr
Copy link
Owner

elzr commented Mar 23, 2015

image

This took long enough but it's finally here! Since the beginning these different value types were being recognized and tagged appropriately in the syntax file, as Number and Boolean. But apparently most color schemes don't have distinct colors for them. I despaired of how to solve this in a general way for a long time, finally I just ended up tagging numbers and booleans as Delimiter. It's hackish but it works.

@elzr elzr closed this as completed Mar 23, 2015
@bobifle
Copy link

bobifle commented Oct 17, 2018

FYI the commit is not on master, or has been reverted. I had to change the syntax file to change numbers and bools to Delimiter.

@ctranstrum
Copy link

As mentioned above, this change has been reverted. While updating the syntax file to set numbers and bools to Delimiter is a solution that works universally and might be a good solution for this package's defaults, it feels a tiny bit hacky to me, and a more correct solution, albeit one that relies on end-user configuration, seems to be simply to update either your colorscheme or your .vimrc to color String, Number, and Boolean differently.

For example, add something like this to ~/.vimrc:

highlight String ctermfg=green
highlight Number ctermfg=blue
highlight Boolean ctermfg=magenta

Maybe it would be a good idea if a tip along these lines could be added to the documentation.

@poetaman
Copy link

poetaman commented Jan 25, 2021

@ctranstrum A better option is to add it in json.vim file ~/.vim/ftplugin/json.vim with all other shenanigans needed for it to work with indentLine plugin, and maybe more...

highlight String ctermfg=green
highlight Number ctermfg=blue
highlight Boolean ctermfg=magenta

" Multiple folding recipes to not open in folded mode
" au BufRead * normal zR
" set foldlevel=99
setlocal foldmethod=syntax
set foldlevel=99

" etc

@juanMarinero
Copy link

Quick testing json:

{
  "bool": true,
  "string": "500",
  "integer, NOT a string": 500,
  "null value": null,
  "error": Error,
  "to do": TODO,
  "array": [ "John", "Peter" ],
  "object": { "name": "John", "age": 30 }
}

Maybe useful too:

highlight Normal ctermfg=grey
highlight Function ctermfg=darkred  " Null value
highlight Error ctermfg=red

@juanMarinero
Copy link

I think it should be jsonConstant, jsonBoolean, etc. like here https://github.com/elzr/vim-json/blob/master/syntax/json.vim#L103; not just Constant, Boolean, etc. because that overwrites all filetype syntax-es (or I suffer it if I code it in ~/.vim/ftplugin/json.vim as soon as I open a json file).

fschauen added a commit to fschauen/dotfiles that referenced this issue Dec 12, 2022
See the following comment for why this way broken:

    elzr/vim-json#37 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants