Hot answers tagged

6

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


5

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 use of :h g@ and :h 'opfunc' A simplified example: " very basic "join" operator nnoremap <silent>J :set opfunc=OperJoin<CR>g@ function! OperJoin(type)...


4

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 "type" of the register, where you can pass 'c' or 'v' to make it a "characterwise" mode register. Assuming you deleted your block into the default ...


4

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 visual block mode, the first step is to get back a list containing every lines. To do that you can use :h getreg() like this: getreg('"', 1, 1) The first ...


4

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. [..] So the solution is to add an empty string in the second sep parameter: :echo join([expand('%:p:r'), '.pdf']) /usr/share/vim/vim81/doc/eval .pdf :echo ...


4

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, so eventually the order of the two lines are exchanged.


3

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 options: :nnoremap <leader>J ddpkJ


2

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 <silent>gJ :join!<CR>


2

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 join operator. Here, even v%J should work Alternately, use :join, which takes a range, and ranges can be quite powerful: .,/}/join


1

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 whitespace with a single space" which can be done with :%s/\s*\n\s\+/ \1/g @filbranden correctly pointed out the shortcomings of this single substitution. ...


1

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 ~ Becomes: int i; // the index in the list ~ ... default formatoptions in vim8 : tcq default formatoptions in neovim : tcqj


1

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 function, to create the text displayed on a closed fold. The documentation :help fold-foldtext contains an example. Note that the resulting text is truncated to fit ...


1

The commandline command you're looking for is 'j': :1,5j


1

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 the problem is that the second line i.e. <line value="abc" value2="def"/> Is also matched by <line/,/\/> so this line is joined with the next ...


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