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, ...
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 ...
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 ...
: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, :...
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 ...
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:
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 ...
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 ...
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 '&...
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
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 ...
You can also use
to convert from
:% 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, ...
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.
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 :...
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 (...
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
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 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.
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 :...
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.
This executes normal A. on the selected lines. normal A. ...
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 ...
vnoremap <silent>x :<C-U>call cursor(line("'}")-1,col("'>"))<CR>`<1v``
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 ...
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 ...
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.