Skip to main content

All Questions

Filter by
Sorted by
Tagged with
34 votes
8 answers
20k views

Faster way to move a block of text

Here's how I usually copy a block of text or code: Select the block with Visual mode (V) and delete it with d; or if it's just a single line, just use dd. Go to where I want the text to be, I am too ...
Martin Tournoij's user avatar
17 votes
3 answers
2k views

How do I visually select the block of text I just pasted in Vim?

I usually need to move/copy code snippets between my source files. After I paste a block of text, I usually need to apply some operation to that block such as reindenting them with =. Is there a way ...
thameera's user avatar
  • 17.8k
10 votes
6 answers
4k views

Clipboard is reset after first paste in Visual mode

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 go to the original source and then do the copy ...
ng.newbie's user avatar
  • 255
8 votes
3 answers
3k views

How to simply remove braces

One of my friend told me that I can use the trick below to remove a pair of curly brackets. Put the cursor inside the curly bracket pair you want to remove. y i { to yank the text in braces , then v ...
MrDwZ's user avatar
  • 101
8 votes
2 answers
6k 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 (...
user19858's user avatar
  • 171
8 votes
3 answers
2k views

Yank/select until delimiter in different lines

From the following text: variable1 = 'example' foo = 'foo' barett = 'ver' I would like to yank (or visually select, if possible) the content of each line until the = sign: variable1 foo barett ...
user2891462's user avatar
6 votes
3 answers
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 ...
statox's user avatar
  • 50.6k
6 votes
2 answers
1k 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. ...
Ruslan's user avatar
  • 475
6 votes
1 answer
1k 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. ...
Mees de Vries's user avatar
6 votes
0 answers
198 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 ...
Muzer's user avatar
  • 161
5 votes
3 answers
621 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.
hgiesel's user avatar
  • 1,954
4 votes
1 answer
433 views

Why does `yW` yank until the end of the WORD, but `W` move to the next one?

My confusion started with realizing, that yW yanks a different region, then what vW selects, but I found this that explains about selection. But then I realized, that while yW will yank until the end ...
fbence's user avatar
  • 707
4 votes
0 answers
254 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! ...
Uri Goren's user avatar
  • 141
3 votes
2 answers
734 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 ...
reFORtEM's user avatar
  • 133
3 votes
2 answers
101 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 ...
Awe Some's user avatar
3 votes
2 answers
852 views

Vim: Replace visual selection without overwriting the unnamed register

How do I replace a visual selection with some register content without overwriting the unnamed ("") register by the visual selection? The question https://stackoverflow.com/questions/3837772/vim-...
Bananach's user avatar
  • 524
3 votes
1 answer
400 views

Duplicate selected lines programmatically

I'm creating a Vim script and a critical part of it is duplicating the selected lines. To duplicate lines, I have this mapping which works as intended: vnoremap <Leader>d :copy '><CR> ...
Ranel Padon's user avatar
2 votes
3 answers
2k 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'...
DannyM's user avatar
  • 121
2 votes
2 answers
1k views

Stop Vim from yanking visual selected text

Let's say I have a file like this (abc) (123) (456) I want to yank abc and paste it in place of 123 and 456. I would yi) on the first line. Then go down a line and paste it with vi)p. But for the 456,...
Tai Nguyen's user avatar
2 votes
1 answer
73 views

Is there a text object or motion for non-comment lines are not separated from comment lines by blank lines? E.g., in git commit messages

Consider the text A B # C # D Is there a text object or motion that will select lines A and B if the cursor is on either, but not select lines C and D? ap or ip with the cursor on any of those four ...
cxw's user avatar
  • 974
2 votes
1 answer
309 views

How do you get which "side" of the visual mode selection the cursor is on in vimscript?

I'm writing some vimscript and would like to preserve the cursor position after a yank occurs in visual mode. Ths issue is that I can't find any way to get the cursor position while in visual mode. ...
Steve Vermeulen's user avatar
2 votes
1 answer
439 views

better copy-paste multiple lines in visual mode where vim pastes after that visual chunk of code

I want to select multiple lines in vim, copy them, and paste after that chunk of code (with cursor at the beginning). yp doesn't work because in visual chunk of code, vim pastes after the 1st line of ...
Mega Bang's user avatar
  • 319
1 vote
5 answers
752 views

Yank lines without leading whitespace

If I have code like this: const treeData = { name: "Parent", children: [ { name: "Child 1", children: [ { name: "Grandchild 1" ...
user avatar
1 vote
1 answer
499 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 ...
Nordine Lotfi's user avatar
1 vote
1 answer
70 views

Paste in front or after in visual-block mode?

I can enter visual-block mode using <C-v>, move down a couple of rows by pressing j several times, then paste some content from the registry via pressing p or P. However, the pasting will ...
athos's user avatar
  • 359
1 vote
1 answer
84 views

How to yank while in visual mode without showing message?

When I'm in visual mode and I yank the selection (which has at least 3 lines), messages like these are shown: 4 lines yanked block of 4 lines yanked How can I suppress this so it won't appear in :...
Steve Ward's user avatar
1 vote
1 answer
1k views

How to yank word from all selected lines in visual mode?

In the middle of a line, Press v and select multiple lines. How to yank the word at current cursor from all selected lines and add spaces if the word is shorter than the longest one to make copied ...
Fisher's user avatar
  • 1,096
1 vote
1 answer
52 views

How would I modify this function to restore from a specified register?

Currently I have the following mapping in my vimrc nnoremap d "_d nnoremap D "_D nnoremap C "_C nnoremap c "_c nnoremap <leader>d "*d nnoremap <leader>D "*D" The result of the above ...
James Franco's user avatar
  • 1,161
1 vote
1 answer
55 views

Why doesn't the dot command work after pasting in visual mode?

1. Why doesn't this work? If my text file is: aaa test bbbb test test bbbb test test bbbb test I can yank aaa, select bbbb in visual mode, and type "0p, to replace it with aaa, with the idea of ...
Zantier's user avatar
  • 111
1 vote
1 answer
2k views

How to paste yanked text over visual selection?

Yanked text with y, then v select some text, paste with p, but nothing happens.
Fisher's user avatar
  • 1,096
1 vote
0 answers
39 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 ...
Philip's user avatar
  • 301
0 votes
1 answer
127 views

Why do I need to type ggVVG to select all, instead of just ggVG? [closed]

Sometimes, ggVG does not work to select text. It will move the cursor to the top, but not select the text. This happens seemingly randomly. I have figured out if I type ggVVG it will work as expected. ...
BigMistake's user avatar
0 votes
1 answer
46 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 ...
Phil R's user avatar
  • 547
0 votes
2 answers
183 views

How to paste a line inside another line ? i.e. How to paste a line as words?

I would like to easily transform these two lines : One line. long line with many words in this example into the line : One long line with many words in this example line. How I currently do ...
Gabriel Devillers's user avatar
0 votes
1 answer
74 views

Vim visual block copy don't paste in KDE konsole

Selecting by visual line mode and copying (V and y) in vim in rxvt-unicode or in gnome-terminal and pasting in another tab of that terminal with Shift + Insert works well. But trying to do the same ...
pevik's user avatar
  • 109
0 votes
0 answers
61 views

What's controlling Vim paste behaviour?

What's controlling Vim paste behaviour via Vim over ssh using putty with right-click paste set to Linux host? To start we have: VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Mar 27 2023 00:00:00) ...
chipfall's user avatar
  • 103
0 votes
1 answer
90 views

Copying non-consecutive selected lines in visual mode

Basically I want to select and copy a bunch of non-sequential lines (some lines only partially) from different locations of a code, in a way that each yanked line is appended to clipboard register so ...
Puya's user avatar
  • 15