18

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 ...


12

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 ...


12

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+"


12

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


12

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


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 ...


10

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 ...


10

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, :...


10

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, ...


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

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 (...


9

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 ...


8

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 ...


8

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 :...


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 ...


8

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 ...


8

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 ...


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

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 ...


7

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-...


7

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


7

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 '&...


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.


6

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.


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

Here's a simple mapping to do the task: vnoremap <silent> rs "zy:call setreg("z", system("echo \"" . @z . "\" \| sed 's/[ \\t]\\+//' \| rs -j 0 1"), "b")<CR>gv"zp It uses z register to keep output of it's intermediate steps. I had to add call to sed to remove trailing white chars from the input to rs, because rs would produce strange output (...


6

For context I'll go over the whole thing. First I'll describe the operations generally and then how they apply to the golf problem specifically. General Description: dj : Delete with 'one line down motion' (delete current and following line) gJ : Join current and next line, adding no extra spaces . : Repeat the join V : Line-wise visual selection of the ...


6

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 until the end of the word). Here <c-v> starts a block selection from the cursor position to the next motion ? starts a backward search is your search ...


5

It doesn't work because using a text-object switches to visual-line mode. Do: vip<C-v> instead of <C-v>ip See :help ip.


5

No, you can only do rectangular selections with visual-block mode. Beside substitution, there are basically two ways to do what you want without third party plugins: direct repetition of normal mode commands and macros. Repeating normal mode commands Do your edit in one place and repeat it in the other places: /"<<CR> search for "&...


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