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. ...
Vitor's user avatar
  • 1,732
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]} – ...
Martin Tournoij's user avatar
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: :'<,'&...
user938271's user avatar
  • 5,827
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 ...
mMontu's user avatar
  • 6,570
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 ...
rbernabe's user avatar
  • 751
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}
marderh's user avatar
  • 263
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. ...
grodzik's user avatar
  • 4,488
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 ...
Ralf's user avatar
  • 9,037
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 ...
DJMcMayhem's user avatar
  • 17.3k
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
Sundeep's user avatar
  • 1,076
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 ...
user9433424's user avatar
  • 6,118
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,...
user9433424's user avatar
  • 6,118
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/...
Maxim Kim's user avatar
  • 12.3k
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 ...
statox's user avatar
  • 49k
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 ...
B Layer's user avatar
  • 19.4k
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 ...
romainl's user avatar
  • 38.3k
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 ...
Peter Rincker's user avatar
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: :'&...
statox's user avatar
  • 49k
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:
Maxim Kim's user avatar
  • 12.3k
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, ...
D. Ben Knoble's user avatar
  • 24.6k
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 ...
Ingo Karkat's user avatar
  • 17.6k
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: ...
muru's user avatar
  • 24.6k
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.
VanLaser's user avatar
  • 9,600
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
Matt's user avatar
  • 20.1k
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 ...
Sakari Cajanus's user avatar
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 ...
user41805's user avatar
  • 333
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 ...
statox's user avatar
  • 49k
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) :&...
Matt's user avatar
  • 20.1k
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.
Matt's user avatar
  • 20.1k
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 ...
Tommy A's user avatar
  • 6,690

Only top scored, non community-wiki answers of a minimum length are eligible