We’re rewarding the question askers & reputations are being recalculated! Read more.
41

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 up as ^[ (depending on the display setting). It's not a mapping; so it makes sense that :map doesn't work. It's recorded in a register, and you can see & ...


19

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 encountered. Hitting end of file (hence no lines to delete) produces an error and repetition of the macro is canceled. See :help recording.


18

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 other text editors: instead of inserting new characters like in insert mode, typing will replace the character under the cursor, and then advance to the next ...


17

:% 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 pattern within () edit: @Jair Lopez mentions in comments, the regular expression can be further improved: :% s/\v^(\d{4}).*/& \1/ or the equivalent :% s/\v^(\...


17

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 down to the second one and delete the next 3 lines. The second Text I want to keep. is now on the second line. Go down one line, delete 3. Rinse and repeat. ...


14

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 over [into register x]. Alternatively you can select your text in visual mode and you can do : :'<,'>normal d2w


12

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. But Vim doesn't "keep track" of non-editing commands. Thus, no, what you're asking for can't be done.


11

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 becomes: /\. to highlight all periods. n to first dot s-> and then Esc. This will replace the dot and insert the text with a single operation. n to next dot . ...


11

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


10

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> Append a white space to the end of the line and go back to insert mode p Paste the date j0 Place your cursor on the first column of the next line (to be able ...


10

Short answer v $ r * :help v_r Longer 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 the right) v $                  Select till end of line r                          Replace all selected characters by char… *


9

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'. Does not repeat a command-line command. So, as expected, you're repeating the last change (d$). If you want to repeat your movement, use ;: ; ...


9

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, or you can specify a register to display by providing its name. For example, to show register a: :reg a yields --- Registers --- "a jjj You can append to ...


9

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 number . the current line :. $ the last line in the file :$ % ...


9

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 can use . to repeat on any other line, irrespective of where the cursor is If you want to comment bunch of lines that are together, use visual mode as ...


8

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(count, key) " If count is not zero, use the original count. If otherwise, don't " include a count. let if_count = a:count ? a:count : "" " ...


8

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 in the text. When exiting insert mode the text will be copied to all the lines. This is the sequence in images: Visual selection of the place of insertion ...


8

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 . operator will still work, because cw is one operation that does both the deletion and substitution.


7

Just hit the enter key. It will take you to the start of the next line.


7

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 ' ;. repeat jump then repeat replace ;. repeat jump then repeat replace ;. repeat jump then repeat replace ;. repeat ...


7

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 &. Use @: to repeat the last ex command.


7

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"] for word in words let line = firstpart . word . secondpart call append(line('.')+1, line) normal j endfor endfunction In the ...


7

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 confirmation This will go through all . of your file and asking each time if you want to substitute. Press y for substitute, n to go to the next dot. see :h :...


7

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 record the macro qaf.vc->^[q Which will go to the following dot on the line (f.) visually select it (v) and replace it (c->). Now when you navigate your ...


6

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 with count Maps can take a count and are made available via v:count and v:count1. The first contains 0 if no count is provided and the later contains 1 as the ...


6

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


6

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 can simply do ciwverify(<C-r><C-o>")<Esc> and repeat with ..


6

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 could also do 'yiw' A "Add a space to the end <C-o> "Do a single normal command p "...


6

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 even on the vim mailing group: History for dot operator Both of these say it is impossible. However, Bram Moolenaar (the author and maintainer of vim) is on that ...


6

You can use a macro: Once your search register is set to Subject: Bar you can empty a register (q in this example) and record the following macro: qqq qqndap@qq The first line empties the q register, the second creates a macro like this: qq start recording n go to next match dap delete the paragraph @q call the ...


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