this post was submitted on 11 Feb 2024
35 points (92.7% liked)

Linux

47538 readers
695 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I do a lot of text editing for work and there are some phrases that I have to type frequently. What's the best way to quickly paste those phrases into a document using a shortcut or keyword? I mainly use Kwrite and Kate as i prefer plain text editors and need no formatting.

top 19 comments
sorted by: hot top controversial new old
[–] Zak 18 points 7 months ago

I mainly use Kwrite and Kate

Kate Snippets

[–] [email protected] 10 points 7 months ago (1 children)

Vim macros are quite easy to use, if you already know how to vi.

[–] ouch 0 points 7 months ago (2 children)

Besides macros, I think vim had some other relevant feature for this. Just can't remember it right now.

[–] [email protected] 3 points 7 months ago (1 children)

I use (neo)vim with UltiSnips for coding, text editing and writing e-mails, and it works great! It's super customizable.

[–] [email protected] 2 points 7 months ago (1 children)
[–] [email protected] 2 points 7 months ago

Yeah with its flags / regex / python support UltiSnips is really the gold standard of a snippet engine. In many other environments "snippets" really just means "substitute one string for another", where UltiSnips is so much more!

[–] [email protected] 1 points 7 months ago

Might be a plugin. I think I'm using friendly-snippets (whatever is in LazyVim). There is also LuaSnip. They feed into my auto completion plugin as one of several sources.

[–] ShittyBeatlesFCPres 7 points 7 months ago

I use Autokey because I prefer a global snippets engine. Then it works in text editors, browsers, email clients, etc.

[–] [email protected] 7 points 7 months ago* (last edited 7 months ago) (2 children)

If I understand you correctly, this is trivial in emacs:

(defun insert-text ()
  (interactive)
  (insert "your text here"))

(global-set-key your-keybind-here #'insert-text)

You could make it a format string if it relies on data specific to some file or parameter. You could also make the keybind local to certain modes/files rather than a global keybind if you don't want to pollute your keybind space.

[–] Zak 11 points 7 months ago (1 children)

Emacs has several templating/snippet packages available, such as YASnippet.

[–] [email protected] 4 points 7 months ago

There's a built in snippet system too, called skeletons, but most people seem to prefer the yasnippet interface.

[–] [email protected] 4 points 7 months ago
[–] [email protected] 4 points 7 months ago

Pulsar (i.e. active fork of Atom) has a pretty comprehensive snippets package that comes bundled with the editor. Can be configured with some fairly simple cson, for example with Markdown:

'.source.gfm':
  'Hello Lemmy':
    'prefix': 'helem'
    'body': 'Hello Lemmy!'

You type helem then press tab and it will expand to Hello Lemmy! when using the Markdown grammar (source.gfm).
It can handle custom tab stops too so you can make a longer preformatted sentence with gaps to insert words which you can just tab through (the $1, $2, $3).

'.source.gfm':
  'My custom snippet':
    'prefix': 'mcs'
    'body': 'My snippet stops here $1 and then here $2 and then continues $3'

You can even do multi-line snippets. For anyone wanting to try it out the docs are here

[–] [email protected] 3 points 7 months ago
[–] z00s 3 points 7 months ago

I've used Autokey with great success in the past. Easy to set up, just works.

[–] [email protected] 3 points 7 months ago

Visual Studio Code has this feature. You can define user snippets using a JSON format and create any alias you like for each. Then, when editing a document you just start typing the alias and press tab when it suggests the snippet (no mousing around required).

You can also create anchor points for variable content that you then tab through and fill out after inserting a snippet. If you find yourself using the same template for your writing this might be a helpful feature.

I’m bad at describing things, here’s some documentation: https://code.visualstudio.com/docs/editor/userdefinedsnippets.

This is all out of the box with no plugins installed. Also, I’ll point out that although the docs are coding related, you can make these work for any type of writing.

[–] [email protected] 2 points 7 months ago

Kate snippets. If you download them you think "huh do I need to know XML or what?"

But just install the extension and everything has a nice GUI

[–] [email protected] 2 points 7 months ago (1 children)
[–] [email protected] 2 points 7 months ago

Looks good, thanks!