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
2
votes
1answer
60 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. Is this possible?
1
vote
1answer
48 views

Yank visually selected text: Keep virtualedit & avoid left/right padding

I use Cygwin's vim & gvim. I used to be able to do as follows. Consider this file mk.bash, with no right-padding spaces: // mk.bash // ------- javac \ -classpath "/c/Program Files/MyJarFile....
2
votes
1answer
26 views

bad comment behavior in cmake files

When I'm editing a cmake file in (neo)vim I'm getting bad behavior block inserting comment characters. Given this section of text install_license_file( PACKAGE tomcrypt TARGET ...
6
votes
3answers
638 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 ...
3
votes
3answers
98 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 ...
0
votes
1answer
18 views

How to delete and replace a block of text with spaces?

What I want to do I want to select a block of text in Vim, delete it, and replace the selected block with spaces. Example Suppose I have the following text: Lorem ipsum dolor sit amet, ...
0
votes
1answer
53 views

Discrete Visual mode

A feature that I love in VSCode is to be able to use my mouse to click at multiple points in the screen and type with multiple cursors. I am aware that in Vim you can do the same in visual mode, but ...
1
vote
1answer
455 views

In Windows 10, WSL 2, Windows Terminal, bash and VIM, how to avoid the conflict of <c-v>?

With the newly released Windows 10 update 2004, we can run native Windows Subsystem for Linux (WSL) 2 and install Ubuntu 20.04 on it. Then we can run native bash inside the latest Windows Terminal. ...
2
votes
1answer
48 views

Put cursor at arbitrary line and column

Normal, insert, and visual modes restrict cursor movements to locations occupied by some characters. They don't allow moving to the right from the end of line and down beyond end of file. For example:...
0
votes
1answer
31 views

Select text in block-wise visual mode on each line asynchronously

If I have text like this: cat = "john" leopard = "frank" tiger = "josh" and I want to select the first word of each line in block-wise visual mode, I want to be able to do something like this: put ...
1
vote
1answer
46 views

blockwise visual mode multi line prepend doesn't work for me [duplicate]

I'm using nVim v0.4.3 and I'm having trouble getting multiline inserts to work in visual blockwise mode. You can check this asciinema to see what I'm doing. https://asciinema.org/a/...
0
votes
1answer
20 views

Search and replace visual block only? [duplicate]

How do I search and replace in a visual block only? '<,'>s/search/replace/ works on entire lines, not visual blocks only.
1
vote
0answers
31 views

Swap characters, vertically

Is there a handy way to do this? My input: # A # - B Desired output: # - A # B My current solution is xjphxkP, which seems like a lot of keystrokes. I realize I could record a macro, but it ...
1
vote
2answers
47 views

Inserting text at the beginning of all lines selected in visual line mode [duplicate]

I have selected a JS block such as following: function map(xs: string[], cb: Function) : string[] { const result: string[] = []; for(let i = 0; i++; i < xs.length) { result.push(cb(xs[i]));...
4
votes
1answer
191 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 ...
3
votes
4answers
636 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 ...
1
vote
1answer
120 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 ...
2
votes
1answer
64 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 ...
0
votes
1answer
84 views

Gradient color background for visual selections

In this video from Bisqwit, the selected line is colored by a gradient according to column number. Image is below. He implemented the gradient in a custom terminal emulator. Is there any way to ...
2
votes
1answer
42 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 ...
2
votes
1answer
76 views

Is there a function for blockwise visual selection in Vimcript?

I have two text files including steps, one is the main-file which has the entire steps and the other one is a sub-file has only part of steps. As follows. [main-file] SeqMain.txt 0001 K1G554 1 1 ...
3
votes
1answer
614 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.['...
1
vote
1answer
32 views

Entering visual mode is selecting whole lines unexpectedly

I'm editing a small bash script: d=$1 year=$(date -d"$d" +%Y) month=$(date -d "$d" +%m) day=$(date -d "$d" +%d) hive -f /home/gavin_cameron/hive_queries/dc_player_daily_snapshot.hive -d ...
2
votes
3answers
1k 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?
1
vote
3answers
201 views

Selecting code chunk in Rmarkdown

I am writing an RMarkdown file, which is a document that is a hybrid of text and R code. Here is an example of what that document could look like: Here is an example of text within my Rmarkdown file. ...
0
votes
1answer
40 views

Is there a way to determine whether the current / last visual block selection is non-rectangular?

One can create non-rectangular Visual-Block selections using C-v$ on files with lines of non-equal length. Is it possible to programmatically determine whether the last Visual Block selection was non-...
0
votes
3answers
495 views

Is it possible to yank a column of text in vim without visual block mode?

Consider the following text file. 1 1 3 1 1 5 One can rank row 1 with the command y$ with the cursor on row 1, column 1. However, to yank the first column, the only way I know is to <C-v>3jy. ...
1
vote
2answers
86 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) ...
7
votes
3answers
791 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 ...
1
vote
5answers
740 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 ...
0
votes
3answers
80 views

What's the simplest way to select the longest non blank vertical column in visual block wise mode? [duplicate]

assume you you have some text like this: <-------unknown area <-------blank lines .....0.....<-------dot represent unknown character .....1..... .....*.....<-------...
0
votes
1answer
894 views

Jump to bottom of block in Visual Block mode

I have some code that looks similar to this: [ (Text), (Text), (Text), ], I want to edit the lines that say "Text" by using Visual Block mode. I can type ctrl-v on the first "T" and ...
0
votes
0answers
146 views

Blockwise pasting from "+ register not working

UPDATE: I run an X server (XQuartz 2.7.11) on MacOS, which I forward via ssh to any Linux machine I use. The problem seems to be that under XQuartz, the "+ register does not support blockwise yanking/...
1
vote
1answer
82 views

How can I stagger text in vim?

Given the following text: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 How can each line be shifted left/right an amount related to their line number? Desired outputs: 1 2 3 4 5 1 2 3 4 5 ...
2
votes
3answers
3k 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 ...
0
votes
1answer
41 views

Bind visual mode 'I' and 'A' to always use visual block mode before inserting

Is there a way to bind I and A in visual mode and visual line mode to switch the selected region to a visual block selection with the same boundaries? I'd like to be able to use visual line mode to ...
2
votes
1answer
77 views

How to visual select everything within a pair of fold markers

Are there simple tweaks that I can visual select everything with in a pair of fold markers? Just like what vi" will do for a pair of double quotes. Preferably vi plus some other keys.
3
votes
1answer
956 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 ...
0
votes
3answers
62 views

How do I insert a single space into the same column of a group of lines?

For example, I wish to change 1 1 2 3 5 8 13 to 1 1 2 3 5 8 13 Where this is not necessarily at the start of the line. How can I do this?
1
vote
2answers
470 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 ...
2
votes
1answer
116 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 ...
3
votes
3answers
2k 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 ...
0
votes
1answer
52 views

Move to last line leave cursor in place [duplicate]

I know I can move to the last line of the file using G but that will move cursor to the first column. When in visual block mode I would like to extend the selection to the last line without moving ...
2
votes
2answers
7k 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: ...
1
vote
1answer
1k views

What does <C-V>?<Space><CR> do?

What does C-V ? space CR do? Can someone explain that key by key? I know C-V is visual block mode, but the ? ? How does that work? Imagine this, with the cursor on the first line, first char: ...
1
vote
1answer
56 views

replacing character in a visual block selection replaces the wrong character?

In visual selection mode, accessed with ctrl-v, I can replace the character I want (say Z to be replaced by A) within my selection by typing : followed by s/Z/A. This is extremely useful. Here is a ...
3
votes
2answers
529 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 ...
0
votes
1answer
111 views

how to accept count for visual block ctrl+a remap?

I have created a vmap but I can't figure out how to apply a count to it. In this case, the mapping is on <C-a> and 4<C-a> is an example of a command with a count failing to be applied. We ...
6
votes
1answer
3k 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 ...
0
votes
1answer
65 views

How can I move the cursor in block mode (without changing the block)?

When a visual block is created, the block itself is highlighted, but the cursor is highlighted differently, green in my terminal. If I want the block to stay the same but move just the location of ...