jumps and marks in vim

2010-07-11 603 words 3 mins read

First we will talk about jumps in vim. Very useful for <a class="zem_slink freebase/en/navigation" title="Navigation" rel="wikipedia" href="http://en.wikipedia.org/wiki/Navigation">navigation and jumping around the vim. The jumps are commands that lets you jump from one location to another location, like {{ or [[ and so on … From the help file of vim

A &#8221;jump&#8221; is one of the following commands: &#8221;&#8217;&#8221;, &#8221;`&#8221;, &#8221;G&#8221;, &#8221;/&#8221;, &#8221;?&#8221;, &#8221;n&#8221;,
&#8221;N&#8221;, &#8221;%&#8221;, &#8221;(&#8221;, &#8221;)&#8221;, &#8221;[[&#8221;, &#8221;]]&#8221;, &#8221;{&#8221;, &#8221;}&#8221;, &#8221;:s&#8221;, &#8221;:tag&#8221;, &#8221;L&#8221;, &#8221;M&#8221;, &#8221;H&#8221; and
the commands that start editing a new file.  If you make the <a class="zem_slink freebase/en/cursor" title="Cursor (computers)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cursor_%28computers%29">cursor &#8221;jump&#8221;
with one of these commands, the position of the cursor before the jump is
remembered.  You can return to that position with the &#8221;&#8217;&#8217;&#8221; and &#8221;“&#8221; command,
unless the line containing that position was changed or deleted.

Now what good is a remembered if you cannot go to that location directly with a <a class="zem_slink freebase/en/keyboard_shortcut" title="Keyboard shortcut" rel="wikipedia" href="http://en.wikipedia.org/wiki/Keyboard_shortcut">shortcut. Correct, shortcuts and lists of the commands are important and the developers of the best <a class="zem_slink freebase/en/editing" title="Editing" rel="wikipedia" href="http://en.wikipedia.org/wiki/Editing">editor did not forget that (Note that you need the jumplist feature for this):

CTRL-O                  Go to [count] Older cursor position in jump list(not a motion command).
CTRL-I                  Go to [count] newer cursor position in jump list(not a motion command).In a |quickfix-window| it takes you to the position ofthe error under the cursor.

:ju[mps]                Print the jump list (not a motion command).

You can read more about jumps in the editor itself with &#8221;:help jump&#8221;

Now lets talk about marks. Marks can be assumed to be named jumps in most simple form. And adding a mark is also very simple

press m<any character/number>

m{a-zA-Z}               Set mark {a-zA-Z} at cursor position (does not move the cursor, this is not a motion command).m&#8217;  or  m`              Set the previous context mark.  This can be jumped to with the &#8221;&#8217;&#8217;&#8221; or &#8221;“&#8221; command (does not move the cursor, this is not a motion command).
m[  or  m]              Set the |'[| or |&#8217;]| mark.  Useful when an operator is to be simulated by multiple commands.  (does not move the cursor, this is not a motion command).

and jumping to a mark can be done in two ways:

  1. With ` (backtick):     The cursor is positioned at the specified locationand the motion is |exclusive|.
  2. With &#8217; (<a class="zem_slink freebase/en/quotation_mark" title="Quotation mark" rel="wikipedia" href="http://en.wikipedia.org/wiki/Quotation_mark">single quote): The cursor is positioned on the first non-blank character in the line of the specified location and the motion is linewise.

To list all the marks you can use the command marks as so:

:marks {arg}            List the marks that are mentioned in {arg}

*:delm* *:delmarks*
:delm[arks] {marks}     Delete the specified marks.  Marks that can be deleted include A-Z and 0-9.  You cannot delete the &#8217; mark.

There are three classification of the marks based on how they can be used or defined :

&#8217;a – &#8217;z         lowercase marks, valid within one file
&#8217;A – &#8217;Z         uppercase marks, also called file marks, valid between files
&#8217;0 – &#8217;9         numbered marks, set from .viminfo file

You can read more about marks in <a class="zem_slink freebase/en/vi" title="Vi" rel="wikipedia" href="http://en.wikipedia.org/wiki/Vi">vi editor with &#8221;:help marks&#8221;

You can get some info at the below link also:

<a href="http://www.linux.com/archive/articles/54159">http://www.linux.com/archive/articles/54159<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://www.consumingexperience.com/2010/01/notepad-save-non-txt-files-without-txt.html">Notepad: save non-TXT files without .txt ending e.g. html files (consumingexperience.com) <li class="zemanta-article-ul-li"><a href="http://www.slideshare.net/maurene19/creating-a-hyperlink-2803127">creating a hyperlink (slideshare.net) <li class="zemanta-article-ul-li"><a href="http://blogs.adobe.com/jkost/2009/12/multiple_clone_source_points.html">Multiple Clone Source Points (blogs.adobe.com) <li class="zemanta-article-ul-li"><a href="http://www.slideshare.net/guestc6bfc6/locating-and-opening-an-existing-documentpptx-maras-presentation-2780294">Locating And Opening An Existing Document.Pptx Mara&#8217;s Presentation (slideshare.net) <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/58b833d8-7ce6-48ea-8b05-2cf1264edd8a/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b41.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it