by Ingo Karkat
This plugin ...
(Original Vim tip, Stack Overflow answer, ...)
(Plugins offering complementary functionality, or plugins using this library.)
(Alternatives from other authors, other approaches, references not used here.)
[count]["x]dJ Delete the following [count] lines.
:[range]JoinFolded[!] [{separator}]
Join all folded lines into a single long line
separated by a space (or passed {separator}).
With [!] the join does not insert or delete any
spaces.
[count]J For me, this means "execute J [count] times", not the
default "Join [count] lines", which joins one line
less that expected.
[count]g\J, {Visual}g\J Join lines removing a line continuation character from
the end of each line (\ by default) in all consecutive
lines that end with the line continuation character
(or {count} times); whitespace before and after it is
condensed to a single space.
[count]gcJ, {Visual}gcJ Join lines removing any leading comment characters and
following indentation. This works like adding "j" to
'formatoptions'.
:: This is a gcJ :: This is a multiline gcJ :: This is a multiline comment.
:: multiline --------> :: comment. -------->
:: comment.
On non-comment lines: Fuse lines together, i.e. join
and remove any hyphen, whitespace and following
indentation.
The foo- gcJ The foobar can be ta- gcJ The foobar can be taken off.
bar can be ta- --------> ken off. -------->
ken off.
[count]gqJ, {Visual}gqJ Join lines removing any diff quirks (leading + / -,
possibly preceded by a ^M) in between.
[count]gcqJ, {Visual}gcqJ
Join lines removing any diff quirks (leading + / -,
possibly preceded by a ^M) and following comment
characters and indentation.
[count]gsJ, {Visual}gsJ Join lines removing any trailing and leading
whitespace completely.
[count]["x]g#J Join lines on the final keywords / non-whitespace
{Visual}["x]g#J non-keywords in the first line, removing everything up
to that same text on following line(s) (and put that
into the default register / register x).
let foo = g#J let foo = "goodbye"
let bar = "goodbye" -------->
:[range]Join[!] {separator}
Join lines in [range] with {separator} in between.
With [!] does not remove spaces.
[count]<Leader>j Query a separator string that is inserted between all
{Visual}<Leader>j joined lines; indent is removed.
[count]<Leader>J Join with the previously queried separator string.
{Visual}<Leader>J
[count]<Leader>gj Query a separator string that is inserted between all
{Visual}<Leader>gj joined lines. Don't remove any spaces, like gJ.
[count]<Leader>gJ Like above, with the previously queried separator
{Visual}<Leader>gJ string.
:[range]Unjoin[!] [{pattern}]
Un-join current line / lines in [range] whereever
{pattern} (or the previously queried separator
pattern of a mapping) matches.
With [!] does not indent the added lines, and does not
automatically insert the current comment leader.
[count]<Leader>uj Query a separator pattern and un-join [count] lines,
{Visual}<Leader>uj i.e. replace each separator match with a <CR> and
proper indent.
[count]<Leader>uJ Un-join on the previously queried separator pattern.
{Visual}<Leader>uJ
The code is hosted in a Git repo at https://github.com/inkarkat/vim-AdvancedJoiners You can use your favorite plugin manager, or "git clone" into a directory used for Vim packages. Releases are on the "stable" branch, the latest unstable development snapshot on "master".
This script is also packaged as a vimball. If you have the "gunzip" decompressor in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress the archive first, e.g. using WinZip. Inside Vim, install by sourcing the vimball or via the :UseVimball command.
vim AdvancedJoiners*.vmb.gz
:so %
To uninstall, use the :RmVimball command.
- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.044 or higher.
For a permanent configuration, put the following commands into your vimrc:
plugmap
The gcJ command also removes comment prefixes defined in the whitelist of the IndentCommentPrefix.vim plugin (vimscript #2529) (see|g:IndentCommentPrefix_Whitelist|).
Report any bugs, send patches, or suggest features via the issue tracker at https://github.com/inkarkat/vim-AdvancedJoiners/issues or email (address below).
First published version.
- Started development.
Copyright: (C) 2005-2022 Ingo Karkat - The VIM LICENSE applies to this plugin.
Maintainer: Ingo Karkat <ingo@karkat.de>