Questions tagged [cut-copy-paste]

Questions about cutting, copying, and pasting text. In Vim, "cut" is also called "delete", "copy" is also called "yank", and "paste" is also called "put".

Filter by
Sorted by
Tagged with
319
votes
11answers
283k views

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

Is there a way to copy a block of text to the system clipboard, so I can paste it in another program?
97
votes
15answers
66k views

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

In vim, I often need to delete, or yank/put large blocks of text. I can count the lines of text and enter something like 50dd to delete 50 lines. But that's a bit of a pain. How can I delete this ...
58
votes
4answers
59k views

How can I easily move a line?

What is the command (or shortcut) to move a line up or down in vim? My current workflow is to yank (copy) the line and than delete that line and than to put (paste) that line.
55
votes
3answers
25k views

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

I know many ways to copy things: yiw = yank in current word yaw = yank all word (includes a trailing space) yy = yank the current line 3yy = yank three lines starting at the current one yap = yank ...
41
votes
5answers
9k views

How to yank a line with a certain line number?

Say that I am on line 20 and I would like to yank line 4, how can I do that? And similarly, how can I yank a line relative to my cursor position, say the one 3 lines up?
30
votes
5answers
2k views

Performing certain operations without clearing register

Frequently, in configuration files I might copy and paste a block of lines, then I want to make small changes to that block. After pasting, I use x to delete characters that I want to remove, then ...
29
votes
4answers
1k views

Is there a text object for the entire buffer?

I often find myself typing commands like gg"+yG or ggdG and would like a more efficient way to do this without having to move the cursor twice. Is there any command that I can use e.g. y[movement] to ...
28
votes
2answers
2k views

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

Is there a specific historical reason for this? Background — (you can skip this part if you already understand the question.) As intermediate/advanced vi users will know, y is the "yank" command—it ...
26
votes
4answers
1k views

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

When I have to replace a word with another word I yank before, I usually use a workflow which seems unnatural to me: Let's say I have this text: foo bar buzz And I want to yank foo and replace bar ...
25
votes
7answers
4k views

Faster way to move a block of text

Here's how I usually copy a block of text or code: Select the block with Visual mode (V) and delete it with d; or if it's just a single line, just use dd. Go to where I want the text to be, I am too ...
21
votes
2answers
1k views

How does one append to the clipboard register in vim?

I already know that you can copy something to the a register using: (plus a yank, delete, etc. command) "a I also understand that you can append to the a register using: "A In addition I ...
18
votes
1answer
2k views

How can I map d[count]d?

N.B. This is not a duplicate of How does the "d3fg" command work? Please read it before voting to close! I've come to a bit of an impasse in my quest to get small deletions work like big ...
17
votes
4answers
1k views

How to replace inner text with yanked text

An editing pattern I frequently run into is the following: I want to yank a piece of text inside quotes or brackets, and replace that piece of text inside another pair of quotes/brackets. For example,...
17
votes
4answers
6k views

Delete from cursor till nth occurence of character x

I know that I can delete from the cursor till and including the first occurence of a character x with d/x<CR> or with v/x<CR>d if I want to see the selection first and then delete. How can ...
15
votes
3answers
8k views

How do I copy a file in netrw?

The current working directory is ./A/B/. An empty document is opened when I type vim, and the netrw is opened with command :e. The window is split by vs., and I can navigate to the upper level ...
15
votes
1answer
2k views

Does “dap” delete everything?

I'm familiar with the "dd" and "d{motion}" commands, but can't find "dap" in vim's help.txt. What does "dap" do in normal mode and why? (Alternatively, how can I find out this sort of thing for myself?...
13
votes
3answers
1k views

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

I usually need to move/copy code snippets between my source files. After I paste a block of text, I usually need to apply some operation to that block such as reindenting them with =. Is there a way ...
13
votes
4answers
2k views

Yanking and pasting while incrementing

I am editing a .sql file in Vim: INSERT INTO apps_forms (app_id, form_id) VALUES (1, 1), What I'm looking to do is yank the (1, 1), line and paste it 137 times; however, I want the second number in ...
12
votes
2answers
1k views

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

I know that I can delete from the cursor till and including the first occurence of a character x with dfx. This only works on one line. How can I delete from the current cursor position till the first ...
12
votes
1answer
797 views

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

Suppose I have the following four lines: line1 line2 line3 line4 Now if I go to line1 and do a yy which copies the line and then go to start of line3 and do a paste using 'p', I would get ... line3 ...
12
votes
3answers
4k views

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

While using WSL/Bash for Windows I want to be able to use y yy 3y and p the same way they always work in vim, but connecting to the system clipboard shared by all apps, not to vim's internal clipboard....
11
votes
3answers
660 views

How to insert repetitive text with minor difference in vim?

I want to insert text like this: similar text wordA similar text ... similar text wordB similar text ... similar text wordC similar text ... I know I can paste the text many times then use the ...
10
votes
6answers
5k views

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

Given a series of lines that look similar to this: 2001 "Some Kind of Title," Author's Name, Publication Name, 1 Mar. 2002 "Some Kind of Title," Author's Name, Publication Name, 12 Oct. 2003 "Some ...
10
votes
3answers
1k views

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

I use the registers a lot for copy/pasting, but I always forgot in which register my content is. Is there a way to display the registers before pasting? Ideally it would leave the register on screen ...
10
votes
6answers
3k views

Deleting In Vim and Then Pasting Without new Line

Many times in vim I would like to delete a line completely, so I use dd. However, I then need to paste that line into some other position within a line, but this inserts a newline before pasting, ...
10
votes
2answers
542 views

How to paste visual block starting with another line

It took me very long time to realize that putting (pasting) something with p or P which visual-block selects with ctrl+v and yanked (copied) with y, preserves the manner before, so that, when the ...
10
votes
3answers
281 views

How can text be moved from one register to an arbitrary number of registers?

Is there a way to 'pipe' text from a register to an another register or set of registers? For example, move "q to registers "1 through "5. I often wish to create slightly different versions of the ...
10
votes
5answers
9k views

How to copy across terminals?

I'm using Linux system. Two vims are opened in two terminals. Now I'd like to copy text from A to B. One way to do so is to select text in A, use mouse to copy, then switch to B, in the insert mode, ...
10
votes
1answer
306 views

What is the origin of the term “yank”?

I'm interested in learning how the term yank got its name. I'm also interested in why Vi/Vim "yank" differs from Emacs "yank". See also: same question on Unix & Linux; dual question about Emacs
10
votes
2answers
354 views

Most efficient way to replace the entire buffer?

Currently, I have two similar methods to replace the entire buffer with some other text (say in clipboard). Method #1: delete all lines: :%d. paste text: "+P ( or similar: :put+). Method #2: ...
9
votes
4answers
465 views

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

Assume I have the text Fnord yanked before and that my cursor resides on the B of the line: M:mock(Baz) How can I change the text inside () with the previously yanked text? Currently, I often make ...
9
votes
1answer
870 views

Paste visual block selection on its own lines

I'm not really sure how to describe what I'd like to do. Basically I'd like to use visual block mode to select a region of text and then paste it "as a collection of lines" rather than as a rectangle. ...
9
votes
1answer
109 views

Overwrite current line with register?

I often want to copy a line and replace another line with the pasted copy. Is there a better way than Y on source line, go to the line that has to be replaced and Pjdd?
8
votes
3answers
1k views

How to simply remove braces

One of my friend told me that I can use the trick below to remove a pair of curly brackets. Put the cursor inside the curly bracket pair you want to remove. y i { to yank the text in braces , then v ...
8
votes
2answers
475 views

How to move a paragraph and paste it without an initial newline first

If I have a pair of quotes on a line by themselves: '' ...and a short paragraph of text, say three lines of text: some text that I'd like to move Now if I want to move the text into the quotes, I ...
8
votes
2answers
788 views

How do I paste the same line of code X times but change one word in the line each time?

I'm writing HTML lists, and I want to be able to automagically paste 10 list items where the item text is the only thing that changes. I could accomplish this using PHP and then just copying the ...
8
votes
3answers
688 views

Paste link to image in clipboard when editing Markdown

I have an image on the clipboard and I want to paste it into my document as the text [](img/image1.png). Instead of first copying it to that directory, I want to do it with a single p key press in ...
8
votes
1answer
799 views

Avoid extra spaces while pasting block with different line lengths

I have the text var1=a var2=aaa var3=aaaaaa some text... "" ... some text... "" ... some text... "" ... I want to paste the a-part of the top 3 lines into the quotes in the last 3 line. The result ...
7
votes
4answers
1k views

Replace . with -> in specific places

Sometimes I need to replace . with -> when fixing code. Usually search and replace cannot be used because there will be many (hundreds of) dots (.) and only a few ones of them must be changed. ...
7
votes
2answers
1k views

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

I want to copy different strings from different lines of the file and then paste them together at once. In other words, I want to collect different words in a basket and then paste them at once. How ...
7
votes
2answers
504 views

Difference between “* and ”+ registers in +clipboard VIM?

"*p and "+p seem to behave the same. I tried :help "*, but it's talking about mouse selection, and :help "+ tells me There are three documented X selections: PRIMARY (which is expected to ...
6
votes
5answers
8k views

how to delete all white spaces until first character?

Is there a simple way to delete all white spaces on a line until the first character on that line is met? An example: #a list of comments # item 1 # item 2 ...
6
votes
5answers
382 views

Easiest way to cut line content and past it inside { }

I have this subject { } it 'delete user' do expect(BlaBla).to eq '' MyModel.my_method end And I want this subject { MyModel.my_method } it 'delete user' do expect(BlaBla).to eq '' end 1. ...
6
votes
5answers
625 views

truncate sentence: delete up to, but not including period

How can I set up a keybinding to delete up to the end of a sentence that ends with a period, but keep the period? The commands df., d), and D all truncate the sentence but don't keep the period. ...
6
votes
1answer
678 views

Delete to EOL without entering insert mode

I have a file that looks like this: Bunch of text trailing... Bunch of text trailing... Bunch of text trailing... Bunch of text trailing... Bunch of text trailing... I can ...
6
votes
4answers
2k views

How to copy text with syntax highlighting?

Want a simple way, like notepad++ plugin: NppExport - Export to RTF, to copy selected text with syntax highlighting. Notepad++, NppExport, Export to RTF example: Select text Copy RTF Paste ...
6
votes
1answer
719 views

Repeat last yank

I'm appending text to "a" register with:"AyW. If I wanted to repeat last change I would use:. But in this case I would like to repeat the last yank command. Is there a command to repeat the last yank (...
6
votes
2answers
588 views

How to paste a line in a vertical selection block?

Consider the following text: long foobar=(test); int barbar=(something); char foofoo=(); Suppose I have yanked some chunk of code which I want to place before each opening parenthesis, e.g. ...
6
votes
2answers
1k views

Insert a text selected via visual block

I'm facing a behavior that I find unatural when trying to paste a block of text selected with visual block mode (<C-v>): I can't insert it between two lines without messing with the already ...
6
votes
1answer
2k views

Copy a word and paste the same word at multiple places in vim

If I try to copy a word via this yw – yank the current word and paste it to somewhere, it works but If I try to paste it somewhere else one more time old world gets lost with previous replaced word. ...

1 2 3 4 5 6