4

By breaking into sentences I mean that each new sentence should start with a new line.

How to repeat )i<CR><Esc> to the end of the paragraph }? (<CR> = Enter)

If I make a macro )i<CR><Esc> as "q", can I execute it until the end of the paragraph?

0
2

You can do a search and replace. I just wrote this out. It works, but you could probably do better.

:%s/\v[ ]*([^\.]*\.)/\1\r/g
2
vap:s/\. /.^M/g
  • vap selects your current paragraph
  • :s/\. /.^M/g replace all periods followed by a space with a period followed by a newline. (Note that to get that literal newline (^M) in the replacement expression, you'll have to type <CTRL-V><CR>.)
0

My solution, start in normal mode and type:

vip:'<,'>s/\n/ /|'<,'>s/\([.?!]\)\s/\1\r/g

Note that the first '<,'> will automatically be inserted on the command line when you press the ":" key after typing "vip" in normal mode.

The first substitute joins the paragraph into one line, then the "|" character delimits a second :-command within the same command line, and this time the "'<,'>" must be typed by hand. The second substitute command replaces a period, question mark, or exclamation mark followed by a space with the matching symbol and a newline.

This won't catch instances where a sentence ends with a period/excalmation/question and a quote character, etc. but the pattern can be extended to do so.

0

I found that there is a very easy way of doing this using vim-macros.

  • First in normal mode press q, then any key, suppose that key is a. So you will see something at the bottom as recording @a.
  • Now follow the key-sequence as 0)i<cr><esc>q Now your macro is recorded. This will break the paragraph at . .
  • Now, repeat this macro as many times by pressing N@a in normal mode, where N is any number.

Note: You can choose any alphanumeric character to store your macro than a, this macro breaks the line at ., you can choose any column just replace . by any N of your choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.