0

I'm editing DocBook XML files and sometimes I need to format the using an external xmlformat command. it is easy to run do this on the whole buffer of text, but how can i achieve the same only for a visually selected lines of text?

EDIT1: simply running !xmlformat on selected lines works. the problem is that i need to do more things to the lines, such as get the number of indent of the first line, do the formatting, then shift the block to the indent size so that it aligns with the rest of the text.. It's summarized in https://github.com/tbazant/vim-daps/issues/38 BTW

EDIT2: the function in my plugin should be defined the way that it can handle either no input (run xmlformat on the whole file/buffer) or range of selected lines

8
  • 1
    Does simply typing !xmlformat work? If not, maybe you could edit the question to explain why. :help v_!
    – Rich
    Commented Mar 25, 2021 at 14:22
  • To more precisely I think Rich means using :'<,'>!xmlformat after a visual selection: '< and '> are marks which refer to the last visually selected text.
    – statox
    Commented Mar 25, 2021 at 14:34
  • 1
    Question header is quite different to the body I would say. There is a way to run a vimscript function on visually selected lines but here it is about filtering of visual selection using external tool.
    – Maxim Kim
    Commented Mar 25, 2021 at 14:52
  • 1
    @statox: Yes, but you don't need to type the colon or the range, simply pressing ! directly from the visual selection will add both automatocally. (I know you know this already.)
    – Rich
    Commented Mar 25, 2021 at 15:13
  • Right @Rich I was just giving more details as I think it can be confusing for someone who doesn't know that :) But your point about editing the question if that doesn't work is still completely relevant
    – statox
    Commented Mar 25, 2021 at 15:18

0

Your Answer

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

Browse other questions tagged or ask your own question.