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,658
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.7k
24 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.1k
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
21 votes

Why is Y a synonym for yy instead of y$?

Y was the yank command of the first vi version (ex-1.1, January 1, 1978). This version did not have the yy cammand. ex-2.2 (May 6, 1979) did have both yy and Y. So actually yy is a synonym for Y (Y ...
user3224237's user avatar
21 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
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.7k
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,369
18 votes
Accepted

How to copy first four characters of every line to the end of that same line?

:% s/\v^(\d{4})(.*)$/\1\2 \1/ is one way to do it \v magic option, to avoid having to escape grouping () ^ start of line \d{4} match exactly four digits .* rest of line \1 \2 has the matched ...
Sundeep's user avatar
  • 1,096
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,670
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
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

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
  • 576
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.2k
14 votes

How can I easily list the content of the registers before pasting?

This peekaboo plugin is pretty good for for previewing registers. When you press " or @ in normal mode, or ctrl-r in insert mode, a split will open to show you the register contents. Preview from ...
Tommy A's user avatar
  • 6,790
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,148
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,224
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.2k
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,225
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
  • 599
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
11 votes

How to copy first four characters of every line to the end of that same line?

And a solution with a macro: qqyiwA <Esc>pj0q Which means: qq Record the macro in the register q yiw Yank the text described by the text object iw (inner word): The date A <Esc> ...
statox's user avatar
  • 50.1k
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,756
11 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.1k
10 votes
Accepted

Can I yank from the current position of the cursor to the end of the line without the newline?

Does y$ Not solve your problem? Yank to the end of line.
Loki Astari's user avatar
  • 6,650

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