New answers tagged

1

:h quote_ : 9. Black hole register "_ *quote_* When writing to this register, nothing happens. This can be used to delete text without affecting the normal registers. When reading from this register, nothing is returned. You could map it like that: vnoremap d "_d


1

You could use substitute() on the contents of the register to make a replacement, and use a :let command to assign it back to the clipboard register. For example, start by copying it to the default register in step 4, with y (instead of "+y.) And then use the :let command to apply a substitute() on the contents of the default register and assign that to ...


3

You can append to the named registers "a through "z, in which case you use the lowercase versions of the registers to overwrite/replace their contents and the uppercase version to append to their contents. So you can use "a3yy (or 3"ayy) for the initial yank of 3 lines, then "A5yy (or 5"Ayy) to append the 5 next lines to that ...


1

Visual block mode is a good route.... Put cursor on "a" in apple <C-V> : we'll visually select the whole block... move cursor to banana, e.g. }k is good (line count agnostic) $A<space><esc> - this adds a space after every line gvd - gv recreates the previous visual selection, d deletes Move cursor to "t" in tomato and ...


2

There's indeed more straight-forward ways to do this. As you can see in the help for :h d *d* ["x]d{motion} Delete text that {motion} moves over [into register x]. See below for exceptions. The delete command, as many, accepts a motion. This means you can tell Vim what object you want to delete (diw for &...


3

You can use the f or t motions for this. With your cursor at the start of the text you want to delete: h5 style=("text-align: center; margin-top: 2rem;") some text ^ Type either of these: df; dt" The first deletes up to and including the ; character, the second deletes up to but not including the ". See :...


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. ...


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 ...


Top 50 recent answers are included