Square Brackets Motion in Markdown and LaTeX in Vim environment

Foreword on Markdown, LaTeX and Vim

Markdown and LaTeX are awesome markup languages, expecially when you use them in creating and developing structured texts.

I assume that the reader already has at least a bit knowledge of them.

A structured text is a text subdivided into chapters, sections, or subsections, etc.

The more complex the text, the more those two languages are useful.

At the same time Vim is an excellent integrated environment for writing in Markdown and LaTeX, available in almost every operating system.

One of Vim most useful features is its ability to quickly jump through the sections of structured texts.

Square brackets can be very useful for Vim jumping through the sections of structured texts.

But be careful: the same combinations of square brackets can have different effects in Markdown and LaTeX for Vim.

Here is a brief comparative overview of the square brackets jumping movements in Markdown and LaTeX in a Vim (and GVim) environment.

Square brackets motion in Vim-Markdown

If you install and use the plasticboy/vim-markdown plugin you have the ability to move through the levels via square brackets.

According to the original README.md document you have the following square brackets motions:

  1. If you digit ]] you jump to next header.
  2. If you digit [[ you jump to previous header.
  3. If you digit ][ you jump to next sibling header (if any).
  4. If you digit [] you jump to previous sibling header (if any).

Ad example could be very useful.
Let’s assume we have the followin Markdown code fragment:

If your cursor is in the Section First level and you digit ]] you jump to the Subsection First level. Another ]] and you jump to the Section Two level and, after, to the Subsection Two one.

Then every time you use the parallel square brackets in Markdown for Vim you cicle through all levels, regardless of what height it is.

Instead, if you cursor is in the Section First level and you digit ][ you jump directly to Section Two that’s at the same level and skip the Subsection First level.

The opposite brackets make you jump to sections of the same higher level.

Obviously, the combinations ]] and [] have the exact opposite effect to the one described above.

Square brackets motion in LaTeX (using Vimtex plugin)

In the Vimtex plugin, dedicated to LaTeX writing in Vim, the use of the parallel square brackets has the same effect as the one already described above in Vim Markdown.

But when you use the opposite square brackets (][ and []) you jump to the section boundaries and not to the same level sections.

Another example could be useful.
Let’s assume we have the followin LaTeX code fragment.

  1. If you digit ][ in the First Section you jump to the blank line above the First SubSection.
  2. If you digit [] in the Second Section you go the above blank line of the same section.
  3. If you digit [] in the blank line above the Second SubSection you jump to the blank line above the Second Section.
    … and so on.

Pay attention: you have to leave empty lines around the section tags for the optimal functioning of the motion system in this case.

Different purposes

The different effects described above reveal distinct purposes of the two writing environments.

In Markdown for Vim the aim is to jump selectively through the different height levels of a document.

In Vimtex (LaTeX) for Vim the purpose is to quickly jump to the editing point near the edge of the sections so you can immediately begin to write under the existing sentences.

Thank You for Your attention.

Comments

Popular posts from this blog

Vim: Cut, Copy and Paste to and from the system clipboard

Vim: searching for text containing a slash or a question mark