Posts

Vim, VimTex: environments and commands in LaTeX

Image
Vim, LaTeX and VimTex: surround commands Table of Contents 1. A smart system for writing 2. VimTex Built-in functions for environments and commands 3. Create a surround function in VimTex based upon surround.vim plugin 1. A smart system for writing Vim is a great editing tool. LaTeX is a "State of the Art" typesetting system. Vim and LaTeX together make a powerful writing system, but an add-on is needed to relate them. VimTex provides exactly that target by relating Vim to LaTeX, and it does its job very well. So Vim and VimTex is a smart system for every kind of writer in LaTeX. The topic is vast and certainly cannot be contained in a short post like this one. In this article, I simply cover functions for managing environments and commands. 2. VimTex Built-in functions for environments and commands I assume that those who use LaTeX already know the difference between commands and environments. VimTeX ha...

Vim Is Magic or Nomagic?

Image
What’s this joke? The title is a joke with the name of “ V.I.M. ” but, at the same time, it’s a real mode of Vim itself: the Magic Mode . To understand what Magic Mode is, the primary source is the item :help magic in Vim. In a few words: - The Magic Mode refers to the regular expressions - The Magic Mode is enabled by default in Vim. - You can explicitly invoke the Magic Mode with the \m command in the RegEx search area. - To deactivate it you must set \M (capitalized m ) in the RegEx search area. - When you use the \M command you invoke the Nomagic Mode . - Nomagic Mode turns “ almost all special regex symbols into ordinary ones unless they start with a backslash ”. - There is also a Very Nomagic Mode that extends the effect to other characters, not relevant to this article. When is magic mode (default) better than nomagic? To analyze the difference between magic and nomagic mode, I resume a formula from a previous article of mine . It’s the Vim RegEx formula for...

Markdown in Firefox

Image
Abstract Use Mozilla Firefox as a Markdown documents viewer written on Linux Ubuntu, Fedora and Arch, with mention of MS Windows and macOS. Mozilla Firefox and the Markdown layout Mozilla Firefox, one of the best Internet browsers, does not natively read documents written in Markdown. If you try to open a document written in Markdown, the browser asks whether it should save it locally or open it with an application among those offered by the operating system. But it doesn’t render the document. It is necessary, therefore, to use an add-on plugin to view a Markdown document in rendered mode within the navigator. An excellent plugin is Markdown Viewer Webext . In addition to displaying content written in Markdown, the component makes available a pop-up table of contents that also allows you to choose the style ( default and github ) and download the HTML version of the document locally. I did, however, have some problems to install the component under GNU/Linux, especially on...

Vim, UltiSnips and Honza vim-snippets: difference and management of the snippets and UltiSnips folders

Image
What is the subject of this article? In this article I will talk about Vim, snippets powered by SirVer UltiSnip : “ the ultimate solution for snippets in Vim ” and Honza vim-snippets (hereafter also simply referred as “honza”). For some more information you can refer to this previous article of mine . SirVer UltiSnip is a plugin to launch and manage snippets in Vim. The application does not contain snippets but you can create your own by following the plugin syntax or use a collection of ready-made snippets. Honza vim-snippets contains an extensive collection of snippets for various languages. In fact into the Honza GitHub repository you’ll find two separate collections of snippets for the same languages. What’s the difference about them? This is the argument we are going to talk about in this article. All operations were performed on a computer running the GNU/Linux operating system. Honza and the snippets collections In the Honza vim-snippets GitHub repository you will...

Vim: study on transposing lists of names from horizontal to vertical

Image
Primary purpose of the study. Initial status : series of inline names, separated by a semicolon followed by a space. Objective : Transpose all names into one column by removing both semicolons and spaces. Purpose : Creating list for mail-merging with e-mail client ( Thunderbird ). Tools : Vim and built-in RegEx function. Example : From: One@mail; Two@mail; Three@mail; ... To: One@mail Two@mail Three@mail ... Secondary goal To test the integration between Markdown and css tags. This objective was accomplished in the Example above by inserting the following code: <p style = "text-align: center; font-weight: bold;" > Da: </p> <pre> One@mail; Two@mail; Three@mail; ... </pre> <p style = "text-align: center; font-weight: bold;" > A: </p> <pre> One@mail Two@mail Three@mail ... </pre> Vim: regular expression for the primary target To obtain the transposition from horizontal to vertica...

Vim: replace text in all opened buffers with only one command

Image
Vim: do you need to replace some text in all opened buffers? Do You need to perform a substitution between two words or text fragments in all opened buffers? The first option is to open all the buffers and perform a search with substitution in each of them. The search and replace string will look like the one below, where foo will be the data element to be replaced and bar will be the replaced data element. %s/foo/bar/g The letter g at the end of the string determines the g lobal substitution avoiding the acceptance for each replaced element. Vim: is it possible to perform the operation with a single command? The one previously illustrated is already a good system, but you can do better: you can replace all items in all documents opened in Vim with a single command . The command is as follows: :bufdo %s/foo/bar/g | w Basically, the bufdo command extends the operation to all open buffers. The name itself is mnemonic from: buffer do , meaning to do in every buffer . The...

Comparison of Vim and Emacs for a substitution operation using regular expressions

Image
Preface This article is a summary of two previous posts that you can read at these pages: “Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command” “Emacs: Study on constructing Regular Expressions to delete or reduce blank lines” The topic of “regular expressions” in Vim and Emacs is well suited for a functional comparison across the four different scenarios covered in the above articles to which I refer for a description of the syntax. Comparation Table Target Vim Emacs Delete “pure” blank lines :g/^$/d M-x flush-lines <RET> ^$ <RET> Delete blank lines with whitespace :g/^\s*$/d M-x flush-lines <RET> ^\s-*$ <RET> Reduce “pure” blank lines :g/^$\n^$/d M-x query-replace-regexp <RET> ^C-qC-j\{2,\} <RET> C-qC-j <RET> Reduce blank lines with whitespace g/^\s*$\n^\s*$/d ^\(^C-q<SPC>*C-qC-j\)\{2,\} <RET> C-qC-j <RET> Emacs: what you type is n...

Emacs: Study on constructing Regular Expressions to delete or reduce blank lines

Image
After writing an article focusing on “Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command” I tried to match with a similar operation with Emacs. The goal is to study the differences in syntax related to “regular expressions” between two writing systems. The following is the result of my attempts after various searches on the net. Removing blank lines in Emacs using RegExp First of all, it may be useful to display the blank lines in the document. To preview blank lines, you can use the whitespace-mode function ( M-x whitespace-mode <RET> ): blank lines will be marked with dollar signs, i.e., lines in which there is no character, not even white space. At this point you can select a region or operate on the entire document from the cursor point with the flush-lines function, or the alias delete-matching-lines , to remove lines that match a search command: M-x flush-lines <RET> ^$ <RET> The formula’s meaning is a...

Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command

Image
Preface On the topic of this article you may find interesting the following one: “Vim and Regular Expressions for removing redundant whitespace” . Unlike the previous article, here the presence of whitespace causes different solutions than blank lines regardless of the number of their occurrences. The study in this article is focused on both the analysis of “ regular expressions ” and Vim’s global command. Vim and the Global Command The Global Command in Vim is the g key. It’s useful for a lot of purposes. In Normal Mode it can be used to compose multi-letter commands, such as the following ones: guw : lower case next word gUw : upper case next word gU2w : upper case next two word gUe : upper case until the end of the word gu$ : lower case until the end of the line ge : move to the end of the previous word (simple e moves to the end of the next word) … and so on. The g Command can also be a motion operator , as described in this article of mine . The same global ...

What is intended by "line" in Vim? How to configure a dual alternate mode of movement between lines.

Image
Why is the Vim line definition “special”? In Vim a “line” is a set of characters that ends with a return line. Is that all? It seems obvious, but how does it differ from the definition of “line” in other writing systems? Simple: in other environments usually “lines” break at the right margin of the monitor. In Vim they don’t. Nothing changes for short lines, that is, lines that do not exceed the margin right margin. It changes, however, in the case of long lines that exceed that edge. For Vim, therefore, the line object can be, in monitor, displayed on multiple visual lines. Movement between lines in Vim? In the default configuration of Vim, vertical moves occur using the keys corresponding to the letters j and k or with the arrow keys and take effect on entire lines, as defined above. Vertical moves between lines exceeding the edge of the monitor, however, require the letter g before j and k motion operators: thus gj or gk . The rule also applies to operations o...

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 ...