Posts

Showing posts from September, 2022

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