Posts

Showing posts from July, 2022

Vim and Regular Expressions for removing redundant whitespace

Image
Introduction and structure of the article I wrote this article to practice “in situ” formula construction of Regular Expressions , also called "RegEx", in Vim. In particular, the goal is to “clean up” documents with excess whitespace at both the beginning and end of each line. A basic knowledge of Vim and the Regular Expressions built into the editor is sufficient for understanding the article. The various formulas are applied to whole documents but, since they are very normal search commands in Vim, they can be applied to individual rows or to specific ranges of rows in the context of the document. There are three formulas illustrated and the construction is progressive with “step-by-step” analysis of the syntax of Regular Expressions . The structure of the article is as follows: first I illustrate the creation of the formula for an end-of-line operation; then I move on to the reverse formula, i.e., for the same operation but at the beginning of the line; finally

Jumping between matching pairs of characters in Vim and Emacs

It is very useful to jump through corresponding pairs of characters, such as parentheses or tags, when coding or writing in a markup language such as HTML, Markdown or LaTeX. Both Vim and Emacs have dedicated commands for this purpose. To jump between matching pairs using Vim Vim uses a “single character” command to jump to the nearest pairs of corresponding characters and to place the cursor into the closing one: % . For instance: let’s assume that the cursor is placed at the beginning of the following sentence: If you want to write your own use the contents of [syntax-ppss (point)] When you press % your cursor jumps to the corresponding closing square bracket. If you press % another time the cursor jumps back to the opening corresponding square bracket. If you place the cursor everywhere inside the square brackets and press % it jumps to the closing round bracket. Naturally, if you press another time the % command the cursor jumps to the opening corresponding rou