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
356
votes
12answers
347k 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?
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 ...
14
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 ...
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 ...
5
votes
1answer
863 views

Can Vim add to the X11 clipboard or primary buffers without an external utility?

We can copy to both the + and * registers, but this doesn't actually copy the content to X's memory (apparently). If you copy something from Vim using the * or + registers and quit Vim, poof! There's ...
98
votes
15answers
75k 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 ...
42
votes
5answers
10k 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?
5
votes
3answers
335 views

Way to get content of Visual Selection?

Now if I select something in visual mode, is there some way to get the selected area without having to yank it to some register? I looked through :h functions but didn't find anything.
32
votes
5answers
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 ...
26
votes
7answers
5k 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 ...
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 ...
6
votes
2answers
6k views

How to select and copy lines to clipboard which are selected by mouse without linenumbers and gutter?

In my default Vim settings I've enabled a gutter and line numbers. Sometimes I copy some lines to clipboard in order to paste somewhere else. Currently I need to disable line numbers and the gutter. ...
9
votes
4answers
486 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 ...
5
votes
2answers
447 views

Why can't I paste commands into vi?

I've been using vi for 40 years. A week ago I upgraded; Disaster struck! The upgrade was to VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 4 2018 23:38:28) I run this on xterm under Cygwin (...
4
votes
2answers
5k views

Copy and pasting blocks of text anywhere

I have two blocks of text and I want to merge them. However, the problem is that the blocks are not synchronous and I want to place one in front of the other completely. For example, suppose we have ...
3
votes
3answers
206 views

How can I use the `global` command to prepend 'document headers' to 'document lines'?

I am trying to change a text file with data in 'document' form into unnormalized csv. The data are a list of hymn authors ('document header') and for each author a list of one or more hymns they have ...
3
votes
1answer
141 views

How to paste the clipboard selection when it was populated with a yank in Vim started from the st terminal?

If I yank some text in the clipboard selection from Vim (e.g. "+yiw), then quit Vim, I can't paste it in st. Here's a MWE: $ git clone https://git.suckless.org/st $ cd st $ make $ ./st $ echo foo | ...
2
votes
1answer
121 views

How can I copy the displayed text, instead of the actual text?

Vim can often show you text differing from the actual input, such as with non-printing characters, concealed text, etc. There are plugins which prettify text (for example, using a proper lambda ...
14
votes
4answers
3k 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 ...
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 ...
21
votes
4answers
7k 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 ...
9
votes
3answers
975 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 ...
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 ...
5
votes
1answer
609 views

Vim, tmux, and xterm-bracketed-paste

From Terminal.app on my Mac, I SSH in to a box where I run Vim 8.0.1601. Left at that, everything works fine. But if I launch Vim from within a tmux window, go to insert mode, and then attempt to ...
13
votes
1answer
1k 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
1answer
984 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. ...
4
votes
2answers
480 views

Copy text based on delimiting strings

I see how to copy text in vim using visual mode, arrow keys, y to yank, and p to paste. I also see how to find a given starting string using back slash. However, I'd appreciate knowing how to copy ...
3
votes
2answers
357 views

How to copy from current line to the `n`-th line?

Suppose I am on line 10, and I want to yank to line 20. Usually I will do 10y. Sometimes I do the subtraction wrong, and copy the wrong number of lines. Is there a way to copy directly from current ...
3
votes
0answers
121 views

how to delete a paragraph respecting the folds?

I have a file (filetype=javascript), this is how it looks without folds: and with folds: I can move with the { and } motions skipping the empty lines inside the folds (thanks to these question and ...
6
votes
5answers
393 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. ...
5
votes
1answer
483 views

How does the “d3fg” command work?

I would like to know how a "d3fg" command works in vi. I have done some research on Google and found that d is delete and fg means foreground. Suppose, if we want to stop the session of vi and resume ...
5
votes
1answer
6k views

How can I copy over an ssh session without +clipboard?

On my local computer, I have the following in ~/.vimrc, which allows me use to the mouse (e.g. to select text) and to copy to the system clipboard with Ctrl+c. set mouse=a vnoremap <C-C> "+y ...
5
votes
2answers
863 views

Keep cursor from moving when yanking upwards

I frequently find myself wanting to make a copy of, eg, a function that I just wrote and modify it slightly. In such a situation, I'll generally use something like y5k to copy what I just wrote. I ...
4
votes
1answer
95 views

Set paste mode when at beginning of line but auto-indent mode when anywhere else on the line?

As per other questions, most of us know that if we want to enter paste mode we can toggle :set paste and :set nopaste. And for auto-indenting we can :set autoindent. However, I was thinking today, I ...
4
votes
2answers
124 views

Can I paste a yanked line even if I delete a line? [duplicate]

When I yank a line with y and paste it with p, it's okay. But when I need to delete a line with dd before pasting my yank buffer changes. Can I still paste my yanked line? Is there a way to do that? ...
4
votes
1answer
127 views

Cut line, trim it and then paste it on another line

I sometimes have to cut a line (d) and paste in in the middle of another line. I'd like to remove the whitespaces that vim has copied (i.e. trim/strip the content). How can I do that in vim? A common ...
3
votes
1answer
1k views

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

To move cursor on the 4th line,toggle into normal mode,input 8yy. To move cursor to 15th line,and toggle into normal mode,press p . Now the lines from 4th till 11th was pasted from 15th till 22th ...
2
votes
1answer
827 views

How to disable bad indentation when pasting text?

I am using vim and simply want to disable auto indent when I paste text into my terminal vim session. I have tried numerous solutions including various incantations of below to ~/.vimrc: set nopaste ...
1
vote
1answer
581 views

Yank/select until delimiter in different lines

From the following text: variable1 = 'example' foo = 'foo' barett = 'ver' I would like to yank (or visually select, if possible) the content of each line until the = sign: variable1 foo barett ...
1
vote
0answers
29 views

Is there a way to reselect the last pasted text, rather than the last actual selection, starting at the current cursor position? [duplicate]

I know that gv reselects the last visual selection. This is great and I use it frequently. But sometimes I want to select the block of text that I just pasted. This is useful e.g. for sending example ...
0
votes
2answers
184 views

Strangely slow key bindings

I defined these maps, to yank into system clipboard. noremap <leader>y "*y noremap <leader>Y "*Y noremap <leader>yy "*yy But when I use the first one (<leader>y), I find it ...