101 votes
Accepted

How can I yank (copy) the single character on which the cursor rests?

Composing the yank operation with the so often used "one character to the right" motion should work: yl. BTW (to comment on a OP comment), for me » can be yanked in this manner, in gVim or terminal ...
VanLaser's user avatar
  • 9,680
31 votes

How can I easily move a line?

If I want to swap one line with the line above I usually do the following ddkP Explanation dd will delete the line and add it to the default register. k will move up a line (j would move down a ...
venkatvb's user avatar
  • 411
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,568
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.5k
27 votes
Accepted

How do I copy a file in netrw?

You cannot use y, p etc., to copy files in netrw - it comes with its own commands. See :h netrw-mc: MARKED FILES: COPYING netrw-mc {{{2 (See ...
muru's user avatar
  • 24.8k
23 votes

How can I yank (copy) the single character on which the cursor rests?

Usually I press vy (visual yank), sometimes xu (delete undo) too. Also , if you want to yank the char before your cursor, instead of lvy, you can press Xu, I think that's the reason why I press xu for ...
Kent's user avatar
  • 1,310
23 votes
Accepted

Why did p paste a copied line after the current line, instead of after the current word?

When you deleted the line using dd, you performed a linewise delete. The p command pastes after the cursor position. Since the default register was populated with linewise content, that means it ...
jamessan's user avatar
  • 11k
23 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
  • 49.6k
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
Accepted

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

I found a paper "An Introduction to Display Editing with Vi" by William Joy (vi creator) and Mark Horton (vi maintainer since 1979). From the paper it is clear that the default Y behavior is not a ...
Borys Serebrov'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
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.5k
20 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
19 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,299
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,086
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,610
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
16 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,527
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
  • 31.6k
14 votes

How to replace text inside () with previously yanked text?

You can use visual selection to select the text to replace, and then paste over it as follows: vi(p vi( selects Baz (because it is enclosed in parenthesis), p pastes Fnord over it. However, this ...
Alex's user avatar
  • 1,293
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,750
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
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,118
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
  • 31.6k
13 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,184
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
  • 1,648

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