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
1
vote
1answer
43 views

Indenting now add suspicious chars to my files when pasting

Following answer I got there to allow >> to indent, I edited my .vimrc to this: :set shiftwidth=2 :set autoindent :set smartindent But now when I copy/paste (via putty), it indents incrementally, by ...
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.
8
votes
2answers
840 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 ...
0
votes
1answer
84 views

accidental turn of mouse wheel when pasting text

A problem that bothers much my editing work with vim happens when pasting text and the mouse wheel rotates slightly by accident with the result that text is inserted elsewhere in the file under ...
1
vote
0answers
431 views

linux: yank to clipboard, cut to primary

I'm using neovim. I want to map the 0 register to the system clipboard and the unnamed register to the system primary (mouse middle click). Is it possible? I can map the unnamed register to primary ...
1
vote
3answers
865 views

Copying and pasting while inserting

When I am inserting a big block of code or text, often I will want to copy and paste text from elsewhere into that block. Is the only way to do this to leave insert mode, go get the text and paste, ...
2
votes
1answer
52 views

What captures the <Shift>+<Ins> key combination?

When I press SHIFT+Ins in vim to paste text, who captures this key combination? Is it the terminal or Vim? How about in gVim?
0
votes
1answer
243 views

Issue with paste command remap in vim

I want to auto indent code on pasting and found this: :nnoremap p p=`] --(not working) but it was not working for me as the code still came out unindented. So I used: :nnoremap &...
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 ...
2
votes
1answer
287 views

Why does pasting screw up my text file and shell script?

I'm using Vim on Ubuntu 14.04 LTS. I've been confused by these two situations and I think they might have common cause: When I open a text file in vim and paste some content that I copied from web ...
1
vote
1answer
148 views

Can I yank from the current position of the cursor to the end of the line without the newline?

I've got a list of files that I want to copy from one place to another, I need to change the name slightly and I'd rather copy the file names instead of typing them over and over again. If I do YP I ...
0
votes
1answer
48 views

Save view after execute command?

I'm mostly developing with python. I'm using pdbpp as python debugger so I'm contantly adding import pdb;pdb.set_trace() or import pdb pdb.set_trace() So I wrote couple of functions. function! ...
3
votes
1answer
156 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 ...
1
vote
2answers
708 views

How can I use tmux for copying if I can't access the system clipboard?

I'm testing out using vim with tmux. One thing that I could do with vim with a split window is yank text from one buffer and paste it into the other. This no longer works when I have vim buffers in ...
4
votes
1answer
86 views

Deleting to the begin of the line with d _

In Vim, v_ selects text from the current position to the actual begin of the line. Example: Test test Test te|st Now pressing v_ we get the selection: Test test [Test te]st From this I would ...
1
vote
2answers
170 views

How can I delete a quotation mark and comma at the end of every line?

Suppose I have the following text, how can I delete single quotation marks and comma in each line end? I know I can use x command and delete ' and , line by line. But are there any more clever way to ...
1
vote
0answers
28 views

How to get vim to use the same register as X? [duplicate]

I would like to be able to yank and paste text from and to X clipboard (webbrowser, email client etc), is there an easy way to fuse the registers to have a single clipboard ?
1
vote
0answers
645 views

How can I reliably copy and paste between vim and other programs? [duplicate]

I have a hard time just copying and pasting between vim and other programs (firefox, chrome, gnumeric) as well as other instances of vim. Normally I try to copy/yank with "+y and paste with "+p. ...
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 ...
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 ...
2
votes
2answers
588 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
1k views

How to copy multiple lines and paste at the end of a file

Suppose I have a file: class X(arg): \t#blabbla \tdef fun1(arg): \t\tsome code \n \tdef fun2(arg): \t\tsome code \n class A(arg): \t#blabbla \tdef fun0(arg): \t\tsome code \n \tdef fun3(arg): \t\...
5
votes
1answer
101 views

yank and append line relative to the current one

I've enabled the relativenumbers in Vim. I would like to automate the following operation. ma(number)(j|k)yy`a(p|P) that is to say: mark the curr position in 'a' move up or down by 'number' lines ...
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. ...
8
votes
1answer
846 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 ...
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 ...
17
votes
4answers
9k 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 ...
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 ...
4
votes
1answer
821 views

How can I replace a word with a yanked word in Vi?

Lately I've found myself working more and more with remote servers over SSH. Most of those severs don't have Vim, but just Vi. Using it hasn't been too rough with just a few problems. One is this: ...
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 ...
29
votes
2answers
3k 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 ...
64
votes
4answers
28k 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 ...
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 ...
1
vote
1answer
85 views

Yank with Separate Line Pasting

Given a b c d e I want to 5yy and then separately paste 5 lines in arbitrary locations in order of a b c d e instead of a separate yy p for each line. Are there any plugins or Vim script that would ...
2
votes
1answer
168 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, ...
4
votes
3answers
1k views

Effects of set paste

This wikia page explains how to paste text from a different application into vim when in insert mode. Simply apply the command set paste and things will work as expected. After you are done, just ...
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 ...
4
votes
1answer
160 views

Yanking lines from a multiple selection

I’m using the multiselect plugin. I have selected multiple contiguous blocks of code and want to yank all of them into one register. For example, from -- selected A -- —— unselected —— -- selected B -...
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 ...
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 ...
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 ...
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 ...
0
votes
1answer
491 views

vi or vim: Mac/Iterm 2 highlight-paste [closed]

When editing with Vim on Macbook Pro with Iterm2 interface I can copy text by highlighting text with left-button double click on mouse, paste text by pressing center wheel on mouse. Instead of (2) I ...
4
votes
3answers
1k views

Duplicate block of code

I'm using vim a lot and I'm trying to optimize few movements I do with too much key pressed. For exemple I have this : module SanitizeIdsParams def self.my_method ids ...code end end And I ...
6
votes
0answers
80 views

Prevent gvim from clearing the clipboard on exit [duplicate]

If I copy text into the xterm clipboard ("+y) from gvim, it is cleared when I exit gvim. How do I prevent this? I've found the solution for vim, but it doesn't work for Gvim: autocmd VimLeave * ...
10
votes
1answer
331 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
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 ...
6
votes
2answers
717 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. ...
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, ...