UP | HOME

Getting started in a principled way

The good starting point is to uderstand what a text is and get familar with the two classic text editors – vi and emacs.

A text has “many structures”, layers and nesting – it consists of sequences of sequences – sequences of paragraphs, sequeunces of sentenses, sequences of words and special charactes, including punctuation, and sequences of ordinary characters (which denotes letters and numbers).

The key insight is that one navigates a text following its nested structure, not (and never!) just by pressing the arrow keys on a keyboard, which is silly, tedious, slow and lame. Programing languages (the source code) have even richer and deeper nested structures.

It has thus a regular structure, which means a hierarchy of nested linear sequences (all sequences are ordered – they have some particular implicit ordering of elements), thus the Regular Expressions has been generalized out of it.

From the regular and nested nature of a text other methodology has been emerged - markup languages, both for structuring the text (XML) and for creating structured documents (Org, markup, etc).

The vi editor (and its modern implemetations, such as Neovim) are especially designed to take advantage of the deeply nested structure of “markups” and “sources”, with the basic regular expressions in mind, so it feels familiar, intuitive and even “natural” just after few days of use.

Emacs, on the other hand, has the most powerful programming technique – the ability to create new and use existing Domain-Specific Languages (for an appropriate level of abstraction), embedded in the Emacs-Lisp, which is the language in which all the high-level functionality of Emacs has been programmed. (Please, completely ignore the previous sentence for now).

And then here comes:

as an ultimate declarative document structuring. Well, not so fast.

Lets take a few little baby steps first. Lets get ourselves familiar with Emacs and vi. They are free, well-known, multi-platform and open-source.

The main principle to always keep in mind (and to observe everywhere) is that a nested, hierarchical strucure is the most fundamental characteristic of almost everything in the world, from Molecular Biology of cells, up to all the spoken human languages, which just “mimic” this universal fact.

So, there are 3 modern classics books from the 90s:

which teach the right understanding and the proper concepts.

There are nice summaries of cheat-sheets:

For using these as toolkits or toolboxes there are differnt books:

Notice that Neovim and Emacs are both programs (layered and “modularized”) and programming environments, so getting familiar with and used to them is a good practice, similar to these of “marial artists”.

Everything is available on the internet as a “pirated content”. Learning how to find and download everything (including understanding the risks) is the crucial skill for larning anything.

There is also some high quality free content from inspired people and a literally sea of low-effort bullshit, which degens mostly copying (parroting) from each other.

The blog posts and youtube videos are plentiful and sometimes even fun. Develop a habit of extracting the principles and generalized knowledge from everything you watch or read.

This is the first steps to real hacking (which is understanding of how everything “works” and why, including the social dynamics and all the social “constructs”).

Just watching what other people managed to do with their copies of Emacs or Neovim is both inspiring, encouraging and satisfying, meaning that you can do it too.

The most important rule: never just copy-paste configurations (or code) without understanding. Always try to come up with a minimal config or a set of functions based on other people’s stuff. Always re-write yourself.

And suddenly you are so submerged in all this stuff of learning, understanding, configuration and customization, that you don’t have time for anything else, at least no time for bullshit.

Last, but not least, you should use the latest stable versions (releases) of your editors, preferably after a major bugfix release, such as, lets sat. 0.9.2 or 29.2. At least it shoud math the version which the examples or configs use.

This will save you from of frustration and stress caused by unexpected errors and compatibility mismatrches. Very few people use the development versions, but major crowds migrate to releases.

It pays off to wait till the most entusiastic and eager power users will switch to a new major release, encounter the bugs, scream and write angry blog posts and even bugreports, so the major bugs will be fixed in a next minor version.

All this is just common, recurrent social dynamics anong developers and users. Learn and develop a habit to observe and understand “hows” and “whys” in what is going on is societies and social niches.

Do not use ready-made configurations, like Doom Emacs or some “branded” Neovim configs from GitHub before you understand the principles and most of the details of how they work, including your personal experience of configuring.

Some day you might find something like

and your whole life will be changed forever. Ok, just kidding.

Emacs

Emacs is a Sotware Lisp Machine (in the form of a program), which happen to be used primarely to edit structured texts, including any program source code.

To start Emacs without any pre-defined configuration type at the shell prompt (bash):

emacs -q

Emacs is /self-documented

The Ctrl-h invokes the Help subsystem, k tells it that you want to know abot what happens when you press a key. a is the key (you want to know about).

Ctrl-h k a

When you press, lets say, the a key on a keyboard, the following Lisp code will be executed.

(self-insert-command 1 'a)

This means that every key-press (or a combination of keys) within a Emacs window invokes some function, and the whole thing is a giant Read-Eval-Print loop. Not bad, eh?

Neovim

Neovim is an open-source, global community-driven project, which extends the original classic vi (and later Vim, which is a particular implementation) editor.

To start Neovim without any pre-defined configuration type at the shell prompt (bash):

nvim --clean

Withing neovim there is also a built-in Help system based on plain-text files.

:help <Tab> - type the : to enter into the ex command mode, then help (a command), then space and press the Tab key. It will show a huge list of topics, sorted in an alphabetical order.

Here is an example configurations: https://github.com/VonHeikemen/nvim-starter%20. He uses git branches, so just navigate it on GitHub website.

Again, never just copy-paste, try to understand first, then write your own, in small steps, step-by-step, based on these files. Start with the minimal (smallest) config.

Beware, there is a lot what is going on - Language Servers and Completion setup, plus additional modules. Ignore file “explorers” – they are unnecessary bloat.

The “text objects”

In Vim, editing commands have the following structure:

  <number><command><'text object' | motion>

The motions are the most familiar $, 0, w, W, e, E, etc.

Vim’s text objects provide an incredible level of precision. The key is to try to always edit by text objects. Editing by motions e.g., by part of a line, to the next occurrence of a character, is tedious, clumsy, and slow. Instead of correcting a misspelling character by character, change the entire word and re-type it. Don’t be discouraged by the large number of text objects, their conventions make them intuitive and easy to learn. After some practice, like every other Vim command, they’ll quickly become just another muscle memory.

A command using a motion, e.g., cw, operates from the current cursor position. A command using a text-object, e.g., ciw operates on the whole object regardless of the cursor position.

The most useful text objects are these with quotes, brasses and bracketsa", a), i}, a], etc. and the commands are c and occasionally d.

The nvim-treesitter-textobjects package adds af if for functions and ac ic for classes.

More: https://blog.carbonfive.com/vim-text-objects-the-definitive-guide/

Learn more

See also:

Author: <schiptsov@gmail.com>

Email: lngnmn2@yahoo.com

Created: 2023-08-08 Tue 18:40

Emacs 29.1.50 (Org mode 9.7-pre)