This is an example of the original code

<Text fontWeight="bold" size="lg" color="turquoise.500">Use Search V2 Beta</Text>

and I want a keyboard shortcut (say I get into visual mode and select the entire tag) and then hit something that converts it to this

    Use Search V2 Beta

another example

import { Box, Flex, Text, useDisclosure, Icon } from "@chakra-ui/react"


import { 
  Icon } from "@chakra-ui/react"


I know there are tools like prettier etc, but what I want with Vim is more control over the process. I want to be very selective over what exactly I'm prettifying. I've had some git merge nightmares b/c of other team members using prettier

  • 3
    find a tool that can format it the way you like and use it with :h 'formatprg'. Once set you can gq visual block with it.
    – Maxim Kim
    Feb 23 at 12:05

1 Answer 1


Find a command line tool that can format part or whole buffer the way it suits your needs.

Integrate it with vim using :h 'formatprg' which then could be used with gq.


Let's imagine there is a tool jsx-beautifier that can format standard input when - is provided:

$ cat some.jsx | jsx-beautifier -

Then you can add following to .vim/after/ftplugin/javascript.vim

setlocal formatprg=jsx-beautifier\ -

And now when in any javascript file you can do

  • gqap reformat current paragraph using formatprg
  • gqiB reformat current {} block using formatprg
  • select visual lines and press gq to reformat it using formatprg
  • ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.