As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [visual-block]

Visual block mode enables users to copy and paste rectangular text. This mode is useful whenever a particular text is pasted to be pasted in every part of a rectangular text.

Filter by
Sorted by
Tagged with
56 votes
5 answers
46k views

How can I insert text at the end of a group of lines?

Let's say I had a block of text... Lorem ipsum Lorem ipsum dolor Lorem ipsum dolor sit Lorem ipsum dolor sit amet ...and I wanted to insert a . at the end of each line. What would the best approach ...
vim.ryan's user avatar
  • 661
16 votes
1 answer
1k views

Paste visual block selection on its own lines [duplicate]

I'm not really sure how to describe what I'd like to do. Basically I'd like to use visual block mode to select a region of text and then paste it "as a collection of lines" rather than as a rectangle. ...
Greg Nisbet's user avatar
  • 1,755
15 votes
3 answers
10k views

Visual select from cursor to next empty line?

How does one select from the current line to the next empty line? I'm aware of SHIFT+V but then I have to either jump to the next empty line or press the down key a bunch of times. I know how to do ...
leeand00's user avatar
  • 3,335
13 votes
1 answer
3k views

Visual block insert new line

I work a lot with visual block mode, which I find really useful for quick changes across a lot of lines. But something I'm struggling to do is inserting a newline like so: Selection is noted as []: ...
nobe4's user avatar
  • 15.7k
12 votes
2 answers
1k views

How to paste visual block starting with another line

It took me very long time to realize that putting (pasting) something with p or P which visual-block selects with ctrl+v and yanked (copied) with y, preserves the manner before, so that, when the ...
Violapterin's user avatar
11 votes
3 answers
2k views

Visual Block Mode edit with sequential number [duplicate]

Suppose I'd like to create a list - "1" - "2" - "3" what Is the smartest way to create such? My attempt would be to i- "1"ESCyypp to get - "1" - "1" - "1" and then jump to the second line's 1 ...
Joel's user avatar
  • 213
10 votes
2 answers
9k views

Is there a command to enter Visual Block mode?

I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work). Is there any ...
Dan's user avatar
  • 445
10 votes
1 answer
1k views

Sorting a column without altering other columns

I was recently aware of the filtering ! technique, and I love it. Unfortunately, I am not able to use it in a visual-block mode. Hope some experts here would help me out. Basically, I want to in-...
Loves Probability's user avatar
9 votes
3 answers
7k views

How can I add text to the end of words on each line?

I have a series of single-word codes on separate lines in a text file. I'd like to add a backquote ( ` ) to the beginning and end of each word. I know I can add a backquote to the beginning of each ...
Yehuda's user avatar
  • 265
8 votes
4 answers
3k views

Add constant integer to visually selected numbers

I have a file like the following : two different files were yanked one after another, and the numbers subsequently don't match anymore. ... 46 atom 142 option 47 atom 143 ...
Feffe's user avatar
  • 1,739
8 votes
3 answers
7k views

Visual Block Mode: How to insert text to multiple lines after line ending?

Below example, first line is shorter than the other lines. I want to insert \ to all lines at the highlighted place. If I press CtrlC, jjj(select all lines) , Shifti, \, only first line changed. How ...
Fisher's user avatar
  • 1,022
8 votes
1 answer
5k views

Deleting and inserting in a single visual block selection

I'm trying to understand how the visual-block mode deals with Backspace and Delete, and if it is possible to vertically select a column of text, delete some characters, then insert new ones in a ...
Ryan Bell's user avatar
8 votes
2 answers
931 views

How I force [count]<C-x> to leave leading zeros?

Context I use vifm as my file manager (that's off topic here, i know, but keep reading) which allows me to edit filenames inside a vim buffer. One issue i found myself annoyed at are numbered files ...
grochmal's user avatar
  • 1,636
7 votes
1 answer
3k views

vmap and visual block: how do I write a function to operate once for the entire block?

I'm trying to write a simple function that wraps a visual selection of lines with Markdown ``` lines. Here's what I currently have: function! MarkCodeBlock() " Add Markdown code-block delimiters ...
Steve Hollasch's user avatar
7 votes
1 answer
356 views

What does [count]v and [count]V do? How is it useful?

I am confused about how the start visual commands work when you pass them a count. I checked the help page but I am still confused. [count]V Start Visual mode linewise. ...
wefwefa3's user avatar
  • 1,113
7 votes
2 answers
18k views

What does it mean to set clipboard=unnamed?

Today I was trying to copy and paste multiple lines in visual block mode and found this excellent answer on StackOverflow showing how to do it. Below is a gif of what I was trying to accomplish: ...
Guilherme's user avatar
  • 173
7 votes
1 answer
988 views

Replace all occurrences in visual block selection but NOT all occurrences on line

I'm trying to figure out how to do a search and replace on a visual block selection that will replace all occurrences in the visual block selection without replacing all occurrences on the line. What ...
user avatar
6 votes
3 answers
3k views

Add a block of text to end of lines

Not sure if this one is possible, but say I have a file with two blocks of text, in this case English words and their French translations. eg: vivre aimer étudier to live to like to study Now I ...
port5432's user avatar
  • 175
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
  • 48.5k
6 votes
1 answer
955 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 ...
Jonah's user avatar
  • 733
6 votes
1 answer
2k views

Jump *to* end of paragraph?

I often find I want to quickly select all the characters in an aligned column, something like this: this.p = obj.['propery']; this.prop = obj.['proper']; this.proper = obj.['...
gandalf3's user avatar
  • 267
5 votes
4 answers
3k views

How do you change the last n characters for a range of lines?

Generally you can select a visual block for the first n characters of a range of lines, and just press c, insert characters, and press Esc to have it apply to all. However, this method is rarely ...
Anon's user avatar
  • 835
5 votes
6 answers
719 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 ...
Enlico's user avatar
  • 2,054
5 votes
3 answers
5k views

How to indent or unindent lines in a block of text?

I use two spaces in my indentation of codes. What are the possible ways to indent or unindent a block of code?
Majal's user avatar
  • 153
5 votes
3 answers
191 views

Insert non-rectangular selection

I repeatedly have the following situation, and wonder how it can be handled better than I do it now. These lines must be merged /path;text /path;text /path;text with these: /subdir /longsubdir /...
atann's user avatar
  • 51
5 votes
1 answer
1k views

Visual block editing: map i

How to map i to start editing on visual block mode? I want the same behavior for <shift>-i and i.
adelarsq's user avatar
  • 584
5 votes
2 answers
374 views

How to center a block without centering its contents

For a visual block selection, the :center command will centre the contents of the selection, not the block as a whole. Is there a way to centre the block as a whole without misaligning the contents? ...
user avatar
4 votes
2 answers
847 views

Vertically rotate visual block

How would one vertically rotate a visual block of text? For example given this: h e l l o Select those characters in visual block and rotate them once: o h e l l As you see, every character is ...
user avatar
4 votes
2 answers
461 views

Replacing text with a visual block

Here is what I want to do. Consider the text abcvvxyz abcvvxyz 123456 123456 I would like to copy the v block and paste it over the 45 block to get the following: abcvvxyz abcvvxyz 123vv6 123vv6 ...
January's user avatar
  • 263
4 votes
1 answer
295 views

Is there a way in Vim to draw the visual area of the same size as the last visual selection, but at a new cursor position?

After I visually select the following area And press Esc and move this position I want to be able to select the same shape in this manner If there is no generic and direct way to do this, any tips ...
vimKoans44's user avatar
4 votes
5 answers
2k views

How to write on multiple places at once

I'm familiar with vertical blocks, and I often ctrl+v down down down shift+I foobar esc to write foobar in various locations at once. This is useful if I want to replace <td> to <th> in a ...
mazunki's user avatar
  • 143
4 votes
1 answer
1k views

Trailing characters error in a substitution command

Suddenly simple find&replace stopped working in one particular case. I'm selecting the code-block in visual-mode, so the final command looks like: '<,'>%s/someStuff/stuff/gI I get the ...
z0lupka's user avatar
  • 143
4 votes
2 answers
6k views

VIM - How to select multiple lines that are not adjacent?

If you have the following text: line 1 line 2 line 3 You can hit CTRL+v on line 1 and hit j to select line 2. However, I want to select both line 1 and line 3, but not line 2. Or, select multiple ...
Dr-Bracket's user avatar
3 votes
4 answers
736 views

Substitute figure by math

I have a file like this: 1 2 3 4 5 6 7 8 9 0 1 2 I want to change a block-wise visual selection area, e.g. 5 and 8. I want to substitute them by multiplying the figures by 0.7 and I want to ...
warem's user avatar
  • 141
3 votes
3 answers
581 views

Paste a block-copy into a single line

I need to restructure a markdown table, and for that, I wish there was a quick way to "join" lines from a multi-line cell. So with Vim, I would have to yank the block (Ctrl-v), and then ...
PlasmaBinturong's user avatar
3 votes
2 answers
684 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
1 answer
1k views

Can I select and edit specific positions in lines while in visual block mode?

say for example, I have this text: <div class="test1"></div> <span class="highlight"></span> <nav class="tester"></nav> <aside class="wrapper"></aside> ...
the_velour_fog's user avatar
3 votes
1 answer
47 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| ...
freddie_ventura's user avatar
3 votes
1 answer
192 views

how to write command to save selected text?

I want to save selected text in vim. I use command :'<,'>w! ~/save.txt. How to write a short command instead of it, or mapping it to key mappings.
linrongbin's user avatar
2 votes
2 answers
106 views

Visual block. Some right-end selections seem impossible

I want to use visual block mode (ctl-v) to select all the comments but none of the code: a = 1 // short comment b = 2 // this one is a longer comment c = 3 // ...
user251764's user avatar
2 votes
3 answers
688 views

Visual block yank to end of line

I found a vim tip a while back recommending swapping visual and visual block mode (http://howivim.com/2016/damian-conway/) For the most part this is really useful. I frequently find myself wanting to ...
Greg Nisbet's user avatar
  • 1,755
2 votes
2 answers
2k views

Delete from end of line in visual block mode

If i've got the code hello hellllo hello i can insert code before or after all of the lines by using I or A in visual block mode, respectively. How can I delete the last x characters? I'm aware ...
user642832's user avatar
2 votes
2 answers
296 views

How do I quote tabulated columns?

Currently, I'm using Vim Surround to make quoting easy on Multiple whole-lines Visual blocks Individual words However, it doesn't seem to make the job easy on columns, for example. Take this ...
Evan Carroll's user avatar
  • 1,016
2 votes
2 answers
159 views

Incrementing File Names

I'm hoping to create a .cl script to run in IRAF. I have a list of spectra on which I want to run dispcor. I was wondering if there's an easy way to paste the output file names with incrementing ...
catclark's user avatar
2 votes
1 answer
186 views

Pasting modified register contents into Visual Block selection

Consider this mapping: vnoremap <leader>U ygv"=toupper(@@)<cr>p It will yank the current visual selection, select it back, and then put a modified version of it. In this case, uppercase ...
filbranden's user avatar
  • 27.6k
2 votes
3 answers
317 views

Is it possible to perform a visual block selection programmatically using line and column numbers?

I've looked around in :help V but haven't found anything of this sort, but was wondering if there's a function I can call from vimscript that would visually select a region based on (row, column) ...
merlin2011's user avatar
2 votes
1 answer
122 views

Why does ^C behave differently from ESC when exiting visual block substitution?

I've started using CTRL+C instead of ESC in vim because of its position on the keyboard and better responsiveness. It mostly behaves the same except when exiting visual block replacements. I am ...
Lombard's user avatar
  • 253
2 votes
1 answer
62 views

extra newlines when pasting altered string in visual block mode

Suppose I have an open buffer containing the following text 1111111111 1 1 1 222222 1 1 2 2 1 1 2 33 2 1 1 2 33 2 1 1 2 33 2 1 1 2 2 1 1 222222 1 1 1 1111111111 I can visually ...
rampion's user avatar
  • 201
2 votes
1 answer
79 views

How does p really works as related to content put in registers?

I've read this question and answer already, however it could not solve my doubts. As far as my understanding is correct, p always has the same effect (putting the content of a register, by default ...
Enlico's user avatar
  • 2,054
2 votes
2 answers
988 views

How to keep Vim from exiting Visual Mode due to mouse clicks while mouse=a?

Currently when I click somewhere in the terminal with mouse=a enabled, Vim exits visual mode. How can I force Vim to remain in Visual mode, and thereby use mouse clicks (not drags) to create a ...
Luke Davis's user avatar
  • 1,327