How to get line numbers of selected text in vim

Is it possible to pass line numbers of selected text to an external command?

Context: I would like to integrate pyfmt

into vim. Ideally, I would like to select the text and type some shortcut so that the selected text is formatted pyfmt

.

So far, I've found that launching !pyfmt -i %

will format the entire file. pyfmt

also supports the parameter --lines START-END

. I would like to be able to pass line numbers from the start and end of the selected text to pyfmt

, so that only the reformatting will be fixed. Is it possible?

+3


source to share


1 answer


Select the lines you want to format (preferably linewise using capital Vto enter visual mode) and then, without leaving visual mode, enter :!pyfmt -i

.



It won't give you line numbers. Instead, it will filter the selected rows with the command and replace them with output.

+2


source







All Articles