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
3
votes
1answer
196 views

Use motion when putting

A very common use case I'm having is to copy something (let's say a word) and I want to paste it in another context (let's say a word with quotes). The way I do it is: const char *foobar(void) { ...
11
votes
5answers
12k 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, ...
3
votes
2answers
2k views

Paste buffer/clipboard into brand new file?

I am breaking apart some files, and I'd like to paste what I cut into a brand new file, which I specify the name of. Something like: :c file-that-doesnt-exist.txt Where c is a key command. Edit I'...
6
votes
1answer
2k views

What's the difference between the “clipboard” and “xterm_clipboard” features?

What is the difference between the clipboard and xterm_clipboard features? When do I need to enable one or the other at compilation time? As an aside, how do these features relate to the mouse ...
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
4k views

Can't yank into * or + registers [duplicate]

I'm trying to yank to the system clipboard on Ubuntu 14.04. I can't yank into the + or * registers, though. Every time I visually select my text and type "*y or "+y the indicator on the bottom right ...
11
votes
6answers
4k 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, ...
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 ...
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 ...
5
votes
1answer
864 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 ...
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 ...
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 ...
3
votes
3answers
183 views

yanking a certain amount of bytes

I'm working on large files for wikisource, along with another guy. I generate a big text file (a few Mb) witch I format a bit using scripts, then I upload the text to a temporary page, where the other ...
5
votes
1answer
79 views

Auto-indenting copied text

I would like to auto-indent text blocks that I have just put. At a minimum, I would like to retab the new block of text, since otherwise I sometimes end up with tabs in files that shouldn't have tabs ...
2
votes
1answer
169 views

Append to register inside a global command

I have a file whose content could be like the following: foo1 bar1 foo2 bar2 bar3 I want to delete from the file all the lines matching the pattern ^foo and put them altogether somewhere else, ...
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 ...
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 ...
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?
3
votes
1answer
293 views

“x” overwrites clipboard, I am not able to finish the copy-pase action [duplicate]

I decided that I have to get rid of a couple of annoying things which decrease my productivity in Vim. I know they must have a simple solution. So, my first question: If I copy a word in clipboard ...
2
votes
1answer
116 views

How do you get which “side” of the visual mode selection the cursor is on in vimscript?

I'm writing some vimscript and would like to preserve the cursor position after a yank occurs in visual mode. Ths issue is that I can't find any way to get the cursor position while in visual mode. ...
3
votes
1answer
788 views

How do I copy the error message I get from YCM

Is there a way to copy the error message that YCM shows at the bottom of vim? For example in the above image, it says: unused parameter 'sortFunction' I had an idea of using "howdoi [paste]" in ...
71
votes
5answers
72k 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.
2
votes
1answer
99 views

How to copy the current line(s) out to a new file?

I'm reading through a very large web service log, and I want to pull a single line out from the file, and write it to a new file. The log lines consist of web service request XML, so they are long ...
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 ...
5
votes
2answers
864 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 ...
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 ...
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 ...
4
votes
3answers
2k views

How do I switch around 2 pieces of text?

I have 2 pieces of text, what is a proper way to switch those pieces of text. around e.g. I have this: This is one piece of text. Here is another sentence. And I want to switch around the 3 first ...
6
votes
4answers
17k views

How do I copy and paste between two vim instances - shared clipboard?

I use gnu screen and I run vim file1.txt and vim file2.txt in two windows. How can I copy part of the text from file1.txt and paste it to file2.txt without using temporary files or opening two files ...
4
votes
2answers
2k views

How can I get vim to not auto-wrap pasted text? [duplicate]

I am pasting several lines of text into vim at once (from another application, so I am using the OS's copy and paste and insert mode in vim). The longest of these lines is below: " :PluginClean -...
10
votes
2answers
391 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: ...
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 ...
1
vote
0answers
18 views

do a command without altering the register [duplicate]

Sometimes I delete a line and when I want to yank it somewhere else I found out that I need to delete another line. How can I delete the new line without overriding the the content of the line that I ...
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. ...
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? ...
5
votes
2answers
3k views

How does one perform a multi-line copy and paste between two sessions in Vim?

I am familiar with the y, p method of copying and pasting a line within Vim; however, I have been unsuccessful in finding a straight forward method for copying multiple lines which have been yanked in ...
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 ...
4
votes
2answers
134 views

How to paste and remove current line

For example if I copy several lines of text and open a brand new file. If I paste with p, then I get an empty line above the pasted text, and if I paste with P, I get an empty line below the pasted ...
6
votes
2answers
200 views

Working with English sentences

When I'm editing English text, I need to work with full sentences instead of lines of text in the file. Using the default Vim commands for this kind of text manipulation is very awkward, because I may ...
10
votes
3answers
339 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 ...
1
vote
1answer
225 views

What can happen if I accidentally paste into command mode? What should I do if I do this? [duplicate]

If I have vim in a windowed terminal, sometimes I paste (using the terminal's paste functionality, e.g. middle click) from another window that isn't vim. Most of the time, when I do this, I wanted to ...
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 ...
10
votes
1answer
139 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?
358
votes
12answers
348k 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?
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 ...

1 2 3 4 5
6