Visual block edit in vim
After pressing I
in visual block mode, vim appears to have entered insert mode. But when you exit the insert mode and go to normal mode again, you will see that the keys you pressed in insert mode have taken effect in the entire selected block.
A demo is available at this link
Vim: How to insert in visual block mode?
Try this
After selecting a block of text, press Shift+i or capital I.
Lowercase i will not work.
Then type the things you want and finally to apply it to all lines, press Esc twice.
If this doesn't work...
Check if you have +visualextra
enabled in your version of Vim.
You can do this by typing in :ver
and scrolling through the list of features. (You might want to copy and paste it into a buffer and do incremental search because the format is odd.)
Enabling it is outside the scope of this question but I'm sure you can find it somewhere.
Vim: insert the same characters across multiple lines
- Move the cursor to the
n
inname
. - Enter visual block mode (Ctrlv).
- Press j three times (or 3j) to jump down by 3 lines; G (capital g) to jump to the last line
- Press
I
(capital i). - Type in
vendor_
. Note: It will only update the screen in the first line - until Esc is pressed (6.), at which point all lines will be updated. - Press Esc.
An uppercase I
must be used rather than a lowercase i
, because the lowercase i
is interpreted as the start of a text object, which is rather useful on its own, e.g. for selecting inside a tag block (it
):
How to edit blocks in vim without visual block mode
What's so bad about blockwise visual mode?! There's no practical alternative to it.
- You could use
:substitute
with atoms like\%>v
,\%<v
,\%>l
and\%<l
to limit the pattern match to a rectangular block, but that's very tedious. - There are some multi-edit plugins (inspired by other editors) that allow you to select some areas, and then simultaneously edit them all.
- For special purposes, you could write a scriptlet / mapping with
getline()
/setline()
and String manipulation in Vimscript.
How do you select a whole column in visual block mode?
G goes to the last line, but moves the cursor to the first non-blank position if the startofline
or compatible
(which enables startofline
) options are set. If you want to keep the same column, set nosol
before going into visual block mode, and then hit G.
From the manual entry for startofline
:
When "on" the commands listed below move the cursor to the first non-blank of the line. When off the cursor is kept in the same column (if possible). This applies to the commands: CTRL-D, CTRL-U, CTRL-B, CTRL-F, "G", "H", "M", "L", gg, and to the commands "d", "<<" and ">>" with a linewise operator, with "%" with a count and to buffer changing commands (CTRL-^, :bnext, :bNext, etc.).
How to insert after the cursor in Vim visual block mode
Just like i inserts before the cursor and a inserts after the cursor in normal mode, Shift+a inserts after the cursor in visual block mode.
Visual block insert in redhat vim
Solution to your updated question:
- Go between "hello" & "world" on first line
- Press Ctrl+v to enter visual block mode.
- Go down using
2j
to select that column - Press I #An uppercase
I
- Press 4 spaces to get the desired output.
- Press Esc
Here's a small demo:
Related Topics
.Net-Core: Equivalent of Ildasm/Ilasm
Granting Access Permission to a File to a Specific User
Trying to Statically Link Boost
How to Enable Tab-Completion of Command Line Switches in Bash
Add Margin to PDF File When Merging Using Pdftk or Similar
Permissions Required to Move File to Different Directory in Unix/Linux
How to Deploy a Container into a Specific Node in a Docker Swarm
Linux Bash: Setting Iptables Rules to Allow Both Active and Passive Ftp
How to Find Hadoop Hdfs Directory on My System
Can Not Connect to Linux "Abstract" Unix Socket
Bluetooth Low Energy: Use Bluez Stack as a Peripheral (With Custom Services and Characteristics)
Context Switch in Interrupt Handlers
How to Make Cscope Display Full File Paths During Search
Why Is "Echo Foo | Read a ; Echo $A" Not Working as Expected
How to Write a Linux Bash Script That Tells Me Which Computers Are on in My Lan
Trace of Executed Programs Called by a Bash Script
Linux Kernel Device Driver to Dma from a Device into User-Space Memory