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
0answers
25 views

Pasting from vim to an ipython terminal

I have an open ipython terminal open, and I'd like to paste the visual selection to it, with prepending "%cpaste" and appending "--" This is what I came up with function! ...
1
vote
1answer
27 views

I wish <C-h> deletes characters that were inserted before pressing the ESC button

In the insert mode after pressing some characters the <C-h> combination pressed once removes the character to the left of the cursor. When repeated it removes next left character and so on. But ...
1
vote
1answer
29 views

How do I yank the next 4000 chars, ignoring linebreaks?

I can for example, copy three lines to the clipboard with "+y3j. But I nothing happens when I attempt to yank 3 chars to the clipboard with "+y3l. Ultimately, I want to copy chunks more like ...
0
votes
1answer
47 views

quickly replace content between quote, bracket ?

“hello world” “need be replaced by hello world” What I do is put cursor in first line, issue command yi" and then move cursor to second line, issue vi"p I want to know is there any more ...
2
votes
1answer
54 views

Option to prevent outer yank (ya') from yanking leading whitespace?

If i have something like foo( 'parameter' ) and I press ya' with the cursor somewhere inside the parameter string then the indentation space gets yanked too and I end up with 'parameter' in my * ...
2
votes
1answer
32 views

Restoring cursor to position before delete after Undo

This question is asked multiple places but none have an answer that works for me. I've tried: '' `` g; g, ; , Ctrl+o In a file add: 123456789 Move your cursor over 7 in normal mode, type d4h, press u....
0
votes
1answer
30 views

Delete multiple lines from cursor upwards

If you have a text like: word1 word2 word3 word4 word5 You can put your cursor over first d, type 2D and be left with: wor But you can't do the deletion upwards from second line with 2d^ or 2d0. ...
0
votes
1answer
105 views

vim ctrl+c doesn't copy/paste with ctrl+c or ctrl+v

I was trying to map ctrl+c to copy, ctrl+v to paste in vim, but it's not working properly.I've tried https://stackoverflow.com/questions/61177658/mapping-select-all-copy-paste-in-vim and https://...
3
votes
1answer
72 views

Paste a column in a table

Suppose I have this file open in Vim: AXXK M(X) 1.1 1 1.2 8 And that the clipboard holds U(1X) MX1 MX2 How can I easily paste that content as a new column? I want: AXXK M(X) U(1X) 1.1 1 ...
1
vote
2answers
66 views

Vim - Yanking a set/number/block of lines, and inserting/appending them before/after another set/number/block of lines?

If I have two 'sets' of lines, each consisting of X number of lines (but the lines differing in their individual lengths), can I yank one set and insert (or append) it to the other? To illustrate, can ...
0
votes
1answer
38 views

Automatically save deleted lines to a new file?

I have a to do list that I manage in vim. I want to keep track of things I remove from the list. After I type dd to delete a line, I want to write this line to a different file. I only want this ...
2
votes
3answers
58 views

How to delete a range of lines not up to N lines under a lines matching a pattern?

Say I have a document cat dog xxx 1 2 3 cow xxx a b c horse I would like to be able to run a command that will end up with xxx 1 2 3 xxx a b c whereby the transformation is defined by matching all ...
0
votes
1answer
31 views

How to multicut, edit and paste word after a word [duplicate]

Want to find a way to do in vim what I usually do in other text editors. It's really hard to describe the problem, so I've created a gif and attached it to this question. Initial document state: inv/...
0
votes
0answers
20 views

Creating vimrc kills my plugin

I have the following ~/.vim/filetype.vim: augroup filetypedetect au BufRead,BufNewFile *?Script.sml let maplocalleader = "h" | source /home/gergely/HOL/tools/vim/hol.vim " recognise ...
2
votes
0answers
68 views

While copying a file in netrw, why should I be in the directory where the file is located?

In netrw, I want to copy a file /dir/subdir1/file.txt to /dir/subdir2. For that, I do the following: I mark the file /dir/subdir1/file.txt I navigate up directory and mark /dir/subdir2/ as target ...
0
votes
2answers
37 views

How to cut characters in the middle of a line and place later in the line (not at the end)

This top line shows how it needs to be formatted, and the other 3 lines show how it currently is formatted. I need the bottom three lines to look like the top line. So, I need to essentially cut this ...
2
votes
2answers
289 views

What is the fastest way to yank with a line break? [duplicate]

Let say I have a simple line hell<cursor>o What is the fastest way to yank this line and paste to a result like this? hello hello I am currently doing this: yy # To yank this line p # Paste ...
0
votes
2answers
53 views

How can I warn when a large chunk of data is about to be (unknowingly) deleted?

I would like a warning when a large chunk of data is to be deleted. I tend to use the mouse along with vim to highlight text (to copy or delete). I also use the mouse to scroll notes when I want to ...
0
votes
1answer
21 views

Waiting for a copy event

I have the following function: function _X() normal! gvy vs tmp normal!p ALEFix black normal! ggVG normal! y <------- endfunc Unfortunately, the y does not work. That is, ...
0
votes
2answers
54 views

Yanking range into register while ignoring blank lines

I’m trying to yank a range into a register while ignoring blank lines. My range is from line 10 to the end of the file. :10,$v/./"*y Looking at my registers in :reg I see that my text is not in ...
0
votes
2answers
65 views

Efficient ways of moving/swapping words?

In my current flow, I find that moving words is made slower by having to insert a whitespace, so I was wondering if there is a more efficient way Here are two use cases: how do I efficiently move a ...
0
votes
1answer
64 views

What is a quick and efficient way to cut and paste text with Vim?

I'm a new Vim user (using the Vim extension in VSCode), and while it's faster at some operations, I'm having a lot of trouble finding an easy way to cut text (copy and delete it), then paste it at ...
1
vote
2answers
116 views

Copy to clipboard or save to file substitution command

I'm trying to answer a vim question in U&L, which involves a very complex and long regex substitution. I would like to copy to clipboard the command, or save it in a file, so I don't have to make ...
7
votes
2answers
295 views

Deleting lines matching a pattern and put them into the buffer

I am trying to do this: deleting lines matching a pattern and then copy these lines into some other place in the file. :g/PATTERN/d does delete the lines but when I use p or P, only the last line is ...
1
vote
1answer
44 views

Copy lines and execute in terminal window

Edit a python file with vim adddf.py, and type vert term and python3, there are two windows in vim. cat adddf.py def add_df(df,number): import re new_df = pd.DataFrame() nrow = df.shape[0] ...
-1
votes
1answer
35 views

mapping to delete and yank multiple lines e.g. d4y instead of d4d

In my vimrc I have nnoremap d "_d nnoremap yd dd to not save lines when I delete. Is it possible to create a mapping that when I press e.g. d4y it will cut 4 lines and save them into buffers? I ...
3
votes
2answers
157 views

Is it possible to copy/yank everything until a matching word is found?

Say I have a text like ... def my_function() do ... end ... And I want to yank/copy from def to end (including both def and end), so I can paste this block of text elsewhere. Is it possible to that ...
0
votes
1answer
26 views

How to copy the current value of a `set` option into the clipboard?

I sometimes need to copy the current value of a set option, e.g. set statusline, into the clipboard (+) to paste its value here. I know how to show the current value of a set option, e.g. set ...
3
votes
1answer
180 views

Recover cut text in vim

I've changed 2 pieces of text accidentally, by using C. Is it possible to access the previous piece, not the last one? (after getting out of vim) If I log back in, by pressing p it prints the last ...
0
votes
0answers
72 views

Copy text from terminal and paste to Vim while preserving text color

Is there a way to copy colored text from terminal and paste it as colored into vim? I am on MacOS, using iTerm2 Build 3.4.4beta3, and the following Vim version: % vim --version VIM - Vi IMproved 8.2 (...
0
votes
1answer
34 views

Yanking into register within a script is not working

Given a file like this: Roy Maurice Jen Douglas If I were to type the following commands: ggVj"zy, followed by :reg z, I would see Roy and Maurice. Now I want to yank Jen and Douglas into the z ...
0
votes
0answers
38 views

How do you disable automatically copying text when pasting over it in visual mode in VS Code? [duplicate]

Like the title says, if I have yanked some text, then select what I want to replace in visual mode, press p to paste, I want the original text still available to paste in other locations. I never ...
0
votes
0answers
43 views

How to bind <C-U> to <Cmd><BS> in vimrc?

I understand that <C-W> is backward-kill-word and I have bound this to shiftBS and it works. But now I want to bind <C-U> to cmdBS. Is this possible? If so, how can I do this?
0
votes
1answer
170 views

How to copy text to clipboard in visual mode? [duplicate]

I ran the following sequence of commands: V10j ⌘ c but it seems like this doesn't copy the ten lines to my clipboard. So how can I do this?
0
votes
2answers
46 views

paste in insertmode without indent i.e. `<C-r>*` without indent

I want to do :set paste, paste, :set nopaste in one keyboard shortcut in insertmode (<C-r>*) In visualmode, with vnoremap p "+p works with no indent. But in insertmode, this <C-r>* ...
0
votes
1answer
136 views

Delete/yank into multiple registers at the same time?

Is there a way to have y/d/c/x/s output into multiple registers at the same time - for example, "a as well as the system clipboard "+? I can do "aY"+Y obviously, and with Y it's ...
2
votes
2answers
200 views

optimise surround with quotes

I want to surround a word with quotes Here is my set of commands: ciw then when I am in insert mode, I type ' (I use the vim extension on Visual code so I get two ' I do not know if it the case for &...
2
votes
1answer
40 views

Delete up everything until searched term, including searched term

If the cursor is at t in the quick brown fox and we type d/brown, we delete the quick . Is there a way to extend this such that the searched term is deleted too? (Such that only fox remains.)
3
votes
2answers
149 views

Reliably saving and restoring registers across a function call [duplicate]

When writing functions to use in mappings and user-defined commands (for plug-ins), it's often convenient to use a Normal-mode command to yank or delete buffer contents. In those cases, it's also nice ...
1
vote
2answers
302 views

Yank a line without a line break or moving the cursor

I want to have a key binding to yank the current line into the system clipboard. My current mapping is as follows: nnoremap <C-y> "+yy However, this also yanks the newline. I often use ...
3
votes
6answers
168 views

Quickest way to put a single piece of text in multiple lines

Sometimes I have a bunch of lines, where there's a column clearly indicating some commonality between them, which in general doesn't go far beyond that column; this is an example, I think general ...
1
vote
2answers
28 views

make da( or dab remove lagging whitespace like daw

TL;DR: da( doesn't delete the following space like daw does. Can I make this do what I want easily? I have some sample lines (cursor is shown as |): 1. Sample line (extraneous| statement) in notes. 2. ...
3
votes
1answer
42 views

Need a functionality behaving like Replace on text but for Pasting Blocks

One of my vim usages is to do sketches of topologies in networking I've found the script Draw it really really useful for that So I can draw things like this by pasting these boxes +------+ |ROUTER| ...
1
vote
1answer
26 views

How to prevent cursor shift when using <C-O>{delete cmd} at the end of a line?

<C-w> deletes a (small-)word in insert mode, but I often want to delete the Word (to last whitespace) I've most recently typed. I tried inoremap <C-_> <C-o>dB which kind-of works -- ...
3
votes
3answers
498 views

How to quickly swap words (around pivot)

I have this: Alice --> Bob Dave --> Eve and want to change that to this: Bob <-- Alice Eve <-- Dave Changing from --> to <-- can easily be done with :s/-->/<--/, but swapping ...
0
votes
1answer
125 views

How can I make backspace work in visual block mode?

I hit Ctrl-v3jShift-ixEscape, and x is correctly inserted on the current line and in the 3 lines below it in the same column. Good. I hit Ctrl-v3jShift-iBackspaceEscape a character is deleted only on ...
1
vote
1answer
49 views

How to switch the order in which objects appear

I have a custom command in a TeX file which takes two inputs A and B, let's call it \operation{A}{B}. I want to find all of the instances of \operation where the first entry A starts with the string ...
0
votes
1answer
155 views

Inline paste from System Clipboard

I have recently started using Neovim on Windows 10. I use "+p to paste from the system clipboard. But sometimes I just want to paste inline before or after the cursor without adding a new line. ...
0
votes
5answers
283 views

How to copy multiple lines and paste multiple times under each line separately?

original below. I want to copy each line and paste multiple n times under their own lines separately. USD XYZ ABC YUT LMO . . . upto so on want them to become like this. Any way how can I achieve ...
2
votes
1answer
249 views

How do I copy the URL under the cursor?

In Vim, I can use gx in normal mode to open the URL under the cursor. Instead of opening the URL, how can I copy the URL? I am looking for something faster than entering into visual mode, selecting ...

1
2 3 4 5
8