Skip to main content
31 votes
Accepted

How to replace inner text with yanked text

You can use vi"p when inside "". This can replace text in yank register, so it matters when you want to use original yanked text more than once. EDIT: Additional info from Octaviour comment regarding ...
grodzik's user avatar
  • 4,668
28 votes
Accepted

Does "dap" delete everything?

"dap" does not actually delete everything. For example, try putting this into your buffer: 1 1 2 2 3 3 Then put your cursor on either '2' and type "dap". It'll leave the '1's and '3's. This is ...
DJMcMayhem's user avatar
  • 17.8k
25 votes
Accepted

How to delete all white spaces until first character?

You can either visually select the lines and use :'<,'>s/^\s*// Which means 'substitute all of the whitespaces following the first column of the line by nothing' Or go on the first line, use ...
statox's user avatar
  • 50.4k
22 votes

How to delete all white spaces until first character?

This works for me. esc : to enter vim command mode %s/^\s*//g Meaning: %s/<REGEX TO REPLACE>/<REPLACEMENT TEXT>/ for string substitution g for global (all lines) Regex matching ...
Ryan Mahaffey's user avatar
22 votes

I Have a Problem with Premature Yanking

The + and * registers can be used to access the clipboard; and you can assign values to registers with let @<register-name>. For example if you've pressed y to yank text to the "0 register: ...
Martin Tournoij's user avatar
20 votes
Accepted

Delete to EOL without entering insert mode

Yes. You want to use the "delete" operator instead of the "Change" operator. The delete operator is d<motion> and it deletes everything that <motion> moves over. In this case, the ...
DJMcMayhem's user avatar
  • 17.8k
20 votes

How to delete all white spaces until first character?

In addition to statox's methods, you can: Position the cursor at the beginning of the leading whitespace and type dw Position the cursor anywhere in the leading whitespace and type diw Position the ...
garyjohn's user avatar
  • 6,379
18 votes
Accepted

Paste visual block selection on its own lines

Try this: :put! " :put: insert the contents of the specified register !: insert before the current line (the default is after) ": the unnamed register (check :help registers for details) You could ...
mMontu's user avatar
  • 6,690
17 votes

Delete from cursor till nth occurence of character x

You can do this by typing <n>df<x> where: <n> is the number of occurrence of particular character df<x> means delete till you find the occurrence of character x
kapil's user avatar
  • 428
17 votes
Accepted

Copying multiple words (from different lines) and paste them at once

Use an uppercase register when yanking (copying): "Ay "A says to append to the a register, as opposed to "a which would replace the contents of the a register. Once you've copied everything into ...
8bittree's user avatar
  • 1,546
16 votes

How can I copy text to the system clipboard from Vim?

If you can't figure out how to get +clipboard to work, which I couldn't for some reason, then you can do this. Assuming you only want to copy a section of the file, I do shift+v to go into visual ...
425nesp's user avatar
  • 586
16 votes
Accepted

How can I delete in Vim all text from current cursor position to the end of file without using End key?

With your cursor in starting position to begin, you can do: vG$d v ( enter visual mode ) G ( go to bottom of file ) $ ( go to end of line ) d ( delete selection )
Zac's user avatar
  • 276
15 votes
Accepted

I Have a Problem with Premature Yanking

I’m going to go ahead and infer from your use of the word “select”, that you yanked via visual mode. If that’s the case, then you can use gv to reselect the previous selection. You can then yank to ...
Rich's user avatar
  • 32.4k
14 votes
Accepted

How to paste visual block starting with another line

When you copy some text, it goes into a register. The text inside a register has a type: characterwise, linewise or blockwise. This type determines in which way the text will be put. In your example,...
user9433424's user avatar
  • 6,178
14 votes
Accepted

Difference between "* and "+ registers in +clipboard VIM?

If you're on Mac or Windows, there's no difference. On Linux they are different. If you only work in Vim, you really don't need either of them (I mean that you can live without them), as they are ...
Enlico's user avatar
  • 2,256
14 votes
Accepted

how to yank from vim to system clipboard?

First get into an appropriate visual mode. v selects the standard visual mode, SHIFT-v selects visual-line mode, and CTRL-v selects visual block mode. Next, select the text that you want to select. ...
JMW's user avatar
  • 280
14 votes
Accepted

ci) - also delete the surrounding parens?

You can use the a variant: ca), ca]. The i is "inner", whereas the a is for "a" as in "a word", "a sentence", or "a [] block". I usually think of ...
Martin Tournoij's user avatar
13 votes

Vim on WSL: synchronize system clipboard? (set clipboard^=unnamed)?

I'm aware this is a very old question but I recently found a good solution. After much frustration, I came across these ways to access the windows system clipboard by copying and pasting. By copying, ...
questionmark's user avatar
13 votes

How to copy text with syntax highlighting?

It's a bit roundabout, but one way to achieve this with built-in tools is to use the :TOhtml command to create an HTML file that contains the highlighted text, open that file in a browser, and then ...
Rich's user avatar
  • 32.4k
13 votes

How can I delete in Vim all text from current cursor position to the end of file without using End key?

Remastered original answer Not the answer you are looking for but (unless we're playing Vim golf) I'd just type d$jdG or DjdG (as Izkata was kind enough to point out) and nothing fancy. That's ...
Friedrich's user avatar
  • 2,845
12 votes

How to replace inner text with yanked text

You can use the numbered register. First yank "foo-bar" with yi", which will fill the "0 register, see :h "0. Then do ci"<c-r>0 to replace with the content of the register 0. See :h i_CTRL-R ...
Karl Yngve Lervåg's user avatar
12 votes
Accepted

How to copy lines from 4th till 11th and paste it from 15th till 22th line in ex mode?

I'm not sure if I understand you correctly but is this what you're looking for? :4,11t 15 This will copy lines from 4 to 11 and paste it on line 15. See :h co for more.
dkns's user avatar
  • 619
12 votes
Accepted

Repeat last yank

If you include the flag y in the cpoptions option; set cpoptions+=y then yanks may be repeated using .. See :help cpo-y: *cpo-y* y A yank command can be redone ...
Mass's user avatar
  • 14.2k
12 votes
Accepted

Deleting lines matching a pattern and put them into the buffer

You could delete the lines in a register: First clean up your register q for example with qqq in normal mode. Then use :g/PATTERN/norm! "Qdd In normal mode when you use "qdd you replace the ...
statox's user avatar
  • 50.4k
12 votes
Accepted

Why does `p` not put all yanked lines after quitting and reopening Vim?

When you quit Vim, your registers' contents will be saved to a viminfo file. See :help viminfo for all the details. What and how much is saved is controlled by the 'viminfo' option, which is ...
Friedrich's user avatar
  • 2,845
11 votes

Replace . with -> in specific places

You could use the s operator, which deletes the character under your cursor and puts you in insert mode. You can then type the replacement and later use . to repeat the whole replacement. Workflow ...
Tumbler41's user avatar
  • 7,786
11 votes
Accepted

How to select the content within brackets including brackets and without including brackets?

You can use text objects to accomplish this. Start a selection with v and then: For selecting inside use: i{ For selecting the whole block including braces use: a{ You can also do this with any ...
Tumbler41's user avatar
  • 7,786
11 votes
Accepted

Replacing text with a visual block

Assuming we are on the topleft v: Ctrl-vjly (yank the block) jj (move to start of next block) 1v (select a block the same size as our last visual selection) p (paste) See :help CTRL-V, which takes a ...
D. Ben Knoble's user avatar
  • 27.3k
10 votes
Accepted

What is the use case for the weird paste behavior?

Why exactly does this character sequence, jkeS, causes this behavior? What is going on behind the scenes? Your gpg key contains jk which you likely mapped to <Esc> (it is very common) so: Vim ...
romainl's user avatar
  • 41.9k
10 votes

Pasting text on Vim inside tmux breaks indentation

Manually toggling :set paste/:set nopaste as suggested by francois P is cumbersome, and resetting the TERM variable as evaristegd suggests is a very bad idea as explained in the comments (which hint ...
Dining Philosopher's user avatar

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