Snippets regardless of the editor

Snippets regardless of the editor

I have been working with for a long time snippets: with their help, I create skeletons of modules, functions and structures (for, if, given). It becomes real to dust even medium projects alone. Snippets – an indispensable thing when searching for an error in a program by the dichotomy method: you have to insert the output of information dozens of times, changing only the current variables in it.

However, it can be used snippets only in one editor. They will have to be transferred manually to another editor.

It would be nice to have a program that could paste snippets in all applications.

Fig. 1.1 mcedit-or

  • On the remote server, you must go to docker – and there you will usually find ed or vi (Fig. 1.2) in which snippets do not write them down – they will disappear when the container is restarted.

Fig. 1.2 Editor vi

  • I use several editors at the same time: vscodium, kate, notepad++ (under wine, of course), kwrite, pycharm, Intellij Idea (in which relevant snippets for html, css/sass and js), atom and subl.

  • sql-snippets will be needed in heidisql, Database Intelliji Idea, in console mysql and pgsql.

  • To check the code (if there are doubts about how it works), I run one-liners in the console in which snippets would be very useful.

  • If you need to give an example of code during correspondence, then snippets will be indispensable in messengers and mail clients.

  • And finally, I often write articles on Habre and, in some cases, it would be ideal to insert a snippet into code fragments directly in the article without switching to the editor for this.

Meanwhile, En-Ru Switcher 7 was released, which supports it (Fig. 2.1).

En-Ru Switcher

Fig. 2.1 The erswitcher configurator is open on perl snippets

Erswitcher configurator [1] opens by clicking on the red square near the clock. It is divided into a list of config sections and an editor. It is easy to move to the desired chapter or section according to the list (chapters start with ##while # – Normal comment).

To the mark = there is a mnemonic in the section [compose]which will be replaced by the text on the right when pressing the menu key (the central key on the additional numeric keypad), or a key combination in other sections.

To indicate the tab character is used \tand for line translation \n. \^ is used to specify the position to place the cursor after inserting text (meaning the text cursor, of course).

As soon as you enter the text, it will be immediately saved in the config and the config will be read by erswitcher.

To use the same config on different computers, just select it all and copy (Ctrl+a, Ctrl+c), then you can save it to docs.google.com, for example.

What is a snippet?

A snippet is such a “skeleton” of code that is often repeated. [4]. After inserting the text of the snippet, the “spaces” in it are filled, as shown in the video [2].

The word “snippet” has other meanings. This is how SEO-optimizers call a snippet “a small fragment of text that we see on the output page of a search engine (Google, Yandex, Yahoo, Rambler, Duck-Duck-Go) together with a link to the site.” [5].

How does erswitcher insert text?

The snippet body is entered according to ICCCM: erswitcher tracks keystrokes and remembers the last characters entered by the programmer. When the menu key is pressed, it recognizes the typed mnemonics, such as “if” and emulates a double backspace to remove them. Then declares itself the clipboard and presses Ctrl+v. The program in which “if” was written asks the exchange server for text and receives the body of the “if() {\n\t\n}” snippet, which it inserts at the cursor position. erswitcher meanwhile, waits for the insertion to finish for 10 microseconds and presses the left arrow key as many times as there are characters between \^ and at the end of the snippet text to reach the cursor position specified in the snippet (“if=if(\^) {\n\t\n}”).

Is there an alternative?

erswitcher made for unix. PuntoSwitcher seems like someone once managed to run it under wine, but without a tambourine you can only get an error of no localization. In addition, text insertions in PuntoSwitcher are made in the form of a list, where you cannot insert a line translation or a tab. You can’t position the cursor either.

Development of an idea

In fact, I would like to specify several “gaps” in the erswitcher snippet, where to position the cursor after filling the first one (for example, when pressing some key combination). Also, the text of the snippet in the configurator editor is written in one line and, although it can be used \n for the string translation symbol, it would be nice to add multi-line snippet definitions.

All this will be implemented in future versions erswitcher-AND.

References

  1. Yaroslav O. Kosmyna “Config EN-RU Switcher”

  2. Yaroslav O. Kosmyna “Snippets from erswitcher”

  3. “Programs supporting snippets” ed. Vbif routine

  4. Yaoguai “Snippets. How to make the process of working with documentation easier”

  5. MPalma “25 Ways to Compose a Comprehensive Snippet”, 2014

  6. alspirichev “On the way to the ‹10x engineer›: shortcuts, snippets, templates”, 2020

  7. Kapodastr “Sublime Text 2: How to create a snippet?”, 2012

Related posts