Posts

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

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

Text documents: from PDF to vector images

Image
Subject of this article Recently I needed to convert some documents from PDF format, containing text generated by LaTeX in GNU/Linux operating systems, into vector images. While avoiding conversion from online services, I basically found three interesting solutions: two in command-line mode ( pdf2svg and pdftocairo ) and one, very famous, in graphical mode ( Inkscape ). In this article I report my evaluations highlighting some differences deriving from the source of the PDF documents and the behaviour of three Linux distributions. Some interesting references on the subject: - Exporting .png or .jpg files directly from LaTeX code. Possible? - LaTeX/Export To Other Formats pdf2svg It’s a command line software, very easy to use, reliable and fast. The followin is the command scheme: pdf2svg < in file.pdf > < out file.svg > [ < page no > ] You can specify the number of pages to be exported. Ideal for quick and direct o...

LaTeX, three packages for one document

Image
LaTeX, three packages for one document The standard version of LaTeX has a “state of the art” typographic quality, suitable for any type of document. For those who want to try different typographical solutions it is, however, possible to use packages that modify the basic settings. The result may be more or less preferable to the standard version but it is, however, interesting to make some comparative tests. In this article I compare the title page of an agreement document in the standard version, in the version named koma-script and in the further version named ArsClassica . At the end of every paragraph I report the relative preambles used for the generation of every version. The images of the three title pages were framed with the open-source software Digikam . LaTeX in standard version Below I report the title page of a agreement written in standard LaTeX The page layout is elegant, well-kept and well-proportioned: perfectly suited to the formal rig...

Vim: copy text directly to the operating system clipboard

Image
Cut and copy in Vim: introduction As an introduction to the topic regarding the Cut, Copy and Paste functions in Vim you can read a previous article of mine . The subject of the current article is, instead, a Vim functionality I discovered while reading this page and which is closely related to the previous topic. Vim can directly redirect cut and copy operations performed on texts to the system memory register ( clipboard ). Therefore, it is not necessary to select the text first, in order to copy it into the clipboard, as is the experience with other writing systems on digital devices. In short: you simply direct the operation (the same as normally used for the specific command) to the operating system memory ( clipboard ) (or, to be more precise to the + register). This feature saves you time when exchanging data from Vim to other applications in the operating system. Vim: examples of direct sending to system memory ( clipboard ) A few examples can make it clear. Fi...