How to enter a literal tab on the commandline in terminal

You press control+v then tab! :slight_smile:

I’ve never seen that before; perhaps you should submit it to OS X Hints as well.

I googled it, and found it in a blog, but since I had overcome my laziness, and figured it out, I though’t I’d share that here. This, has been an annoyance for some time now, so I am glad I solved it.

I haven’t figured out what kind of short cut key function that is, but I guess it is from the emacs/cocoa text subsystem.

At least I’ll mention it in a clause in some post at Mac Os X hints. It is kind of small for a hint isn’t it, but I’ll ponder it. :slight_smile:

It’s however commonly known that ctrl+v is used to insert an escaped character. That means that the character will be inserted and it’s associated action will not be performed.

It comes with some history as expected. As you may have noticed, Mac OS X supports the old unix cut/paste features, ctrl+k and ctrl+y. Some applications like Quarkxpress still support it too, ctrl+k and ctrl+d to cut. I use it as an secondary clipboard but is seen by many users as an feature in OS X. Well the “secondary” cut and paste (originaly named kill and yank) is as old as the ctrl-v (verbatism insert). The history goes indeed back to emacs when the modern cut/copy/paste method didn’t existed yet.

ctrl+u removes everything before the cursor
ctrl+k removes everything after the cursor
ctrl+y paste (what has been removed with commands above)
ctrl+w remove word before cursor
ctrl+a move cursor to beginning
ctrl+e move cursor to end
ctrl+l clear screen same as clear (not same as command+K in Terminal.appclears the view)
ctrl+r search history command
ctrl+t switch characters
ctrl+v verbatim insert
esc - u makes the word uppercase
esc - l makes the word loawercase
esc - b move backwords in words
esc - f move forward in words
ctr+c cancel the current command
esc - tab autcompletes commands (instead of path)
esc - ? autocomplete (once you aleady have typed a command like 'cat ’ it shows the content of current directy)
esc - * place all autocomplete suggestions

  • means keys have to be pressed simultaneous
  • means keys have to be pressed chronologically
    esc means the option key. This is by default the escape key but kan be changed in the Terminal’s preference by selection the option ‘option key as meta’ in the keyboard tab.

Those are the most characters I’m using if someone is interested.

:smiley:

How nice! then I gather it is the short cut keys that are implemented free with all applications that are using the Cocoa Text Subsystem.

Well, I’m going to play a little bit with this, but while we are speaking of this in the context of just the terminal, I’d like to add a couple of tidbits.

I have a prompt that shows the current command number in the terminal window. (Path in window title).

then I can do a history |more, or history |grep something. I can see the number and execute the command I want to execute with ! .

If you look at the readline commands in the bash manual (man bash) I think you’ll find some of the same commands as DJ Bazzie Wazzie just has mentioned, I think you also can make ctrl-R and ctrl-S work for incremental search through the history buffer. There are also symbols that can be used for placeholders on a command line, like back references in a regular expression.

What’s more worth mentioning, is that at least on my machine, I can move by word by holding down the opt and arrow keys, this also works with ctrl-f and ctrl-b when editing the command line.

one more is ^Z for suspend the current job, you get it back by fg %1 and kill %1 kills it!

Definitely worth mentioning but unfortunately on my machine is ctr+b and ctrl+f same as left en right arrow key (back and forth). On many machines the option key is equally to alt but because it conflicts with the cocoa text system (that is only used by Terminal.app) the escape key is the option key in bash here. Can be confusing with other bsd systems

Hello, I believe I sat it somewhere, though maybe it works for the standard cocoa text subsystem.

ctrl-f and ctlrl-b works with every cocoa text subsystem document based app, like TextEdit and XCode, or the Spotlight search field, (as do crl-A, ctrl-K and so on.) I believe it works in any NSTextField!

I think I did tinker something, so I changed the meta key for the whole cocoa text subsystem to use opt/alt instead of Esc, but I can’t for the bare life of me remember how I just did that for the moment. (I have fever).

I’ll come back to this, if It lightens up for me! It is so practical! :slight_smile:

Edit, I have not set the “use opt” as meta key in terminal app, so I have done it with the cocoa text subsystem, so it works everywhwere.

Just try something that requires meta in TextEdit, and you’ll see that those indeed works there a s a part of the cocoa text subsystem.

Still not sure how I did it this time, I am at least totally sure that you can do it with the free preference pane KeyRemap4Macbook!

I think I actually have made my own config file for the cocoa text sub system thiis time.

It’s just an option in Terminal application ‘Use option key as meta key’. Which I have turned off and probably you have turned on.

edit: I turned Mac OS X off, as you like to name the cocoa text system, and I needed the escape key again. Thanks for the heads-up, I’ve changed it in my first post.

Hello. The cocoa text subsystem of Mac Os X would be appropriate. Not all apps on Mac Os X uses this model, TextWrangler and BBEdit, at least did provide their own, so does also Sublime. So it is nothing you have to use on Mac Os X.

You know, you can make a fully working copy of micro Emacs, (But very basic) by just specifigying key bindings, and an NSDocument app, without much more than is in the template! :smiley: (It is described in the Text Systems Overview).

My point was that when I turn Mac OS X off, the cocoa text system is turned off as well. Which mean, when I’m in a real shell, and not in an (pseudo) terminal application, I don’t have anything to do with key bindings done by the Terminal application.

No one cares about my made short keys and wouldn’t have any value to this topic so I wanted to be sure that the shortcuts described in my previous posts are correct, which are.

I figured out how you turned off Mac Os X. I used to do that during long train travels some years ago! :slight_smile:

I think non cocoa key bindings are as interesting when it comes to terminal, as cocoa text bindings, for those reasons. Some times, you can’t leverage on terminal.app at all. Maybe because one uses Screen (man screen), that is a great session manager for starting several terminal sessions on a remote host, where you just detach the screen session manager before you log off the host, and wake it up again the next time you log on.

I used to use screen locally, to keep my terminal windows in one place before tab’s started working in terminal app.

Readline, which is documented in bash, is great for configuring the keyboard, when the cocoa text subsystem aren’t available, I see no conflict arising in parallell bindings. so I think you can pretty much configure your ~/.inputrc file with the same bindings as the cocoa text sub system, and have those working for you, when not working from the terminal.app. Having a conformant system means a lot to me. We are dealing with muscle memory here after all.

The last little tidbit, is that I think you can specify cocoa text subsystem keybindings on a per app basis. So if you’d rather have to specify those in the shell, and conflicts appears by having the same keybindings in two places, then you can “erase” the cocoa text subsystem keybindings for Terminal.app.

Edit

Overriding the meta key ‘ESC’ and turning that into ‘opt’, doesn’t seem that easy when you are not using the Terminal.app, but I am sure there is a way to do this with the Readline library, having had a look at man readline I guess you would do so by entering the key code of opt in some incanttion.

Here is a generally good reference on Readline: GNU Readline Library:

It’s easier as you think. You can use the bind command to use it for 1 session or you can create an inputrc file where you will overwrite bash’s default key bindings. The manual of bash describes perfectly how you can create such a file. Before you start creating your own, you can find a lot of inputrc files ready made for you to simulate other shells/terminals.

I actually skimmed through it, back in the days of Tiger, I used to have my own inputrc, to make everything work as it should, with my accented characters.

Today, I didn’t find anything to change the meta-key directly. (Bind meta-key to othe rkey.)But as I stated in the post above, I guess there are ways, before you go to the measure of recompiling readline.

My second thoughts about doing this, (changing the metakey from ESC to opt with readline), is how it would affect bash command completion, which uses readline extensively. I use that a lot and hates it when it stops working, rendering my keyboard useless for typing shell commands! :slight_smile:

Hello.

If you have a table of some sort, with a heading, then you can hit ctrl-shft-V and then ctrl-A in front of every field heading, the heading will then always come out on top after sorts. (This is called NoSQL tables, if it is to be a real NoSQLTable, then the first column should be unique and contain the primary key.)

And it’s christmas soon, O’Reilly are giving away one of their earlier titles on Unix Text processing. :smiley: [url=http://oreilly.com/openbook/utp/]Unix Text Processing (Hayden Books)[/url

(Groff is included with every copy of Mac OsX and it can output, at least html, and PDF documents.)

Ok.

Here is a little keystroke in the terminal that can make a huuge difference, when you have to enter long arguments.

Esc+period (.) repeats the last argument to the previous command, if everything is set up, like I have it.

(I see no reason why it shouldn’t work for you.)

Actually, a better way to do this is to press control-q than control-v, since control-q works in the whole cocoa text system if for instance you want to type a tab into some text field in some dialog, like the comment section of the file -info pane of finder, then prepend the tab with control-Q, so you it sticks to that field, and doesn’t move you to the next.

This works throughout the whole cocoa text system, which lies behind every standard text control on OS X. It also works in both Terminal.app and iTerm.app. (The key presses are then parsed at a higher level.