Hot answers tagged

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
grodzik's user avatar
  • 4,488
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 ...
daviewales's user avatar
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 ...
Matt's user avatar
  • 20.1k
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 "...
filbranden's user avatar
  • 28.1k
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 ...
statox's user avatar
  • 49k
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. [...
Martin Tournoij's user avatar
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, ...
doraemon's user avatar
  • 1,647
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 ...
DJMcMayhem's user avatar
  • 17.3k
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 <...
Matt's user avatar
  • 20.1k
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 ...
D. Ben Knoble's user avatar
  • 24.8k
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 ~ ...
dedowsdi's user avatar
  • 6,148
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 ...
mattb's user avatar
  • 1,081
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
Jan P's user avatar
  • 31
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 ...
Martin Tournoij's user avatar
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
D. Ben Knoble's user avatar
  • 24.8k
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 ...
Jürgen Krämer's user avatar
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 ...
Maxim Kim's user avatar
  • 12.3k
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 ...
user985675's user avatar
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 ...
Ralf's user avatar
  • 9,037
1 vote

How to join lines within a block with `J`?

The commandline command you're looking for is 'j': :1,5j
Jhal's user avatar
  • 119
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 ...
DJMcMayhem's user avatar
  • 17.3k

Only top scored, non community-wiki answers of a minimum length are eligible