vimtricks.wiki Concise Vim tricks, one at a time.

How do I fully justify a selected text block to a fixed width using Vim's built-in justify plugin?

Answer

:packadd justify | :'<,'>Justify 72

Explanation

Vim can wrap text, but full left-and-right justification is a different task. The optional built-in justify plugin gives you that capability directly inside the editor, which is useful for prose-heavy files, commit templates, release notes, or documentation blocks where visual alignment matters. The workflow is lightweight: load the plugin on demand, then justify only the range you selected.

How it works

  • :packadd justify loads Vim's optional justify runtime plugin for the current session
  • :'<,'>Justify 72 runs the plugin command on the current visual range
  • 72 is the target width; the plugin redistributes spaces between words to align both margins

Because this is an optional package, loading it with packadd keeps startup minimal while still giving you the command when needed.

Example

Before:

This paragraph has uneven spacing and line lengths.
It wraps awkwardly and does not align to a consistent right edge.

After selecting the paragraph and running the command:

This paragraph has uneven spacing and line lengths. It wraps
awkwardly and does not align to a consistent right edge.

The text is now justified to the chosen width.

Tips

  • Keep this plugin lazy-loaded if you only justify occasionally
  • Use a visual selection to avoid modifying unrelated sections
  • Try :help Justify after loading to explore optional arguments like max spacing and indent control

Next

How do I make buffer jumps prefer the last-used window that already shows the target buffer?