Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
517 votes
Accepted

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

For X11-based systems (ie. Linux and most other UNIX-like systems) there are two clipboards which are independent of each other: PRIMARY - This is copy-on-select, and can be pasted with the middle ...
user avatar
116 votes
Accepted

How can I easily move a line?

First, you do not need to yank and delete; the latter will also put the deleted contents into the (default or specified) register. Therefore, ddp / ddkP are common commands to move a line one down / ...
user avatar
  • 16.6k
85 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 ...
user avatar
  • 9,260
78 votes

How can I easily move a line?

The easiest is: :m+ or :m-2 which is abbreviation for :move as Ingo suggested. Or using visual mode (V) by cutting the line (d/x) then paste it (p - below cursor, P above cursor) after you moved your ...
user avatar
  • 16.5k
77 votes

How do I delete a large block of text without counting the lines?

In Vim, use visual line mode: Put your cursor on the top line of the block of text/code to remove Press V (That's capital "V" : Shift + v ) Move your cursor down to the bottom of the block of text/...
user avatar
  • 8,739
68 votes
Accepted

How to yank a line with a certain line number?

From :help :yank: :[range]y[ank] [x] Yank `[range]` lines [into register x]. So, to yank line 4, one would type: :4yank Note you can easily do this from insert mode with <C-o>; this ...
user avatar
46 votes

How do I delete a large block of text without counting the lines?

You can easily delete large block of text if you know its structure. If it's a paragraph, use d{ or d} or dap (or 3d{ for 3 paragraphs and so on). If it's within parenthesis, use d% or dab or da( or ...
user avatar
  • 16.5k
44 votes

Is there a text object for the entire buffer?

Since vim uses the percent sign to reference the current buffer, you can use it to get everything quickly. :%y will yank the entire buffer :%y+ will yank it to the + register (and presumably the ...
user avatar
43 votes

How do I delete a large block of text without counting the lines?

You can :set relativenumber, so you don't have to count. ;)
user avatar
42 votes

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

From http://vim.wikia.com/wiki/Accessing_the_system_clipboard set clipboard=unnamedplus This changes the default Vim register to the + register, which is linked to the system clipboard. From :h ...
user avatar
40 votes

How to yank a line with a certain line number?

In addition to Carpetsmoker's answer, I should point out the awesome :help :m and :help :t. If you want to copy line 4 to right below the current line you can do this: :4t. or that, if you want to ...
user avatar
  • 32.6k
38 votes
Accepted

Performing certain operations without clearing register

Your options are: Use the black hole register _. For example, to delete a line you would type "_dd. This deletes without affecting the clipboard. Explicitly name a register for the original yank. ...
user avatar
37 votes

How to replace a word with a yanked word in normal mode

Assuming you've already yanked foo with ye or something similar, and that the cursor is somewhere on foo, you can use Wvep: W to go to bar (this is obviously optional and will depend on the current ...
user avatar
32 votes
Accepted

How can I map d[count]d?

Operator-pending mode Between typing an operator (like d, c, or gU) and a motion (like w, i}, or /foo<CR>), Vim is in Operator-pending mode. You can create mappings for this using :omap and :...
user avatar
  • 7,140
29 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 ...
user avatar
  • 391
29 votes
Accepted

Delete from cursor till nth occurence of character x

You can do : wd4/x<Enter> If you start on the top left of your text Explanation w : move to beginning of next word d : delete 4/x<Enter> : until the 4th occurence of x If you don't ...
user avatar
  • 1,092
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 ...
user avatar
  • 16.5k
26 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 ...
user avatar
  • 4,208
25 votes

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

On builds that support it, the register named * is the system clipboard. To copy text from Vim to the system clipboard, you can select the text using visual mode, then press "*y to copy it to the ...
user avatar
  • 8,739
25 votes
Accepted

How do I visually select the block of text I just pasted in Vim?

The '[ and '] marks delimit the first and last line of the previously changed or yanked text. The `[ and `] counterparts delimit the respective lines & columns. Using that, you could visually ...
user avatar
  • 10.3k
25 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 ...
user avatar
  • 23.7k
24 votes

How do I delete a large block of text without counting the lines?

You can use motions and/or text objects. For instance, you can delete everything from the cursor to the next blank line with d}. If the cursor is inside a paragraph, the paragraph may be deleted with ...
user avatar
24 votes
Accepted

Delete from cursor till first character x (spanning multiple lines)

Use / for forward search: d/x<CR> and ? for backward search: d?x<CR>
user avatar
  • 32.6k
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 ...
user avatar
  • 10.3k
21 votes

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

The other answers cover how to copy text from your buffer into the system clipboard. Another common operation is to copy text from another register to the clipboard. For example, if you've already ...
user avatar
  • 2,517
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 ...
user avatar
  • 16.5k
19 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 ...
user avatar
  • 1,240
19 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 ...
user avatar
18 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 ...
user avatar

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