Tuesday, May 24, 2022

Re: Json inline format

Sorry Marc to answer quite times after..

I have solved my need by pure VimL autocommand and vim9 func.

        autocmd BufEnter *.json g:FormatJson()

def g:FormatJson() # {{{

    if ( line('$') == 1 ) # when json is not expanded
        silent! :%s/\("\w\+":\)\({\|\("[^"]\+"\(}*,\)\)\)/\1 \2/g
        silent! :%s/\(},\)/\1/g
        silent! :%s/\(^{\)/\1/g
        silent! :%s/\("[^"]\+"\)}/\1}/g
        silent! :%s/\(}\)}/\1}/g

        silent! norm gg=GG1G
    else
        # silent! norm ggVG1J just for debug
    endif
enddef # }}}


Le samedi 7 mai 2022 à 23:58:09 UTC+2, Marc Chantreux a écrit :
> Thank you Paul, I don't want third part.

you mean you want a pure viml solution? what's the point?

regards,
marc

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/0bf86c34-bdf3-47d9-a98c-0a4faad348f4n%40googlegroups.com.

No comments:

Post a Comment