42

Right now I'm working with some blocks of text that are over 1000 lines long. Is there a simple way to move to the beginning of the next paragraph?

My workaround for now is searching for two consecutive newline characters:

/\n\n

Another workaround would be vip Esc j

  • vip visually select in paragraph (which also takes you to the end of the paragraph)

  • Esc Escape from visual selection

  • j move down

Christopher Bottoms
  • 3,772
  • 6
  • 22
  • 33
  • I think you meant vap<Esc>j, right? Too bad there's no 'previous paragraph' equivalent. – awvalenti Mar 19 '24 at 11:49
  • @awvalenti vap<Esc>j and vip<Esc>j seem to give the same results here. Thanks for pointing out an alternative. Also, vapo<Esc>kk will get you two lines before the current paragraph. – Christopher Bottoms Mar 26 '24 at 15:49

1 Answers1

60

Yes, you can use the } and { paragraph motions to move a paragraph forwards or backwards.

From :help paragraph:

A paragraph begins after each empty line, and also at each of a set of paragraph macros, specified by the pairs of characters in the 'paragraphs' option. The default is IPLPPPQPP TPHPLIPpLpItpplpipbp, which corresponds to the macros .IP, .LP, etc. (These are nroff macros, so the dot must be in the first column). A section boundary is also a paragraph boundary. Note that a blank line (only containing white space) is NOT a paragraph boundary.
Also note that this does not include a '{' or '}' in the first column. When the '{' flag is in 'cpoptions' then '{' in the first column is used as a paragraph boundary posix.

Like you would expect, you can of course add a count and/or operator; eg. 2} to move 2 paragraps fowards. Or to delete the previous 2 paragraphs you can use 3d{.

Also see :help object-motions

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
  • 3
    Side note: very useful for programmers is also [[ and ]] (as well as [] and ][) to jump between beginning (and end) of functions. – Shahbaz Mar 05 '15 at 15:53
  • 2
    Unfortunately those function-jumping motions only really work if the opening brace is in the first column. I worked somewhere which put the functions' opening braces at the end of the function declaration line and the suggested tweaks in the docs never worked terribly well. :( – dash-tom-bang Oct 06 '17 at 21:44
  • Very interesting: "Note that a blank line (only containing white space) is NOT a paragraph boundary." – Christopher Bottoms Oct 23 '23 at 15:09
  • @ChristopherBottoms In some vim plugins (namely for VS and VSCode), white space lines are considered paragraph boundaries, which I think is a better behavior since you can't exactly discern them visually otherwise. I wonder if there's a switch somewhere... – Rei Miyasaka Mar 23 '24 at 22:28
  • @ReiMiyasaka Good question. I was quoting from the help info in MartinTournoij's answer. I found this: https://stackoverflow.com/a/3939481/215487. "change vim paragraph separator" may be the magic search words in this case – Christopher Bottoms Mar 25 '24 at 22:08