0

I'm new at vim, started to play with macroses, and founded not obvious override behaviour for jump/change lists. The main question - are there any stable ways to jump by changes/moves inside same line (except marking each point), cause this lists remember only last change on the same line (if changes are consequtive withing on line).

Example for jumplist. Cursor position at '(', '{' - marked as m.

( smth ) { } %`m%

I jumped firt to ')', next by mark at the same line and next to last bracket I'm able to do only one ^o - last jump at first line. But expected to jump 2 times more.

Same situation with changes list and g; 't1 t2 t3' -> 't2 t3 t4', I can't move between all 3 t

At least I wanted to jump by same points as stored at undo history. All modern editors like VSCode, Sublime, e.t.c. have this stable option "Alt -" / "Alt +" to jump all prev. cursor positions. What is Vim way?

Founded this when tried to make macro, which swaps any 2 pair of brackets.

{ smth } (
)

Let's mark first pair of brackets with 'mm', to remember whith whom should we swap. let's mark '{' as main bracket and go to '(', starting macro 'qq'. I'm marking current pair of brackets as 'mc' and swapping later between main and current.

@q=mc%x`m%Plx^O^Op`mx`cPlx`mP

( smth ) {
}

moving cursor to { and running '@q' - we get initial text, double swapping brackets

Problems started, case second pair brackets marked as mm, and cursor located at first pair of brackets. '(' - mm, '{' - start position

{ smth } (
)

only first ^o would work, and then macro will jump outside of this block

1 Answer 1

1

There are two rules: "small" moves are never remembered; and, "changes" are remembered upon leaving from insert mode.

So all those macros and stuff they are sort of "batch processing tools", not "usual line editing tools".

Instead, to get t2 t3 t4 from t1 t2 t3 you could do ctrl-a w . w . Or to swap the brackets with d%%p. And so on.

This sort of "small edits" should be done by normals in Vim. So you need to master the normals first. Maybe reading the "Practical Vim" by Drew Neil could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.