How can I break a paragraph into sentences with Vim?
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?
vim macros
add a comment |
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?
vim macros
add a comment |
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?
vim macros
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?
vim macros
vim macros
edited May 21 '11 at 21:13
peth
7,13022338
7,13022338
asked Apr 26 '11 at 0:04
kirill_igum
59321028
59321028
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You can do a search and replace. I just wrote this out. It works, but you could probably do better.
:%s/v[ ]*([^.]*.)/1r/g
add a comment |
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>
.)
add a comment |
My solution, start in normal mode and type:
vip:'<,'>s/n/ /|'<,'>s/([.?!])s/1r/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.
add a comment |
I found that there is a very easy way of doing this using
vim-macros
.
- First in
normal mode
pressq
, then any key, suppose that key is
a
. So you will see something at the bottom asrecording @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, whereN
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.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f275364%2fhow-can-i-break-a-paragraph-into-sentences-with-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do a search and replace. I just wrote this out. It works, but you could probably do better.
:%s/v[ ]*([^.]*.)/1r/g
add a comment |
You can do a search and replace. I just wrote this out. It works, but you could probably do better.
:%s/v[ ]*([^.]*.)/1r/g
add a comment |
You can do a search and replace. I just wrote this out. It works, but you could probably do better.
:%s/v[ ]*([^.]*.)/1r/g
You can do a search and replace. I just wrote this out. It works, but you could probably do better.
:%s/v[ ]*([^.]*.)/1r/g
answered Apr 26 '11 at 0:12
Dan Loewenherz
24817
24817
add a comment |
add a comment |
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>
.)
add a comment |
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>
.)
add a comment |
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>
.)
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>
.)
answered May 2 '11 at 3:44
chisophugis
1585
1585
add a comment |
add a comment |
My solution, start in normal mode and type:
vip:'<,'>s/n/ /|'<,'>s/([.?!])s/1r/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.
add a comment |
My solution, start in normal mode and type:
vip:'<,'>s/n/ /|'<,'>s/([.?!])s/1r/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.
add a comment |
My solution, start in normal mode and type:
vip:'<,'>s/n/ /|'<,'>s/([.?!])s/1r/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.
My solution, start in normal mode and type:
vip:'<,'>s/n/ /|'<,'>s/([.?!])s/1r/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.
answered May 21 '11 at 21:34
Heptite
14.7k54157
14.7k54157
add a comment |
add a comment |
I found that there is a very easy way of doing this using
vim-macros
.
- First in
normal mode
pressq
, then any key, suppose that key is
a
. So you will see something at the bottom asrecording @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, whereN
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.
add a comment |
I found that there is a very easy way of doing this using
vim-macros
.
- First in
normal mode
pressq
, then any key, suppose that key is
a
. So you will see something at the bottom asrecording @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, whereN
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.
add a comment |
I found that there is a very easy way of doing this using
vim-macros
.
- First in
normal mode
pressq
, then any key, suppose that key is
a
. So you will see something at the bottom asrecording @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, whereN
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.
I found that there is a very easy way of doing this using
vim-macros
.
- First in
normal mode
pressq
, then any key, suppose that key is
a
. So you will see something at the bottom asrecording @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, whereN
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.
edited Dec 1 at 12:19
answered Dec 1 at 11:28
Galilean
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f275364%2fhow-can-i-break-a-paragraph-into-sentences-with-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown