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 ...
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, ...
: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+"
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, :...
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 ...
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:
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 ...
Depending on your usecase the following might be useful:
Create the entries all with the number "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
See :help v_g_CTRL-A
Update: What if ...
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 ...
The secret is to press $ after you have expanded your block vertically:
or to press $ before expanding your block vertically:
Well, $ is the secret.
…which is not that surprising, after all.
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:
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 (...
On first line just type:
4 and : create a range for you and then norm A. adds the dot to each line
Another solution for longer paragraphs could be:
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 ...
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 ...
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:
Otherwise you need to use a macro or use visual mode and then use :...
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 ...
You can do it like this:
select the lines you want to rotate (with V or <C-v>)
type <C-w> to get rid of the '<,'> that appeared after the :
type '> move '<-1, or the short version '>m'<-
The move command accepts a range to move and an address to where the content should be moved (see :...
EDIT Here is a better solution than the one I gave previously:
'<,'> 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
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
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 '&...
One (*) secret is:
... 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.
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.
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 ...
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 (...
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.
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 ...
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).
<c-v> starts a block selection from the cursor position to the next motion
? starts a backward search
is your search ...
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 "&...