vi keybindings move to beginning of line with <ctrl> \ what about end of line - keyboard-shortcuts

I use the vi key bindings from set -o vi . I emphasize this because most vi conversations invariably lead to regular vi. and this is not, these are the vi key bindings. anyhow.
I hit control and '[' to get into command mode from the command line.
Then I hit shift and '\' (backslash) to go to the beginning of the line. I like it better than using 'Shift ^'. I don't see it documented anywhere and I can't use it in regular vi.
I still use shift $ to go to the end of the line. Does anyone know a different way to go to the end of the line in the vi set -o keybindings besides "shift $". If there is an easter egg command of shift and '\' to get to the beginning of a line, there might be other hidden commands as well - I am looking for one that will get me to the end of the line. One besides 'shift $'

The | command is used in vim to go to a particular column. You can prefix it with a count (e.g. 13| to go to column 13), which is 1 if omitted. Thus the naked | command goes to the first column, the same as 0 that casper suggests. This differs if you have leading whitespace in your command, where ^ will go to the first non-whitespace character, while 0 or | will go to the first character, even if it is whitespace.
Out of the box, set -o vi the only synonym for $ that I know of is <end> (which is unfortunately, waaaaay over there on the keyboard).

Related

Remove first 4 whitespaces from line

I inherited a script I want to refactor.
for some reason the script is intended with four whitespaces.
I would like to remove leading four whitespaces from each line.
Is there any handy and fast way to do it?
Message "Try to get Package Lock..."
if waitForPackageLock("300","false")
comment "UCS: Extra check if package lock is available."
endif
Cheers
That was a difficult one.
sed 's/^ //'
Or edit your script with an editor.
vim file
:%<
: execute a command
% apply to all lines
< remove one indent

AIX: remove the last symbols (CRLF) from a file

There is a large file where the last symbols are \r\n. I need to remove them. It seems to be equivalent to removing the last line(?).
UPD: no, it's not: a file have only one line, which ends with \r\n.
I know two ways, but both don't work for AIX:
sed 's/\r\n$//' file # I don't why it doesn't work
head -c-2 # head doesn't work with negative numbers
Is there any solution for AIX? A lot of large files must be processed, so performance is important.
Usually, if you need to edit a file via a script in place, I use ed due to historical reasons. For example:
ed - /tmp/foo.txt <<EOF
g/^$/d
w
q
EOF
ed is more than a bit cantankerous. Note also that you did not really remove the empty lines at the bottom of the file but rather all of the empty lines. With ed and some practice you can probably achieve deleting only the empty lines at the bottom of the file. e.g. go to the bottom of the file, search up for a non-empty line, then move down a line and delete from that point to the end of the file. ed command scripts act (pretty much) as you would expect.
Also, if they really do have \r\n, then those are not going to be considered empty lines but rather lines with a control-M (\r) in them. You may need to adjust your pattern if that is the case.
My answer https://stackoverflow.com/a/46083912/3220113 to the duplicate question should work here too. Another solution is using
awk ' (NR>1) { print s }
{s=$0}
END { printf("%s",substr($2, 1, length($2)-1) ) }
' inputfile

How do I get scribble to make -- be two short dashes rather than one long dash?

In scribble, when I put two dashes (or even three dashes) together, such as --, it comes out as one long dash. How can I make scribble keep them as two short dashes, such as in this documentation page?
My ultimate goal is to be able to turn them into flags for a command, such as -h and --.
verbatim Does keep the dashes separate, but it also changes the font, and makes a new paragraph, which I don't want.
If your only goal is to add documentation for command line flags such as -h and --, then you can use the commands:
DFlag
Flag
The first will give you -- for longer flags, and the second will give you - for shorter flags. They will also change the font to match the terminal typeface for the docs.

Why can't I type "|" in the codecademy Command Line course?

I am 55% into the Command Line course on Codecademy but, I can't type "|".
I'm trying to do
cat volcanoes.txt | wc
And the | doesn't show and when I try to copy+paste it in only shows a ^V instead of the |. Please help
Try pressing alt + 124 on the numpad.
You should switch to US keyboard layout. Last key in ASDF row (just next to Enter) should print "|" when pressed in combination with Shift.
It worked for me in Codecademy command line console.

Is there a tool to clean the output of the script(1) tool?

script(1) is a tool for keeping a record of an interactive terminal session; by default it writes to the file transcript. My problem is that I use ksh93, which has readline features, and so the transcript is mucked up with all sorts of terminal escape sequences and it can be very difficult to reconstruct the command that was actually executed. Not to mention the stray ^M's and the like.
I'm looking for a tool that will read a transcript file written by script, remove all the junk, and reconstruct what the shell thought it was executing, so I have something that shows $PS1 and the commands actually executed. Failing that, I'm looking for suggestions on how to write such a tool, ideally using knowledge from the terminfo database, or failing that, just using ANSI escape sequences.
A cheat that looks in shell history, as long as it really really works, would also be acceptable.
Doesn't cat/more work by default for browsing the transcript? Do you intend to create a script out of the commands actually executed (which in my experience can be dangerous)?
Anyway, 3 years without an answer, so I will give it a shot with an incomplete solution. If your are only interested in the commands actually typed, remove the non-printable characters, then replace PS1' with something readable and unique, and grep for that unique string. Like this:
$ sed -i 's/[^[:print:]]//g' transcript
$ sed 's/]0;cartman#southpark: ~cartman#southpark:~/CARTMAN/g' transcript | grep CARTMAN
Explanation: After first sed, PS1' can be taken from one of the first few lines of the transcript file, as is -- PS1' is different from PS1 -- and can be modified with a unique readable string ("CARTMAN" here). Note that the dollar sign at the end of the prompt was left out intentionally.
In the few examples that I tried, this didn't solve everything but took care of most issues.
This is essentially the same question asked recently in Can I programmatically “burn in” ANSI control codes to a file using unix utils? -- removing all nonprinting characters will not fix
embedded escape sequences
backspace/overstriking for underlining
use of carriage-returns for overstriking