Skip navigation

Tag Archives: cut

This is a way to select whatever text we had just inserted inside a buffer. I forgotten this trick until now that used it again. A small tip worth annotating that might come in handy for somebody else as well:
1) yank(paste) the text “C-y”
2) mark the point where the cursor landed, (using point-to-register), do “C-x r SPC” and pick any letter ( a-z)
3) go back to the point where you initially were, by doing “C-u SPC”
4) set the mark there,“C-SPC”
5) use “C-x r j” (+ the letter picked) to go up the point where the yanked text ends inside your buffer.
6) Voila, the text yanked is highlighted ready for whatever manipulation you need to do onto it.

ps: Of course in case you pasted text at the end of the buffer is simpler,
just a matter of:
“C-u SPC”
“C-SPC” to mark
“M – >” to go to the end

UPDATE: Actually, thanks to Peter (see comment below) I learned that this is possible just doing “C-x C-x after the yank if you have transient mark mode enabled” .

A quick note so I can remember the way to skip some fields at the beginning of a line printing the rest without further specifications (as it’d be tedious to have to write say: awk '{print $2,$3,$4,$5,$6,$7,$8,$9...$n}')
The solution found here explains a simple way: just to print the substring starting from the nth field.
In my example where I pull the history of commands filtering for “find” I skip the first field in order to output without the command number:
history | grep find | awk '{print substr($0, index($0,$2))}'
(for what it matters, turns to be convenient for me inside the emacs shell, as I can select the line I want doing fewer keystrokes:C-a SPC, activates the selection mark at the beginning, C-e extends selection to the end of the line and C-w copies it to customize and reuse it)

Later observation:
Actually, I found a simpler (hence, better) way using the cut command:

history | grep find | cut -d ' ' -f3-

where “-d ‘ ‘” is the separation field and -f3- means from the third field on. With cut you don’t need to know which is the last field, leaving the second part of the range empty implies “up to the end”.