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
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
2answers
7k 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. ...
6
votes
1answer
7k 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 ...
6
votes
2answers
230 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 ...
6
votes
1answer
3k 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. ...
6
votes
2answers
716 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 (...
6
votes
0answers
87 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 * ...
5
votes
1answer
488 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
3answers
364 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.
5
votes
1answer
895 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 ...
5
votes
1answer
436 views

What is the use case for the weird paste behavior?

Today, I wanted to import a public GPG key. To do so, I have navigated to page, copied the key, opened up vim, entered insert mode by pressing i and pasted the text. Every line has been pasted fine ...
5
votes
2answers
922 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 ...
5
votes
2answers
849 views

delete words backwards

I use Vim 7.4.576 on debian8. I don't grasp the concept of deleting words backwards. Here is some text. Cursor position is on "that" (the pipe symbol) this is a new text on th|at line. How can I ...
5
votes
2answers
4k 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 ...
5
votes
1answer
116 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 ...
5
votes
2answers
116 views

WORD movement across lines

Consider the following text snippet: value1, value2 Now, if the cursor is at (1,1) (the 'v' of value1), W takes me to (2,5) (the 'v' of value2) which is as expected. But if I do dW at the same ...
5
votes
1answer
647 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 ...
5
votes
3answers
354 views

Prevent the cursor from moving to the start of the yanked text?

Vim help's change.txt states that Note that after a characterwise yank command, Vim leaves the cursor on the first yanked character that is closest to the start of the buffer. This means that "...
5
votes
1answer
82 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 ...
4
votes
4answers
669 views

vim delete parenthesis

I have cursor at first t and I want to delete all this code from t to };\n without counting lines. How can I achieve it? Is there more cleaner way than d/};$/e? tabControl.PropertyChanged += (s, e) =&...
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 ...
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 -...
4
votes
2answers
126 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
2answers
143 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 ...
4
votes
4answers
575 views

How to apply a register to a command?

I have the given file 4 apples 2 bananas 6 peaches 3 grapes 1 pineapple 5 pears 3 tomatoes What I want to do is to recieve the following result instead: apple apple apple apple banana banana peach ...
4
votes
3answers
2k views

Paste with space inserted before text

Is there a command to paste (p) text with space inserted before that text like in join? I don't want to achieve that by mapping. Normally p pastes text right in the cursor's position in Normal Mode. ...
4
votes
2answers
6k 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 ...
4
votes
1answer
226 views

How does vim know if register contents were from a linewise selection when pasting?

I haven't been able to find documentation on how vim knows if register contents came from a linewise-selection vs characterwise or blockwise selection. For example, given the text below: Hello there ...
4
votes
1answer
940 views

Get 2 lines yanked or 1 line yanked confirmation

This is a small thing, but it still annoys me. When I select at least 3 lines with Visual line mode, and then yank them, I get a confirmation: n lines yanked appears at the bottom of my screen. ...
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 ...
4
votes
2answers
301 views

Paste word on new line with indentation from current line

Using ]p in normal mode, I can paste a yanked line of text on a new line below the cursor with indentation equal to the current line. Using the :put command, I can paste a yanked word as if it were a ...
4
votes
2answers
2k views

Pasting from cliboard in osx returns ^M instead of newline

I'm having a problem with pasting on MacOS Sierra. When I copy text with newlines, I can paste it in a terminal without issue. e.g.: Text to be copied: echo 'Foo' echo 'Bar' result from terminal (...
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 ...
4
votes
1answer
212 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 ...
4
votes
2answers
557 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 ...
4
votes
1answer
26 views

Cursor Movement in y8k vs y8j [duplicate]

Why does y8j not move the cursor but y8k does move it up? What .vimrc entry would prevent yanking upwards moving the cursor?
4
votes
1answer
244 views

Vi: * and + registers do not exist

I'm unable to use the system clipboard in Vim. I'm using ssh to connect to an EC2 instance running Ubuntu 18.04. I'm fairly sure that this has to do with neither the * or the + register showing up in ...
4
votes
1answer
152 views

Why does VIM not copy the entire text inside the backticks in `\\sfdas\lsdfjla\` if I use `yi``

If I have a line say `\\sfdas\lsdfjla\` and I try to select the text inside the backtics using yi`, I expect that the entire text inside the backtics should be selected. However, it seems that in ...
4
votes
1answer
169 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 -...
4
votes
1answer
130 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 ...
4
votes
5answers
183 views

Can I define something in .vimrc to speed up pasting of large amounts of data?

Occasionally, I paste large amounts of data into vim, using Ctrl+v in my terminal emulator (in Linux). This takes several seconds before vim is responsive again. I have tried two other methods, which ...
4
votes
1answer
753 views

trailing spaces when copying text from vim session in one server to vim session in another server

I have two windows open in tmux(version 2.3). In first tmux window I have a SSH session to server1 and in second tmux window I have a SSH session to server2. In server1 I opened a shell script with ...
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 ...
4
votes
1answer
1k 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: ...
4
votes
1answer
97 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
1answer
151 views

Why copying from named register cannot be repeated using dot operator?

I am copying a word with: viwy (visual, inner, word, yank) Now I would like to replace some other word: viwp. This works only once, because each word is replaced by the last removed word. Ok, so I ...
4
votes
0answers
57 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 ...
4
votes
0answers
22 views

How to copy text to X primary selection only when visual mode is started with the mouse?

At the moment, if I use Visual mode, whenever I select a block of text using the keyboard it ends up on my X primary selection (ie the clipboard that is filled using the mouse). Even if I just select ...
3
votes
4answers
269 views

How to paste columns vertically to columns with unequal number of characters

We have two separate files: f1.txt 17.0, 155.7, 1123,9, and f2.txt 1 2 3 After opening files vertically with vim -O ~/f1.txt ~/f2.txt How to obtain? 17.0,1 155.7,2 1123,9,3 which is the ...
3
votes
2answers
369 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 ...

1
2
3 4 5
7