Skip to main content
rewrite now the OP has confirmed that they need the entire buffer to be passed
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

Presuming that yapf doesn't require the whole buffer in order to be able to reformat lines 30-40, an easier way to achieve your goal is to use Vim'sVim provides a filter feature aimed at this sort of problem. This allows you to pass content from Vim into an external tool, and then replace thethat content you passed with the tool's output.

The documentation can be found at :help filter, but your goal might* be as simple to achievereplace the entire contents of your file with the output of your yapf command you can use the command:

:%!yapf -l 30-40

For commands that don't require the entire content of the buffer as input, you can use a range with a filter (See :help :range!). e.g.:

:30,40!yapf

* I say "might" because I don't have yapf installed so haven't tested this precise command. You might need to tweak the command slightly if yapf requires further arguments. See :h :range! for the specific form I'm using above.

Presuming that yapf doesn't require the whole buffer in order to be able to reformat lines 30-40, an easier way to achieve your goal is to use Vim's filter feature. This allows you to pass content from Vim into an external tool, and then replace the content you passed with the tool's output.

The documentation can be found at :help filter, but your goal might* be as simple to achieve as:

:30,40!yapf

* I say "might" because I don't have yapf installed so haven't tested this precise command. You might need to tweak the command slightly if yapf requires further arguments. See :h :range! for the specific form I'm using above.

Vim provides a filter feature aimed at this sort of problem. This allows you to pass content from Vim into an external tool, and then replace that content with the tool's output.

The documentation can be found at :help filter, but to replace the entire contents of your file with the output of your yapf command you can use the command:

:%!yapf -l 30-40

For commands that don't require the entire content of the buffer as input, you can use a range with a filter (See :help :range!). e.g.:

:30,40!yapf
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

Presuming that yapf doesn't require the whole buffer in order to be able to reformat lines 30-40, an easier way to achieve your goal is to use Vim's filter feature. This allows you to pass content from Vim into an external tool, and then replace the content you passed with the tool's output.

The documentation can be found at :help filter, but your goal might* be as simple to achieve as:

:30,40!yapf

* I say "might" because I don't have yapf installed so haven't tested this precise command. You might need to tweak the command slightly if yapf requires further arguments. See :h :range! for the specific form I'm using above.