Is there a command to split lines in Vim?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
In Vim, the J key joins two lines together. Is there a similar, built-in, key combination to split lines with a newline (at the cursor position, or similar)?
Alternatively, what would be the most robust way to define a key combination to do that (in normal mode, not insert mode)?
vim vi
add a comment |
In Vim, the J key joins two lines together. Is there a similar, built-in, key combination to split lines with a newline (at the cursor position, or similar)?
Alternatively, what would be the most robust way to define a key combination to do that (in normal mode, not insert mode)?
vim vi
See also: stackoverflow.com/questions/624821/vim-split-line-command
– dreftymac
Jan 7 '17 at 15:36
add a comment |
In Vim, the J key joins two lines together. Is there a similar, built-in, key combination to split lines with a newline (at the cursor position, or similar)?
Alternatively, what would be the most robust way to define a key combination to do that (in normal mode, not insert mode)?
vim vi
In Vim, the J key joins two lines together. Is there a similar, built-in, key combination to split lines with a newline (at the cursor position, or similar)?
Alternatively, what would be the most robust way to define a key combination to do that (in normal mode, not insert mode)?
vim vi
vim vi
edited Jun 11 '17 at 11:31
Peter Mortensen
8,386166185
8,386166185
asked Jun 24 '13 at 15:12
Andrew FerrierAndrew Ferrier
89931334
89931334
See also: stackoverflow.com/questions/624821/vim-split-line-command
– dreftymac
Jan 7 '17 at 15:36
add a comment |
See also: stackoverflow.com/questions/624821/vim-split-line-command
– dreftymac
Jan 7 '17 at 15:36
See also: stackoverflow.com/questions/624821/vim-split-line-command
– dreftymac
Jan 7 '17 at 15:36
See also: stackoverflow.com/questions/624821/vim-split-line-command
– dreftymac
Jan 7 '17 at 15:36
add a comment |
5 Answers
5
active
oldest
votes
No, there's no built-in command for that.
When I want to split on a <Space>
, I do r<CR>
.
--- EDIT ---
@keith-nicholas' comment reminded me about this question. FWIW I came up with an hopefully "universal" method in the mean time:
function! BreakHere()
s/^(s*)(.{-})(s*)(%#)(s*)(.*)/12r146
call histdel("/", -1)
endfunction
nnoremap <key> :<C-u>call BreakHere()<CR>
3
Usingr<CR>
is simply clever! Thanks!
– Marcelo
Apr 8 '17 at 13:33
that's great! super annoying going into insert to insert lines
– Keith Nicholas
Jul 13 '17 at 4:06
I founds<CR>
keeps indentation whereasr<CR>
does not.
– py4on
Mar 1 at 11:41
add a comment |
a
Enter Esc to split to the right of the cursor, or i
Enter Esc to split to the left.
1
That is it. Just insert a single newline. Alternatively: use r+<return> to replace the character under the cursor with a newline. Would be nice to have a single letter command for it, but as far as I know there isn't one.
– Tonny
Jun 24 '13 at 15:23
add a comment |
You could define your own using map. To define z as the command for example:
:map z i<CTRL+m>
add a comment |
The easiest way I've found to split lines in Vim is the normal mode command gq
(type both letters in quick succession in normal or visual mode):
- In visual mode, it will split whatever is selected.
- In normal mode, you follow
gq
with a motion.
For example, gql
will split one line to the currently set width. To set the width of the split lines to be different from your current setting, you can use
:set textwidth=<n>
Where n=number of characters you want in a line, e.g., 10, and change back to your normal width when you're done.
Got this information from a Youtube video by Kholidfu that shows how to join and split lines in normal mode using a motion: Vim Tutorial - Join and Split Lines.
add a comment |
You can record a macro:
in normal mode type "q+" to start the record.
press "i", the macro you want to record.
then press "q" again to stop recording.
to use the macro go to normal mode and type "@+letter".
in my case I used the "b" to use this macro:
to record type in normal mode "qbiq"
to use type in normal mode "@b"
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%2f611410%2fis-there-a-command-to-split-lines-in-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
No, there's no built-in command for that.
When I want to split on a <Space>
, I do r<CR>
.
--- EDIT ---
@keith-nicholas' comment reminded me about this question. FWIW I came up with an hopefully "universal" method in the mean time:
function! BreakHere()
s/^(s*)(.{-})(s*)(%#)(s*)(.*)/12r146
call histdel("/", -1)
endfunction
nnoremap <key> :<C-u>call BreakHere()<CR>
3
Usingr<CR>
is simply clever! Thanks!
– Marcelo
Apr 8 '17 at 13:33
that's great! super annoying going into insert to insert lines
– Keith Nicholas
Jul 13 '17 at 4:06
I founds<CR>
keeps indentation whereasr<CR>
does not.
– py4on
Mar 1 at 11:41
add a comment |
No, there's no built-in command for that.
When I want to split on a <Space>
, I do r<CR>
.
--- EDIT ---
@keith-nicholas' comment reminded me about this question. FWIW I came up with an hopefully "universal" method in the mean time:
function! BreakHere()
s/^(s*)(.{-})(s*)(%#)(s*)(.*)/12r146
call histdel("/", -1)
endfunction
nnoremap <key> :<C-u>call BreakHere()<CR>
3
Usingr<CR>
is simply clever! Thanks!
– Marcelo
Apr 8 '17 at 13:33
that's great! super annoying going into insert to insert lines
– Keith Nicholas
Jul 13 '17 at 4:06
I founds<CR>
keeps indentation whereasr<CR>
does not.
– py4on
Mar 1 at 11:41
add a comment |
No, there's no built-in command for that.
When I want to split on a <Space>
, I do r<CR>
.
--- EDIT ---
@keith-nicholas' comment reminded me about this question. FWIW I came up with an hopefully "universal" method in the mean time:
function! BreakHere()
s/^(s*)(.{-})(s*)(%#)(s*)(.*)/12r146
call histdel("/", -1)
endfunction
nnoremap <key> :<C-u>call BreakHere()<CR>
No, there's no built-in command for that.
When I want to split on a <Space>
, I do r<CR>
.
--- EDIT ---
@keith-nicholas' comment reminded me about this question. FWIW I came up with an hopefully "universal" method in the mean time:
function! BreakHere()
s/^(s*)(.{-})(s*)(%#)(s*)(.*)/12r146
call histdel("/", -1)
endfunction
nnoremap <key> :<C-u>call BreakHere()<CR>
edited Jul 13 '17 at 11:23
answered Jun 24 '13 at 15:23
romainlromainl
18.1k23446
18.1k23446
3
Usingr<CR>
is simply clever! Thanks!
– Marcelo
Apr 8 '17 at 13:33
that's great! super annoying going into insert to insert lines
– Keith Nicholas
Jul 13 '17 at 4:06
I founds<CR>
keeps indentation whereasr<CR>
does not.
– py4on
Mar 1 at 11:41
add a comment |
3
Usingr<CR>
is simply clever! Thanks!
– Marcelo
Apr 8 '17 at 13:33
that's great! super annoying going into insert to insert lines
– Keith Nicholas
Jul 13 '17 at 4:06
I founds<CR>
keeps indentation whereasr<CR>
does not.
– py4on
Mar 1 at 11:41
3
3
Using
r<CR>
is simply clever! Thanks!– Marcelo
Apr 8 '17 at 13:33
Using
r<CR>
is simply clever! Thanks!– Marcelo
Apr 8 '17 at 13:33
that's great! super annoying going into insert to insert lines
– Keith Nicholas
Jul 13 '17 at 4:06
that's great! super annoying going into insert to insert lines
– Keith Nicholas
Jul 13 '17 at 4:06
I found
s<CR>
keeps indentation whereas r<CR>
does not.– py4on
Mar 1 at 11:41
I found
s<CR>
keeps indentation whereas r<CR>
does not.– py4on
Mar 1 at 11:41
add a comment |
a
Enter Esc to split to the right of the cursor, or i
Enter Esc to split to the left.
1
That is it. Just insert a single newline. Alternatively: use r+<return> to replace the character under the cursor with a newline. Would be nice to have a single letter command for it, but as far as I know there isn't one.
– Tonny
Jun 24 '13 at 15:23
add a comment |
a
Enter Esc to split to the right of the cursor, or i
Enter Esc to split to the left.
1
That is it. Just insert a single newline. Alternatively: use r+<return> to replace the character under the cursor with a newline. Would be nice to have a single letter command for it, but as far as I know there isn't one.
– Tonny
Jun 24 '13 at 15:23
add a comment |
a
Enter Esc to split to the right of the cursor, or i
Enter Esc to split to the left.
a
Enter Esc to split to the right of the cursor, or i
Enter Esc to split to the left.
answered Jun 24 '13 at 15:17
ScottScott
16.2k113990
16.2k113990
1
That is it. Just insert a single newline. Alternatively: use r+<return> to replace the character under the cursor with a newline. Would be nice to have a single letter command for it, but as far as I know there isn't one.
– Tonny
Jun 24 '13 at 15:23
add a comment |
1
That is it. Just insert a single newline. Alternatively: use r+<return> to replace the character under the cursor with a newline. Would be nice to have a single letter command for it, but as far as I know there isn't one.
– Tonny
Jun 24 '13 at 15:23
1
1
That is it. Just insert a single newline. Alternatively: use r+<return> to replace the character under the cursor with a newline. Would be nice to have a single letter command for it, but as far as I know there isn't one.
– Tonny
Jun 24 '13 at 15:23
That is it. Just insert a single newline. Alternatively: use r+<return> to replace the character under the cursor with a newline. Would be nice to have a single letter command for it, but as far as I know there isn't one.
– Tonny
Jun 24 '13 at 15:23
add a comment |
You could define your own using map. To define z as the command for example:
:map z i<CTRL+m>
add a comment |
You could define your own using map. To define z as the command for example:
:map z i<CTRL+m>
add a comment |
You could define your own using map. To define z as the command for example:
:map z i<CTRL+m>
You could define your own using map. To define z as the command for example:
:map z i<CTRL+m>
answered Jun 24 '13 at 15:23
suspectussuspectus
3,71162031
3,71162031
add a comment |
add a comment |
The easiest way I've found to split lines in Vim is the normal mode command gq
(type both letters in quick succession in normal or visual mode):
- In visual mode, it will split whatever is selected.
- In normal mode, you follow
gq
with a motion.
For example, gql
will split one line to the currently set width. To set the width of the split lines to be different from your current setting, you can use
:set textwidth=<n>
Where n=number of characters you want in a line, e.g., 10, and change back to your normal width when you're done.
Got this information from a Youtube video by Kholidfu that shows how to join and split lines in normal mode using a motion: Vim Tutorial - Join and Split Lines.
add a comment |
The easiest way I've found to split lines in Vim is the normal mode command gq
(type both letters in quick succession in normal or visual mode):
- In visual mode, it will split whatever is selected.
- In normal mode, you follow
gq
with a motion.
For example, gql
will split one line to the currently set width. To set the width of the split lines to be different from your current setting, you can use
:set textwidth=<n>
Where n=number of characters you want in a line, e.g., 10, and change back to your normal width when you're done.
Got this information from a Youtube video by Kholidfu that shows how to join and split lines in normal mode using a motion: Vim Tutorial - Join and Split Lines.
add a comment |
The easiest way I've found to split lines in Vim is the normal mode command gq
(type both letters in quick succession in normal or visual mode):
- In visual mode, it will split whatever is selected.
- In normal mode, you follow
gq
with a motion.
For example, gql
will split one line to the currently set width. To set the width of the split lines to be different from your current setting, you can use
:set textwidth=<n>
Where n=number of characters you want in a line, e.g., 10, and change back to your normal width when you're done.
Got this information from a Youtube video by Kholidfu that shows how to join and split lines in normal mode using a motion: Vim Tutorial - Join and Split Lines.
The easiest way I've found to split lines in Vim is the normal mode command gq
(type both letters in quick succession in normal or visual mode):
- In visual mode, it will split whatever is selected.
- In normal mode, you follow
gq
with a motion.
For example, gql
will split one line to the currently set width. To set the width of the split lines to be different from your current setting, you can use
:set textwidth=<n>
Where n=number of characters you want in a line, e.g., 10, and change back to your normal width when you're done.
Got this information from a Youtube video by Kholidfu that shows how to join and split lines in normal mode using a motion: Vim Tutorial - Join and Split Lines.
edited Jun 13 '17 at 15:24
Greenonline
1,2733923
1,2733923
answered Jun 13 '17 at 14:12
vdicarlovdicarlo
111
111
add a comment |
add a comment |
You can record a macro:
in normal mode type "q+" to start the record.
press "i", the macro you want to record.
then press "q" again to stop recording.
to use the macro go to normal mode and type "@+letter".
in my case I used the "b" to use this macro:
to record type in normal mode "qbiq"
to use type in normal mode "@b"
add a comment |
You can record a macro:
in normal mode type "q+" to start the record.
press "i", the macro you want to record.
then press "q" again to stop recording.
to use the macro go to normal mode and type "@+letter".
in my case I used the "b" to use this macro:
to record type in normal mode "qbiq"
to use type in normal mode "@b"
add a comment |
You can record a macro:
in normal mode type "q+" to start the record.
press "i", the macro you want to record.
then press "q" again to stop recording.
to use the macro go to normal mode and type "@+letter".
in my case I used the "b" to use this macro:
to record type in normal mode "qbiq"
to use type in normal mode "@b"
You can record a macro:
in normal mode type "q+" to start the record.
press "i", the macro you want to record.
then press "q" again to stop recording.
to use the macro go to normal mode and type "@+letter".
in my case I used the "b" to use this macro:
to record type in normal mode "qbiq"
to use type in normal mode "@b"
answered Feb 7 at 11:14
luizhjluizhj
1
1
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.
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%2f611410%2fis-there-a-command-to-split-lines-in-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
See also: stackoverflow.com/questions/624821/vim-split-line-command
– dreftymac
Jan 7 '17 at 15:36