Google Docs: How to have a piece of text automatically substituted without a trailing space? - google-docs

This is probably trivial but...
I have created a couple of substitutions in Google Docs (Tools → Preferences → Substitutions), but the substitutions are trigged by a space and I do not want that space.
Example
Sometimes I just need to type Abfall (waste in German) or Bioabfall (bio waste), but other times compound words like Abfallsammelfahrzeug (waste collection vehicle) and Bioabfallsammelfahrzeug (bio waste collection vehicle). Rather than having four separate substitutions for the two types of waste and their collection vehicles, I would like to have three: "Af" and "Bf" for the wastes and "sf" for the vehicle, so that by typing "Af sf" and "Bf sf" I get the respective vehicles.
Currently typing "Af" and a space to trigger the substitution leaves the space and I have to press backspace to delete it before typing "sf" and having the full compound word.
How should I modify my substitutions in order to get rid of those trailing spaces?

Related

What is the VIM way to copy a list of variables (a list of words vertically aligned with different widths)?

let(:aaaaa) { 123 }
let(:bb) { true }
let(:ccc_ccc) { "foo bar" }
I want to copy all variable names (:aaaaa, :bb, :ccc_ccc).
In VsCode, for example, I would use a multi-line selection.
How can I do it in VIM?
Block selection didn't work, once the variable names have a different length.
You could use the command :%norm f:"Qyt) to make your 'q register' contain the
following:
:aaaaa:bb:ccc_ccc
The way it works is as follows:
:%norm means 'to all lines, apply the following normal commands'
f: moves the cursor to the first colon on the line
"Qy appends yanked text to the 'q' register
t) is a motion 'till the next closing parenthesis
This assumes that the 'q' register is already empty (you can use qqq to clear
it). If you only want to do this for a subset of lines, you'd replace the %
with a range (or visual selection).
What you do with the register's contents after that is up to you.
"qp will put them into the buffer, and maybe you'd then do :s/:/\r:/g to
split the lines at the colons like this:
:aaaaa
:bb
:ccc_ccc
If your immediate goal is to have something like this in the default register:
:aaaaa
:bb
:ccc_ccc
then it won't be easy to achieve without the ability to visually select multiple non-contiguous pieces of text of arbitrary length, which Vim doesn't have out of the box.
This means that, if we don't want to use a multiple cursors plugin, we are left with more pedestrian ways involving substitutions, macros, etc.
Assuming the cursor is on the first line, you could do something like:
:,+2t+2 " copy the block below itself
:'[,s/.*(\(.*\)).*/\1 " remove everything you don't need
:'[,d " cut the three lines to the unnamed register
But Vim works best when it is used with intent. "Copy this" is rarely a goal in and of itself: it generally is one of the several low-level steps necessary to complete a higher-level task (which itself might be one of the steps of another even higher-level task). What one intends to do with the copied text often plays an important role in choosing the best strategy. Here, your actual goal may have been to get the three variable names on three lines right below their definition, something that actually doesn't imply copying them, so the two first steps would have been enough.

Why are paragraphs interpreted differently using "{" and "}" motions vs. "ap" and "ip"?

When using { or } to navigate between paragraphs, Vim appears to treat lines with white space characters as if they were part of the paragraph and skips past them. This behaviour has been discussed in a number of threads and the explanation given (based on :h paragraph) is that "a paragraph begins after each empty line", which is fine.
However, this does not appear to be consistent with the way Vim treats the ap and ip commands, which actually do treat lines with whitespace characters as paragraph breaks. For example, given the following text where the first two paragraphs are separated by a non-empty line (containing whitespace) and the second and third paragraphs are separated by an empty line (and assuming the cursor starts at the top of the buffer) the following occurs:
1 abc # next line contains spaces
2
3 def # next line is blank
4
5 jkl
}: moves the cursor to line 4 (i.e., treats lines 1-4 as a paragraph)
dap: deletes lines 1 and 2 (i.e., treats only lines 1-2 as a paragraph)
These two behaviours appear to be inconsistent with one another. Why do these two commands that operate on a paragraph object behave differently?
As mentioned in :help ap and :help ip:
Exception: a blank line (only containing white space) is also a paragraph boundary.
So the behaviour of ap was made voluntarily different from that of } and the difference is clearly documented. The exact reasoning behind that difference is explained nowhere, though, and may be lost in time. You might want to ask on Vim's official mailing list.
Anyway, we can extrapolate a little…
Vim's } is consistent with vi's }. This is expected since Vim's whole purpose is, after all, to be a convincing stand-in for vi.
ap (and the whole concept of text objects) is a Vim thing. It wasn't in vi so there is no existing behaviour to replicate and the person who added that feature decided to make it treat "paragraphs" in a slightly more intuitive fashion than }.

vim: how to change a few last letters of the word?

Imagine you need to change a few last letters in a word.
From
.. visualizing a graph?_
(_ denotes where the cursor is, mode:normal)
you need to arrive at
.. visualize| a graph?
(| denotes the cursor, mode:insert)
How would you do this?
(please suggest how would you really do this, not the "super-doper" way nobody uses)
I am asking, because I do this insanely inefficiently:
type b until reach _visualizing a graph?,
followed by e (visualizinG a graph?),
followed by x to remove g under cursor,
followed by few Shift+x to remove what is before the cursor,
and, finally, i switch into the insert mode and type e.
With given example, I would do:
Tzcwe
If there are just a few words between the cursor and where I want to go, I will use CTRL+left as many times as needed plus CTRL+right once and <bs> 3 times. I may also use the mouse. It's not that different from what you use, except I don't leave the insert mode for simple moves. Note this is exactly what I use when I type messages in my browser (I've never been conquered by vimperator & co).
I'm aware of <esc>gegege...3<left>cwe<esc>. But that's definitively not my first choice.
I may use T and F on symbols with few occurrences, but I seldom use them on letters as I'll spend more time detecting the best character to use than using CTRL+cursor as many times as needed. Beside, when I'm correcting what I've typed, it's likely that my mind is in "reread+correct/refactor sentences" mode, speed typing is not my priority.

How to make a text object/motion with begining and ending pattern in Vim

I would like to define a text object like iw, aB and the other ones listed in :help text-objects that defines an area beginning with some pattern and ending with another. More precisely, I would like to define a text object which starts with some {pattern1} and ends with some {pattern2}. The patterns included. It is important that it can stretch over multiple lines (like aB but unlike a").
The examples I have in mind are for selecting in-line equations in LaTeX, that is, everything between one $ and the next $ (including the $'s), and for selecting LaTeX environments like between \begin{*} and the following \end{*}, where the * here is just any string of characters (but non-greedy like \{-} in Vim regex).
I have tried to tried to look at this guide at the Vim Tips Wiki, but I do not know how to replace [z and ]z with something that searches backwards for some pattern and forwards for some patters, respectively, so that it works as I want it to.
So to give the example of the inline equation (lets say the text obejct is called ad), then, if the cursor was placed somewhere between the $'s in the following line:
it follows that $ \sum_{n=0}^\infty 2^{-n} $ is two
in normal mode, and vad was pressed, then $ \sum_{n=0}^\infty 2^{-n} $ should be in visual, or if dad was pressed it should be deleted.
The mentioned Vim Tips Wiki page lists the two plugins (under "Related scripts") that make defining new text objects very easy:
textobj-user is very flexible and generic
CountJump plugin (by me) is specially written for text objects defined by start and end patterns
The following call defines an ad text object for text inside $...$:
call CountJump#TextObject#MakeWithCountSearch('', 'd', 'a', 'v', '\$', '\$')

vim - How do you save line numbers so you can easily jump to them whenever you want?

Suppose I am working on three functions and I will be jumping back and forth between them. Suppose functions A,B, and C are on lines a, b and c. Is there a way to bind the following (which jump to the line position)
:a
:b
:c
to keys during runtime so I can easily jump to these positions. If you play Starcraft this is kind of like binding a selected group of units to your number keys, and then using the number keys to quickly change your selected group (or jump to the designated line, in this case).
Or is there another way of getting a similar result that I am unaware of? I just recently discovered that =% autoformats your tabs within the highlighted brace, so I am pretty new to vim.
Thanks.
You want to use marks. They allow you to save your current position in the file to a variable.
In Starcraft, you "Hotkey" your guys by pressing Ctrl+1 to tag them, then tap 1 to select them again.
In Vim, you "Mark" a place by pressing [m], then [a](or any letter) to mark them, then [`], then [a] to go back to that mark.
So you have hotkeys to 1,2,3,4, etc in SC, but marks are a-z(and probably other characters but I'm not sure) in Vim.
For more technical info try
:help marks

Resources