7
votes
Accepted
Join the line above the current line
I'm almost sure there is no such mapping. As you wrote, one can use kJ. But if you aren't using K, you can remap it to kJ:
nnoremap K kJ
6
votes
Join multiple lines based on pattern
I found something on the Vim wiki that combines ranges with searches.
This command did the trick for me:
:g/^"/,/"$/j
e.g.
:g (global)
/^"/,/"$/ (a range between a line ...
5
votes
How to join lines within a block with `J`?
This is called "a motion". Even though linewise motions result in a line range.
Normally, it's enough to do 5J and there's no need for "join" operator. However, if you really want it, you can make ...
4
votes
Accepted
Paste a block-copy into a single line
You can use setreg() to manipulate the contents of the register, after you delete into it from the visual block. Note that setreg() takes an optional third argument that you can use to set the "...
4
votes
Paste a block-copy into a single line
Here is one way to achieve what you want to do. I think another solution could be to use a macro but getting back at the right position might not always be trivial.
So once you yanked your column in ...
4
votes
Accepted
Preventing the join() command from adding extra space
From :help join():
join({list} [, {sep}])
[..]
When {sep} is specified it is put in between the items. If
{sep} is omitted a single space is used.
[...
4
votes
Accepted
Prepend line underneath current line (or "join" to front of line)
If you don't want to use any register, you can do
:+m- | normal J
or use mapping
:nnoremap <leader>J :<c-u>+m-<cr>J
:+m- is to move the next line to be after the previous line, ...
3
votes
Prepend line underneath current line (or "join" to front of line)
Just swap the lines before you join them:
ddpkJ
Of course, if you would like to override J's behavior, you could map this with:
:nnoremap J ddpkJ
or if you want a new mapping so that you have both ...
2
votes
Accepted
Is it possible to ignore J if only one line is selected?
As :join[!] command does not really do anything if range has equal start and end values, you can make use of it instead of original J / gJ
xnoremap <silent>J :join<CR>
xnoremap <...
2
votes
How to join lines within a block with `J`?
Well, since J works in visual mode...
va{J
More generally v[motion or text object]J. Normally I would say this is a bit of an anti-pattern (prefer [operator][motion or text object]), but there is no ...
2
votes
Accepted
use J to join comments
set fo+=j
:h fo-table:
...
j Where it makes sense, remove a comment leader when joining lines. For
example, joining:
int i; // the index ~
// in the list ~
...
2
votes
Remove blank lines appearing between non-blank lines without a regex?
If you're on linux, you could call an external program to filter a range of
lines (here I filter all of them with %):
:%! awk NF
In the above awk command, NF indicates the total number of fields, and ...
2
votes
How to only join lines that start with multiple spaces
Turns out since I need to join current line to above line and not the below line to the current line, -j has to be used like so:
:g/ \{2,}/-j
2
votes
How to join multiple lines which doesn't include space at the end
Personally I wouldn't use a macro but :substitute; this seems to do what you want:
:%s/\([^.?!]\)\n/\=(submatch(1) == ',' ? '' : submatch(1)) .. ' '/
In the find pattern:
\([^.?!]\)\n
The \n is a ...
1
vote
Remove blank lines appearing between non-blank lines without a regex?
This technically involves a regular expression, but if it's only a single blank line:
:global/./join
" aka
:g/./j
1
vote
Remove blank lines appearing between non-blank lines without a regex?
Use a recursive mapping. Define it with
:nmap <F2> gg}gJ<F2>
and then press F2. The mapping will go to the start of the file (gg), search for the next empty line (}), and try to to join ...
1
vote
Join contiguous lines of natural text and leave adjacent, non-connected lines
Imagine you have a program (naturaljoin) that does that analysis and produce the result you need.
Then you can filter buffer contents using it:
:%!naturaljoin
Help topic :h filter might be worth ...
1
vote
Paste a block-copy into a single line
Not sure if the pattern is true for your entire file, but your example can be interpreted as:
"For all lines beginning with whitespace, replace the preceding whitespace, linebreak and beginning ...
1
vote
Vim: Foldtext contain all content, instead of only the first line
The option foldtext defines a expression, that is evaluated to create the text displayed for a closed fold. By default this is set to the build in function foldtext().
You can create a custom ...
1
vote
How to join lines within a block with `J`?
The commandline command you're looking for is 'j':
:1,5j
1
vote
Accepted
How do I remove newlines inside arbitrary xml tags matching a pattern?
First off, I never knew that you can have a search in the range. Thanks for making me learn something new!
Second off, you were really close with :g/<line/,/\/>/join. But I'm pretty sure that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
join × 19regular-expression × 4
functions × 2
replace × 2
options × 2
whitespace × 2
multiple-lines × 2
vimscript × 1
key-bindings × 1
neovim × 1
search × 1
cut-copy-paste × 1
substitute × 1
folding × 1
formatting × 1
macro × 1
comments × 1
filetype-markdown × 1
visual-block × 1
global-command × 1
original-vim × 1
string-manipulation × 1
object-motions × 1
set × 1
selection × 1