Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
48 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. ...
user avatar
  • 1,532
21 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]} – ...
user avatar
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 ...
user avatar
  • 681
17 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 ...
user avatar
  • 6,370
15 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: :'<,'&...
user avatar
  • 5,457
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 ...
user avatar
  • 16.5k
14 votes
Accepted

Is there a command to enter Visual Block mode?

There is no built in command to start visual block mode in vim, but you can define one yourself: command! Vb normal! <C-v> Here is a breakdown of how it works: command! Vb - This creates a ...
user avatar
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
user avatar
  • 1,041
14 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}
user avatar
  • 243
14 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. ...
user avatar
  • 4,208
14 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 ...
user avatar
  • 8,520
12 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 ...
user avatar
  • 5,868
11 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,...
user avatar
  • 5,868
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 ...
user avatar
  • 45.9k
10 votes

Is there a command to enter Visual Block mode?

As far as I can find, there is no built-in command to start visual mode. However, you can easily add these commands to Vim: :command! Visual normal! v :command! VisualLine normal! V :command! ...
user avatar
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 ...
user avatar
  • 18.2k
10 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/...
user avatar
  • 9,783
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 ...
user avatar
  • 32.6k
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 ...
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: :'&...
user avatar
  • 45.9k
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: ...
user avatar
  • 23.7k
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.
user avatar
  • 9,260
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 ...
user avatar
  • 16.6k
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 ...
user avatar
7 votes

Vertically rotate visual block

You can do it like this: select the lines you want to rotate (with V or <C-v>) type : type <C-w> to get rid of the '<,'> that appeared after the : type '> move '<-1, or the ...
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 ...
user avatar
  • 333
7 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:
user avatar
  • 9,783
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) :&...
user avatar
  • 15.5k
7 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
user avatar
  • 15.5k
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 ...
user avatar
  • 6,320

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