How do you use markers in vi?

I just discovered the existence of markers in vi. How do you use it, what do you know about them? are they useful, say, for a c ++ developer?

+5
source share
4 answers

I use them all the time for:

  • Commenting on blocks of code
  • copying and moving blocks of code,
  • yanking and removing blocks of code in named buffers and
  • Edit: replacing the testing unit.

A comment:

  • go to the first line of code you want to comment,
  • mark it, for example. enterma
  • go to end of block
  • enter :'a,.s/^/#(or any other comment character you need)

Copy and move:

  • , ,
  • , /.
  • , . mb
  • , , :'a,'bco . :'a,'bmo . .

:

  • , ,
  • , .
  • enter :'a,.ya a a :'a,.ya a a

: :

  • , ,
  • ,
  • :'a,.s/search_string/replace_string/[gc], . "g" "c" .

: , , 'a ( a) , , `a ( a) , .

So `ad`b (bactic-ad-backtic-b) - char, 'a', char char, b.

, Vim :reg , . .

+11

, . , , , , , .

, , , , .

, , ( ) , ++.

- , .

+3

- . , mx , y'x, ( ) d'x, () . p p , .

+2
.

, . :

int tmp = 0;
while (tmp < 10)
{
    doIt(tmp); /* cursor before d */
    /* ... */
    finishIt(tmp);
    tmp++
}

If I want to extract from doIt(tmp)in finishIt(tmp), I would set the marker in the cursor (for example ma), go to the end, and then delete to mark a with d'a.

+1
source

All Articles