40

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. Insert desired text. <Esc> - Exit insert mode and finish block append. When compared to writing :norm after selection there are even less key presses, ...


19

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]} – Move [count] paragraphs forward. You can use <S-v>} to select all lines from the current line to the next blank line. This will include the blank line, so ...


18

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 step is to select the paragraph with Vip then you change to visual block mode and move the cursor to the end of each line with $ then you add the . to each ...


17

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 do it from insert mode as well: Ctrl-r+"


14

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


14

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 constant to each of them. If you leave of the /g flag, it will only increment the first number on each line. This uses the "expression register". To learn more, :...


14

A shortcut for next empty line is }. So you just might want to use SHIFT+v}


13

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 command called "Vb". The ! after command means that vim will not throw an error if the command is already defined. normal! <C-v> - This command tells vim ...


13

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. As for why Vim is not including va - simply it's outside of the visually selected block. I couldn't find anything about that in the :help, but I think Vim is ...


12

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 indentation (8): here is foo here will be foo here was foo And you want to change foo with bar. You could use the following commands: vip ...


12

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 move down to the last "1". So now all but the first "1" is selected. Now hit gCtrl-a and you get - "1" - "2" - "3" - "4" See :help v_g_CTRL-A Update: What if ...


11

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, you copied some text from visual block mode. So, the text had the type blockwise and was stored in the unnamed register ". Because of this type, when you will ...


11

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: :'<,'> ├┘ ├┘ │ └ mark put automatically on the last line of the visual selection └ mark put automatically on the first line of the visual selection (see `:h '&...


10

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 the visual selection) norm! interpret the following string as a normal command $4hCfoo go 4 characters before the end of the line and replace them by foo EDIT ...


10

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/regexWhat/substituteValue without range will substitute on a current line. \w\+ is a regexp for a word & is a whole value of what has been matched with regexpWhat, ...


9

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! VisualBlock execute "normal! \<C-v>" You can change the names of these commands to whatever you want, but all user-defined commands must start with an ...


9

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 that surprising, after all.


9

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 incrementing. There are other plugins that might work as well: visualinc visual-increment.vim Otherwise you need to use a macro or use visual mode and then use :...


9

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: :'<,'>B !sort Note that the command can be anything, so instead of !sort you could do a lot of other processing on the block like saving it to another file (...


8

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: Note that I have added mov76.webm - you don't actually have ten files in your example list. Replace with zeros and select the same region again: r0gv Use g<c-...


8

Maybe this? xnoremap Y :yank<cr> Being an ex command, :yank will automatically copy whole lines.


8

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 lines as used for the last Visual operation, but at the current cursor position, multiplied by [count]. So, if you specify a ...


7

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 make i act as i in visual and linewise-visual modes, and as I otherwise, i.e. in blockwise visual mode.


7

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 short version '>m'<- press <Enter> Explanation The move command accepts a range to move and an address to where the content should be moved (see :...


7

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 type :. This should bring up something like :'<,'> in the command-line. :'<'>normal A. This executes normal A. on the selected lines. normal A. ...


7

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 Normal mode. Since OP is flexible on the format and because some of this is probably new for a lot of folks I'll show a couple methods for joining the text using ...


7

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) :<C-U> --- drop visual line range (also switches to normal mode) call cursor(...)<CR> --- set cursor position line("'}")-1 --- the last line of the ...


7

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


6

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 into a command/function if you think you'll need to do this often. Another way is to do as muru mentioned and use substitute + printf, which can preserve the ...


6

One (*) secret is: set virtualedit=block ... in your vimrc :) (:h virtualedit will explain everything). A disadvantage of this method: when yanking, you get trailing spaces on the shorter lines. (*) The other is in the answer provided by @romainl. BTW, for the secret of the golden rivet, see this instead.


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