Prepend to Visual Block Not Working in Vim

Visual block insert/append doesn't work

Ctrl-V-> select the block -> press I -> type #

then press ESC

more detail:

:h v_b_I

you can see:

Visual-block Insert                     *v_b_I* 

With a blockwise selection, I{string}<ESC> will insert {string} at the start
of block on every line of the block, provided that the line extends into the block.

prepend to visual block not working in vim

The source of the problem was lack of compiled support (thanks to my shared hosting provider). For others who are having a similar problem, check vim for the +visualextra option. You can check from normal mode with:

:echo has('visualextra')

It will return a "1" if it does. Otherwise you can look using:

:version

Or by invoking the --version option from the commandline:

vim --version | grep visualextra

Vim called from Git Bash: visual block prepend does not get applied to all lines

It seems like the vim that you are using is the one that came installed with git-bash, since vim works like you'd expect from within powershell and cmd prompt.

Follow the steps here to see if changing the vim version to your own makes the visual block prepend feature work.
https://superuser.com/questions/423532/how-do-i-use-installed-vim-in-git-bash-instead-of-the-one-that-came-with-git

From top answer by 'nevermind':

By default Git runs vim from Git\bin\vim. This is actually a script that contains path to the executable itself:

#!/bin/sh
exec /share/vim/vim73/vim "$@"

Therefore you can edit this file to point to your Git location.

The default editor can be overridden in Git\etc\gitconfig:

[core]
editor = path_to_your_editor

I hope this helps!

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.

Visual block insert in redhat vim

Solution to your updated question:

  1. Go between "hello" & "world" on first line
  2. Press Ctrl+v to enter visual block mode.
  3. Go down using 2j to select that column
  4. Press I #An uppercase I
  5. Press 4 spaces to get the desired output.
  6. Press Esc

Here's a small demo:

demo gif

Why lowercase [i] does not work in visual block mode?

The reason because i and a are not behave like in normal mode in all visual modes is that i and a are used to extend the selection to text objects. As you can see in :help visual-operators:

4. Operating on the Visual area

The operators that can be used are:
~ switch case
d delete
c change (4)
y yank
> shift right (4)
< shift left (4)
! filter through external command (1)
= filter through 'equalprg' option command (1)
gq format lines to 'textwidth' length (1)

The objects that can be used are:
aw a word (with white space)
iw inner word
aW a WORD (with white space)
iW inner WORD
as a sentence (with white space)
is inner sentence
ap a paragraph (with white space)
ip inner paragraph
ab a () block (with parenthesis)
ib inner () block
aB a {} block (with braces)
iB inner {} block
at a <tag> </tag> block (with tags)
it inner <tag> </tag> block
a< a <> block (with <>)
i< inner <> block
a[ a [] block (with [])
i[ inner [] block
a" a double quoted string (with quotes)
i" inner double quoted string
a' a single quoted string (with quotes)
i' inner simple quoted string
a` a string in backticks (with backticks)
i` inner string in backticks

Additionally the following commands can be used:
: start Ex command for highlighted lines (1)
r change (4)
s change
C change (2)(4)
S change (2)
R change (2)
x delete
D delete (3)
X delete (2)
Y yank (2)
p put
J join (1)
U make uppercase
u make lowercase
^] find tag
I block insert
A block append

So just use the block insert uppercase I or the the block append uppercase A commands in visual block mode.

Append to visual block only on specific lines

The only native way to accomplish that from visual-block mode or any other visual mode is to use a substitution:

:'<,'>s/emos/&_suffix<CR>

where…

  • you press :,
  • Vim inserts the range '<,'> for you, meaning "from the fist selected line, :help '<, through the last selected line, :help '>`,
  • s/emos/&_suffix substitutes every first occurrence of emos on each line of the given range with itself, :help s/\&, followed by _suffix.

Visual selection is often an unnecessary step and, in this case, visual-block mode is totally useless because A or I is going to operate on every line of the selection anyway.

Another method:

/emos/e<CR>
a_suffix<Esc>
n
.

Another one:

/emos<CR>
cgn<C-r>"
_suffix<Esc>
.

Another one, assuming the cursor is on the first line of your sample:

:,'}s/emos/&_suffix<CR>

Etc.



Related Topics



Leave a reply



Submit