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
54 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
53 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
32 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
48 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
30 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
18 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
62 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
36 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
256 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
18 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
46 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
47 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
46 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
90 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 ...
6
votes
2answers
242 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
42 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
32 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
85 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
25 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
109 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
21 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
37 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
39 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
103 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
92 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
161 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
33 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
105 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
276 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
157 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
26 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
39 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
24 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
364 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
72 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
35 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
121 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
165 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
200 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 ...
0
votes
3answers
58 views

How to copy the selection to clipboard without the indentation that is relevant just in the full file, not in the selection?

With other words: How to copy selection without its root-level indentation? Example: How to copy this: a b c d instead of: a b c d I am using Neovim inside VS Code ...
0
votes
1answer
46 views

clipboard not activated

I installed vim from their github repo. But I cannot seem to copy paste with from the system clipboard. So, I explored a little and tried to install vim-gtk package which would enable the clipboard ...
2
votes
1answer
82 views

How do I enable copy/paste between vim and tmux in both two directions?

In a tmux session, I'm running vim in one pane and a terminal in another pane. Recently, I figured out how to enter visual mode in tmux but it doesn't help much now. Can I yank selected text from a ...
0
votes
0answers
23 views

How to paste text from other applications into Vim without incrementally indenting each pasted line? [duplicate]

I want to copy text from other applications into Vim, e.g. from Visual Studio Code, but the result is awful. In particular, each pasted line is being indented incrementally: Furthermore, visually ...
1
vote
1answer
991 views

Yank multiple lines without using visual mode

I have the text: abcd abcd abcd abcd my cursor is in the first line, and I want to yank the first 2 lines. Usually I would do it by pressing Shift+v, selecting the second line by going down with j ...
0
votes
1answer
69 views

Grep for a pattern using current visual selection on another file

I want to basically search for a pattern in the current file on another file, from vim, using the current visual selection. I know doing: :grep pattern otherfile works, but i want the 'pattern' to be ...
1
vote
1answer
73 views

Vim filter command not using line-wise selection

I may have seen this question before on Vi Exchange but I'm having trouble locating it while searching now. If it's already been answered, please let me know the duplicate and I can find that. I have ...
1
vote
2answers
189 views

How can I paste text appending it to the end of each line? [duplicate]

If I have file1.txt which contains the following: Line 1.1; Line 1.2; Line 1.3; and file2.txt with the following Line 2.1; Line 2.2; Line 2.3; I want to copy all the lines of file2.txt and paste it ...

1
2 3 4 5
7