56 votes
Accepted

How can I view and edit my recording (i.e. recorded macro)?

Note: I'm assuming you're using the a register for the entirety of this answer, but you can use any register Note2: <1b> is Esc; you can insert this with Ctrl+v and then Esc. It may also show ...
user avatar
28 votes
Accepted

Execute normal command over range

You can do this with the normal command : :1,10normal d2w This is because the d operator doesn't accept a range, but only a motion : :h d ["x]d{motion} Delete text that {motion} moves ...
user avatar
  • 15.2k
23 votes
Accepted

How to replace more than one character without entering insert mode

If the new text is the same length as the old text, Vim's replace mode is an option. From normal mode, R (that's a capital "r") brings you into replace mode. This is similar to "overwrite" in some ...
user avatar
  • 1,326
19 votes

Delete n lines skip 1 line script

Very simple approach: Move to the first line you want to delete. Record a macro: qa3ddjq Repeat it with a high number: 1000@a Step three will repeat the macro a thousand times or until an error is ...
user avatar
  • 8,675
18 votes
Accepted

How to copy first four characters of every line to the end of that same line?

:% s/\v^(\d{4})(.*)$/\1\2 \1/ is one way to do it \v magic option, to avoid having to escape grouping () ^ start of line \d{4} match exactly four digits .* rest of line \1 \2 has the matched ...
user avatar
  • 1,066
17 votes

Delete n lines skip 1 line script

The easiest solution to me would be: :%norm j3dd That is: %: for every line norm: run the following keys as if in normal mode j3dd: go down on line then delete 3 lines So from the first line, go ...
user avatar
  • 346
16 votes

How can I view and edit my recording (i.e. recorded macro)?

To get something to work with... qajjjq Will start record a macro into the a register. You can see many of your current registers (used for macros, yanking, deleting, etc.) with the :reg command, ...
user avatar
12 votes

Can I repeat the last UI command?

The dot command . works because Vim "keeps track" of commands that change the contents of buffers. If you run :echo b:changedtick, you'll see it incrementing with each change to the current buffer. ...
user avatar
  • 3,618
12 votes
Accepted

repeat insert at beginning of line

Just use uppercase I instead of lowercase i The i and a Insert mode commands have uppercase versions I (insert at beginning of line) and A (append at end of line) So, if you use I##<Esc>, you ...
user avatar
  • 1,066
12 votes
Accepted

How can I insert a character repeatedly until even with next line?

Short answer v $ r * :help v_r Longer answer y y p / P     Duplicate line to below/above 2 l                    Move to position from where to overwrite (in this case 3rd column ← 2 to ...
user avatar
11 votes

How to copy first four characters of every line to the end of that same line?

And a solution with a macro: qqyiwA <Esc>pj0q Which means: qq Record the macro in the register q yiw Yank the text described by the text object iw (inner word): The date A <Esc> ...
user avatar
  • 46.5k
11 votes

Replace . with -> in specific places

You could use the s operator, which deletes the character under your cursor and puts you in insert mode. You can then type the replacement and later use . to repeat the whole replacement. Workflow ...
user avatar
  • 7,466
11 votes

Repeat motion easily

Since you mentioned cursor movement but not ; there is of course ; Repeat latest f, t, F or T [count] times. , Repeat latest f, t, F or T in opposite direction [count] times. This is very ...
user avatar
  • 2,673
11 votes
Accepted

Repeat last yank

If you include the flag y in the cpoptions option; set cpoptions+=y then yanks may be repeated using .. See :help cpo-y: *cpo-y* y A yank command can be redone ...
user avatar
  • 12.8k
10 votes
Accepted

How to repeat last action with movement?

From the repeat documentation : . Repeat last change, with count replaced with [count]. Also repeat a yank command, when the 'y' flag is included in 'cpoptions'. ...
user avatar
  • 1,490
10 votes
Accepted

Understanding line reference differences through :g/^/norm and through :%norm

Well, % is shorthand for 1,$ (a range from the first line to the last). From :he :%: Line numbers may be specified with: :range E14 {address} {number} an absolute line ...
user avatar
  • 23.9k
9 votes

Can I repeat the last UI command?

There is no way of doing this by default in vim because vim does not keep track of the previously executed wincmd. However, it is possible to do this through some clever mappings: function! s:Wincmd(...
user avatar
9 votes

How can I add a prefix to a few lines?

What I do to achieve this is to make a visual rectangular selection with Ctrl-V at the place where I want to add the prefix, and once all lines are selected, just press I (that's a capital i) and type ...
user avatar
  • 2,251
8 votes
Accepted

Repeat replace one character (r) for next occurence

Well, <Shift>v:s/"/'/<Enter> is certainly less efficient than :s/"/'<CR>. Here are various ways to perform the same task: f" jump to next " r' replace it with a ...
user avatar
  • 33.1k
8 votes
Accepted

Replace . with -> in specific places

The cw(change word) command will solve your problem. Put your cursor on the period and type cw-><Escape> something.somethingelse turns into something->somethingelse and the . ...
user avatar
7 votes
Accepted

How can I repeat last Ex-mode command in normal mode?

Use the /c flag at the end of your substitution in order to confirm each substitution: :%s/foo/bar/gc See :help s_flags. Use & to repeat the last substitution without the flags. See :help &....
user avatar
  • 33.1k
7 votes

repeat insert at beginning of line

Just hit the enter key. It will take you to the start of the next line.
user avatar
  • 1,193
7 votes

How to insert repetitive text with minor difference in vim?

You can use the following function: function! GenerateLines() let firstpart="similar text part 1" let secondpart="similar text part 2" let words=["wordA","wordB","wordC","wordD","wordE"] ...
user avatar
  • 46.5k
7 votes

Replace . with -> in specific places

I recommande using the substitute command: :%s/\./->/gc This will: :%s substitute over all lines /\. match dot /-> replace by arrow /g replace all on lines c ask for ...
user avatar
  • 15.2k
7 votes

Replace . with -> in specific places

If you don't want to use a substitution or the dot command as suggested by the other answers your best bet is probably to create a macro which you can use when your cursor is next to a dot. You can ...
user avatar
  • 46.5k
6 votes
Accepted

Is it possible to make a numerically-prefixed hotkey run a function that many times?

By default vim treats all functions as if they are default ex commands, i.e. any prefixed numbers are used as {range}. To change this you need to modify your function and your map to use a count. Map ...
user avatar
  • 2,510
6 votes
Accepted

Delete multiple lines by address

The bar | command can be used to separate multiple commands in a single command statement. Your example could be written as :1d|4d|32d http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:\bar
user avatar
  • 226
6 votes
Accepted

Is there a way to encapsulate a variable with a method with a repeatable action?

If you already have the surround plugin, you can do ysiwfverify<CR>. Tim Pope has another plugin called repeat that lets you repeat surround commands with .. Without any plugin or setup, you ...
user avatar
  • 33.1k
6 votes

How to copy first four characters of every line to the end of that same line?

Here is the way that I would do it: :%norm y4lA <C-o>p Explanation: :%norm "Apply the following keystrokes to every line: y4l "Yank 4 letters. You ...
user avatar
  • 16.8k
6 votes

Is there a way to repeat the pænultimate (or older) change?

No, this is not possible. After some searching on the web, it appears other people have asked about this very feature before on other stack exchange sites: Repeat the nth last command in vim And ...
user avatar
  • 16.8k

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