63
votes
How can I insert text at the end of a group of lines?
I do the following to append text to multiple lines:
<c-V> - Enter Visual Block mode.
Use j/k to select the lines.
$ - Move cursor to last character.
A - Enter insert mode after last character.
...
26
votes
Accepted
Visual select from cursor to next empty line?
Vim understands the concept of a "paragraph". Vim's definition of a paragraph is a block of text surrounded by blank lines*. There are several motions and text objects to work with this.
[count]} – ...
19
votes
Accepted
vmap and visual block: how do I write a function to operate once for the entire block?
When you press leader _, you enter command-line mode from visual mode.
If you try to enter command-line mode from visual mode manually, you'll see that Vim automatically inserts this range:
:'<,'&...
18
votes
Accepted
Paste visual block selection on its own lines
Try this:
:put! "
:put: insert the contents of the specified register
!: insert before the current line (the default is after)
": the unnamed register (check :help registers for details)
You could ...
18
votes
How can I insert text at the end of a group of lines?
On first line just type:
4:norm A.
4 and : create a range for you and then norm A. adds the dot to each line
Another solution for longer paragraphs could be:
Vip<C-v>$A.<Esc>
The first ...
16
votes
Visual select from cursor to next empty line?
A shortcut for next empty line is }.
So you just might want to use SHIFT+v}
16
votes
Accepted
Deleting and inserting in a single visual block selection
Instead of deleting with d, select spaces in Visual Block Mode and press c, then type var. Difference is that c performs two operations at once - it deletes text and stays in Insert Mode after that.
...
16
votes
Accepted
Visual Block Mode edit with sequential number
Depending on your usecase the following might be useful:
Create the entries all with the number "1":
- "1"
- "1"
- "1"
- "1"
Then go to the second "1" and press V to start line-wise visual. Then ...
14
votes
Accepted
Add constant integer to visually selected numbers
Visually select all the lines you want to increment, and do the following:
:s/\d\+/\=submatch(0) + 132
Does exactly what you describe. Visually selects a bunch of numbers, and adds a mathematical ...
14
votes
How do you change the last n characters for a range of lines?
Building on @statox's answer,
:'<,'>s/\v.{3}$/foo/
\v very magic option, see :h \v for more info
.{3}$ last 3 characters of line
foo desired replacement string
13
votes
Accepted
How do you change the last n characters for a range of lines?
It would not work all the time, but maybe you could temporarily right-align the right border of the code.
Suppose you have the following code containing 3 lines, each with the same level of ...
13
votes
Accepted
How to paste visual block starting with another line
When you copy some text, it goes into a register. The text inside a register has a type: characterwise, linewise or blockwise.
This type determines in which way the text will be put.
In your example,...
12
votes
Accepted
How can I add text to the end of words on each line?
You can also use
:%s/\w\+/`&`
to convert from
Lorem
ipsum
dolor
sit
amet
to
`Lorem`
`ipsum`
`dolor`
`sit`
`amet`
:% range to the next command (whole buffer)
s is a substitute command :s/...
10
votes
How do you change the last n characters for a range of lines?
EDIT Here is a better solution than the one I gave previously:
'<,'>g/.*/norm! $4hCfoo
'<,'> apply the command to the visual selection
g/.*/ apply the global command on all the lines (of ...
10
votes
Accepted
Add a block of text to end of lines
While doing yank/put while iterating through the rows works fine this can actually be done with a single yank/put thanks to blockwise Visual mode. That is the mode you enter by hitting Ctrl+V from ...
9
votes
Accepted
Visual block. Some right-end selections seem impossible
The secret is to press $ after you have expanded your block vertically:
<C-v>jj$
or to press $ before expanding your block vertically:
<C-v>$jj
Well, $ is the secret.
…which is not ...
9
votes
Add constant integer to visually selected numbers
As of Vim 7.4.754+ you can use <c-a>/<c-x> in visual mode. See :h v_CTRL-A.
However since you can not upgrade Vim you may want to look into speeddating.vim which does some visual ...
9
votes
Accepted
Sorting a column without altering other columns
I think your best hope is the vis.vim plugin. This plugin provides a command B which allows to apply a command to a block.
Here after installing the plugin, you'd select your block and then use:
:'&...
9
votes
Accepted
Visual Block Mode: How to insert text to multiple lines after line ending?
It could be done with virtualedit=ALL:
set virtualedit=all
select visually vertical part of the text
A\<ESC>
return set virtualedit=block
See the screen:
9
votes
Accepted
Replacing text with a visual block
Simply (assuming we are on the topleft v):
Ctrl-vjly (yank the block)
jj (move to start of next block)
1v (select a block the same size as our last visual selection)
p (paste)
See :help CTRL-V, ...
8
votes
Accepted
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?
Yes, this feature is there, but it's a bit hidden. From :help v:
[count]v Start Visual mode per character.
With [count] select the same number of characters or
...
8
votes
How I force [count]<C-x> to leave leading zeros?
While I'd definitely go with :s + printf for complex replacements, I can get the effect you desire if I start from 00, and have set nrformats-=octal. That is:
Select the numbers in a visual block:
...
8
votes
Accepted
Visual block yank to end of line
Maybe this?
xnoremap Y :yank<cr>
Being an ex command, :yank will automatically copy whole lines.
8
votes
Accepted
Paste a block in "replace" mode
There's :h put-Visual-mode. Just select the visual block of the same dimension to make it work as one-to-one replace: 1vp
7
votes
Accepted
Visual block editing: map i
You can use :h map-expression to determine which version of visual mode you are in, and change the behaviour accordingly. Visual mode mapping
vnoremap <expr> i mode()=~'\cv' ? 'i' : 'I'
will ...
7
votes
How can I insert text at the end of a group of lines?
First you can visually select them using V and then use the movement keys to select the entire text (or if the text were strictly a paragraph you could do [starting at the first line] V}). And then ...
7
votes
Accepted
What does <C-V>?<Space><CR> do?
You need to see this as an action (<c-v>) followed by a motion (? <CR>) which is the basis of the Vim "grammar". For example ve is an action (v visually selection) followed by a motion (e ...
7
votes
Accepted
Jump *to* end of paragraph?
vnoremap <silent>x :<C-U>call cursor(line("'}")-1,col("'>"))<CR>`<1v``
Explanation:
vnoremap <silent>x --- remap something useless in visual mode (x is the same as d)
:&...
7
votes
Accepted
Trailing characters error in a substitution command
You don't need %, as you already have another range ('<,'>) for your command s. So it must be simply '<,'>s/SomeStuff/stuff/gI.
6
votes
Accepted
How I force [count]<C-x> to leave leading zeros?
This can be done in two relatively simple steps:
Decrement the lines with ctrl-x
Run a substituion on the changed lines to add the leading zeros: '[,']s/\d\@<!\d\>/0\0/
You could turn that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
visual-block × 102visual-mode × 29
cut-copy-paste × 22
insert-mode × 8
replace × 7
key-bindings × 6
multiple-lines × 6
vimscript × 5
neovim × 5
indentation × 4
register × 4
cursor-movement × 3
selection × 3
regular-expression × 2
search × 2
command-line × 2
substitute × 2
normal-mode × 2
comments × 2
cursor × 2
count × 2
custom-text-object × 2
vimrc × 1
vim-windows × 1
microsoft-windows × 1