tags:

views:

378

answers:

4

I am practising '[ and '], and I cannot see the difference.

How can you highlight the positions of the marks?

+2  A: 

Your problem may be that the previously changed or yanked text was all on one line. If you use ' with a mark it just takes you to the line, not to the exact character. Use ` instead to get the exact character.

One way to temporarily highlight the region would be to type this:

`[v`]

This will jump to the start change/yank mark, start a visual block and then jump to the end change/yank mark.

Laurence Gonsalves
A: 

Normally you can "blink" the matching delimiter ([{}]) ... using the % (percent sign) command in vi.

(That's not even unique to vim ... it works in other versions of vi as well).

The '[ and '] (single quote, square brackets) are unique to vim as far as I know. They move to the first non-blank character on the first or last line where most recently modified or "put" any text. If your most recent change only only affected a single line then the commands would both move to the same place (as you described).

Note that the ' command (in normal vi as well as vim) is a movement. 'letter (single quote followed by any lower case letter) is a command to move to the locate where a mark was most recently set (using the m command, of course). '' (repeating the single quote command twice) moves to "most recent" cursor location (think of there being a implicit mark there). That's the most recent location from which you initiated a movement or made a change ('[ and '] are ONLY about where you made changes).

For example if I'm on line 100 and I use n to search for the next occurrence of my current search pattern, then '' will get me back to line 100. From there if I type '' again then it will toggle me back to whatever the search (n) command found.
Personally I never use '[ and '] ... I drop a mark using ma (or b, or c or whatever) and then make my changes or pastes before or after the mark I've set, as appropriate.

Jim Dennis
+4  A: 

Use the showmarks plugin for VIM. It does just that.

Nathan Fellman
showmarks is wonderful.
Drew Stephens
+1  A: 

This command will show the marks:

:match Error /\%'[\|\%']/
too much php
I left a mark by `ma`. I run your command. I do not see the mark. **How does the command work?**
Masi
My command only shows the special marks '[ and '], that is all you asked for in the question.
too much php