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
3answers
94 views

Paste a block-copy into a single line

I need to restructure a markdown table, and for that, I wish there was a quick way to "join" lines from a multi-line cell. So with Vim, I would have to yank the block (Ctrl-v), and then ...
3
votes
2answers
511 views

The meaning of "= in Vim

I was solving a problem on Vimgolf (you can take a look at this) where I stumbled upon this solution. djgJ.V"=[<C-R><C-A>]<CR>pZZ Could you please walk me through the meaning of ...
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 ...
3
votes
2answers
131 views

Yank part of another line based on pattern

Im trying to yank part of another line: 1 foo=bar 2 3 (paste only foo here - without "going/moving" to 1) I understand that I can yank the whole line using :1y. A "pseudocode" for that would be :...
3
votes
3answers
93 views

Using :g to yank in quotes across multiple lines

I was reading through the vim wiki about the power of g https://vim.fandom.com/wiki/Power_of_g and would like to do something similar to :g/pattern/y A but a little bit different. I have an html file ...
3
votes
1answer
147 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 | ...
3
votes
1answer
243 views

Is possible in vim to delete a line after a word or character?

I have this file name ... line1 name ... line 2 name ... line 3 etc I want to delete lines after the "..." sequence ,and preserve the others: is possible? The result will be name ... name ... ...
3
votes
3answers
185 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 ...
3
votes
3answers
207 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
297 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 ...
3
votes
1answer
133 views

How to copy paste one value and overwrite another

A common function I do in textmate or any other editor is copy some text and then paste it over some other text, for example: https://gyazo.com/fcef05504e83b608b583af085f92ecd2. Currently to copy a ...
3
votes
1answer
95 views

Is it possible to place marks at the end of a line?

Typical mark placement using m places the mark at the cursor. When the cursor is on the last character of a line, this means that jumping to that mark for the purpose of copying text starts the ...
3
votes
1answer
129 views

Paste a block in “replace” mode

This is best explained with an example: Start by block selecting some text: Yank and paste it somewhere else: Note that the existing x characters were pushed over to the side, rather than being ...
3
votes
2answers
58 views

Why is this appearing to select wrong number of lines?

First, I typed 2V to select two lines, and y to yank them. Then I typed 3V, and instead of selecting 3 lines, Vim selects 6 lines. Next I typed 4V and Vim selected 8 lines. It seems that 3 or 4 in the ...
3
votes
1answer
158 views

Good method for saving and inserting commonly used snippets

I often need to insert the same text into a file. My approach has been to put the text into my vimrc as a variable: let map='<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">' And ...
3
votes
1answer
89 views

How do I copy the directory structure into the text of a file?

This might be more of a bash question than vim, but I thought I should start here. Frequently when editing code, it would be "nice" to copy and paste the directory structure into a text editor. For ...
3
votes
1answer
796 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 ...
3
votes
1answer
50 views

Append to current copy buffer

I am copying multiple lines from different parts. I can for example do 3yy to copy the 3 next lines. Then I would like to scroll a bit and add 5 more lines: 5yy and so on. At the end, I want to paste ...
3
votes
2answers
119 views

Is there a way to paste at multiple locations/lines in vim?

I use :copy a fair bit. So like range :12,15 copy 20 will paste a block of text from 12 to 15 lines at 20th line. But when I want to paste a line at multiple places it doesn't work. For example :24 ...
3
votes
3answers
1k views

How to copy lines with line numbers?

I would like to copy several lines with line numbers; the text from set number isn't copied. Is there any way to do this?
3
votes
1answer
301 views

Vim pasting yank register when opening a new file

For a few weeks, I have the strangest issue, on a single computer. On this computer, when I open a file with Vim, the yank register have a low chance of being pasted on the current position of the ...
3
votes
1answer
90 views

What is the rationale behind not using the numbered registers for small deletes/yanks?

This is related to this previous question: Numbered register doesn't record most deleted text within a line? I want to know the rationale for this. I was writing an email and deleted a note in ...
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) { ...
3
votes
1answer
84 views

Keeping lines identical

I realize that this is probably too much to ask, but: sometimes one wants certain lines in a document to remain identical; might there be a way to link two lines such that changes to one are ...
3
votes
1answer
316 views

Paste mode sometimes inserting “<Paste>”

Sometimes when I paste (via cmd+v) some text into neovim, it inserts <Paste> at the bottom, i.e: This was pasted and I got some bonus letters <Paste> I can't figure where this text comes ...
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 ...
3
votes
0answers
40 views

How to exit insert mode if pressing escape merely types “^[”?

I have neovim 0.4.2 running in a session of kiTTY 0.17.4 on OSX. I have pasted a long url while in insert mode. After doing this, every time I type BKSPC vim adds ^? to my document. Every time I type ...
3
votes
0answers
103 views

Cursor position after pasting

I believe the default behaviour in vi(m) for pasting (p) or (P) was to leave the cursor at the current position as before pasting, and in order to paste a register and have the cursor be at the end of ...
3
votes
0answers
122 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 ...
2
votes
3answers
4k views

How to delete searched line and next

I have a file containing special comments in the following forms: // SPECIAL // Some stuff // Some other stuff // Last line of other stuff So I need to be able to delete the line containing SPECIAL ...
2
votes
3answers
280 views

Is there a quicker way to replace the content in parentheses with the content yanked?

If I want to replace something inside a group of parentheses (like say a function call) with something I've yanked I currently do: vi(p this obviously isn't an excessive use of the keyboard, however I'...
2
votes
2answers
747 views

Copy entire line and paste it after another line

Let's say I'm at line 20 and I want to copy (and paste below line 20) just the line 50. I can do that with :50,50y , then paste with p in normal mode. I found this here. I want to know if there are ...
2
votes
1answer
122 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 ...
2
votes
4answers
116 views

Clipboard is reset after first paste in Visual Mode

I am on Neovim. This is really annoying and weird. When I make a selection in Visual Mode and copy, then select a text and then paste, this paste only works once. For the next time, I again have to ...
2
votes
3answers
141 views

Delete specific character on previous line

I deleted lines in a file with :g/^\s*key3/d and now have a file like this: entry{entryname1, key1 = {text}, key2 = {text}, } entry{entryname2, anotherkey = {text}, yetanotherkey = ...
2
votes
4answers
1k views

How can I overwrite a whole file with the content of another?

I have two tabs open, file1.txt and file2.txt, each with different content. How can I copy the whole content of file1.txt and overwrite file2.txt with it, resulting in both files having the same ...
2
votes
2answers
606 views

Yank current file path and line number into system clipboard

I'm trying to save the current relative path of my file and line number into my clipboard. I would like to have application/models/my_model.rb:34 But I don't understand how expand works. They have ...
2
votes
1answer
60 views

Date change question: Find and replace with wildcards?

I have a file with a bunch of dates of the form a/b/c, where a,b, and c are numbers of varying character length. However, I'd like to change every instance to read c/a/b. I'm wondering if there is a ...
2
votes
3answers
598 views

Deleting without copying to clipboard in Windows?

Here is a typical workflow I would like to follow: copy some data from Excel spreadsheet into the clipboard in vim , delete the data in the file using ggdG then paste the data into the file from the ...
2
votes
2answers
2k views

Paste clipboard shortcut in vimrc

I know that I can paste the clipboard in by by typing ctrl-shift-v. The problem is that this is a very counterintuitive shortcut. It requires me to move my hand in a very uncomfortable way. I would ...
2
votes
2answers
94 views

How can I conveniently yank then change small text?

This is more of a specific deeper dive into vanilla Vim then the question Can I make Vim also save “small deletions” into register "1?. A common text editing situation I run into is to yank a text ...
2
votes
1answer
173 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, ...
2
votes
2answers
70 views

Search and copy the text between two markers in gvim

I want to copy strings that spans across multiple lines between two markers in a large file. In the below example file, start marker is <ROW> and end marker is </ROW>. <ROW> &...
2
votes
1answer
279 views

copy line XX and paste it below my cursor (avy / ace jump style)

I am wondering what the way of copying a line and pasting it below my cursor in vi/vim might be? Current workflow (copy line 21 and paste it below cursor): 21ggyy''p Is there something shorter like: ...
2
votes
1answer
359 views

How to select the content within brackets including brackets and without including brackets?

I have some code structure e.g { { // Some content goes here } [ // Some content goes here ] } I want to select the content inside { } in some case and also content inside with ...
2
votes
2answers
580 views

Text after cut not going to register 1

As I know, when we cut text using d or c, this text will go to register 1, and shift all registers from 2 -> 9. I have tested and I see two things: My text, after cutting, is not going to register 1....
2
votes
1answer
172 views

Extra character after pasting yank text into command line

I have a line of vimscript in my buffer like: call MyFooFunction(1,2) and I'm trying to execute it quickly. So, I yank it (yy), invoke the command line (:), and paste it in with <C-r>" But, ...
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 ...
2
votes
2answers
129 views

How to activate bracketed paste mode in GNOME Terminal for Vim inside tmux

Edit this issue happens inside a tmux session. The original value of $TERM before starting vim is: echo $TERM screen The issue appears for example when pasting this kind of indented code: def ...
2
votes
1answer
141 views

Yank then Paste without moving cursor

I want to be able to: :42y then something like: :13p having it to paste the yanked line in a new line after 13, without taking my cursor away. So far, all solutions I have found involves going to ...