Hot answers tagged

48

To find out about a key binding. In bash: $ bind -p | grep -a '{' "\e{": complete-into-braces "{": self-insert $ LESS='+/complete-into-braces' man bash complete-into-braces (M-{) Perform filename completion and insert the list of possible com‐ pletions enclosed within braces so the list is available to the shell (see ...


23

In bind -p listing, I can see the command is called edit-and-execute-command, and is bound to C-xC-e in the emacs mode.


22

You could do this: mv /longpath/longfile !#:1:h/morepath/ See https://www.gnu.org/software/bash/manual/bashref.html#History-Interaction !# is the current command :1 is the first argument in this command :h is the "head" -- think dirname /morepath/ appends that to the head and you're moving a file to a directory, so it keeps the same basename. If you ...


18

If the characters on your command line are sometimes displayed at an offset, this is often because zsh has computed the wrong width for the prompt. The symptoms are that the display looks fine as long as you're adding characters or moving character by character but becomes garbled (with some characters appearing further right than they should) when you use ...


16

zsh provide this functionality by using history-beginning-search-backward history-beginning-search-forward Ex. bindkey "^[[A" history-beginning-search-backward bindkey "^[[B" history-beginning-search-forward Find exact Key code by ctrl+vKEY Ex. ctrl+vUP ctrl+vDOWN ctrl+vPageUp ctrl+vPageDown etc.


14

OK, I got this. The problem isn't autocd, it's correctall. vim as a command (vim file) doesn't trigger any correction*, but vim in sudo vim is an argument, zsh sees that it's close to the name of a folder in the current directory, and asks if you want to change to that, as files and folders are more common arguments. So the solution is unsetopt correctall (...


14

You could also do this with brace expansion: mv /longpath/{,morepath/}longfile The shell expands this so that the mv command sees it the same as: mv /longpath/longfile /longpath/morepath/longfile


10

If you don't want to disable corrections completely, you should define an alias: alias knife='nocorrect knife'


10

When you press Enter at the end of: for VARIABLE in file1 file2 file3 The shell can't execute anything since that for loop is not finished. So instead, it will print a different prompt, the $PS2 prompt (generally >), until you enter the closing done. However, after > is displayed, you can't go back to edit the first line. Alternatively, instead of ...


10

Typing the Ctrl-U key combination will, in most cases1, erase the entire line of input even if echo is turned off. [1] Some programs put the terminal device into "raw" mode, where every character you type is sent to the program. Emacs is one example. They may have their own conventions for character erase/line kill processing.


9

It doesn't highlight the selection, but otherwise I think it works fine. Try running $ bind -p | grep copy-region-as-kill to make sure that C-x C-r actually worked. It should say: "\ew": copy-region-as-kill After that, it should work fine. Example: $ abc<C-Spc><C-a><M-w> def <C-y> gives me $ abc def abc If you ever want ...


9

If you have $EDITOR = vi* or VISUAL = vi* when zsh starts up, zsh uses vi insertion mode as the default keymap. Otherwise zsh uses emacs mode. You presumably set EDITOR (or VISUAL) to vim in your init file, but have no such setting when running as root, so you're seeing the vi mode map, in which history search is on ^X r and ^X s. Add bindkey -e to your ....


8

As in your example, you can use next construction: mv foo/bar/poit/zoid/{narf.txt,troz.txt} or even (as suggested Ansgar Esztermann): mv foo/bar/poit/zoid/{narf,troz}.txt instead ot typing/copypasting long address twice.


8

This is the documented behavior: down-line-or-search Move down a line in the buffer, or if already at the bottom line, search forward in the history for a line beginning with the first word in the buffer. There doesn't seem to be an existing widget that does exactly what you want, so you'll have to make your own. Here's how to define a widget that ...


8

If you are for more efficient typing in command line, you may find various readline shortcut useful. Readline is already built-in your shell. For your paricular case you could yank/delete parts of your line and then recall them from readline killiring. Moreover, if you have EDITOR environmnent variable set to your favorite editor, then Ctrl-X,Ctrl-E will ...


8

Ctrl+R works with ksh in emacs mode (ksh -o emacs or set -o emacs within ksh), and it was most probably the first shell to support it. Only it's not as interactive as in zsh or bash or tcsh's i-search-back widget. In ksh (both ksh88 and ksh93), you type Ctrl+RtextReturn. And Ctrl+RReturn to search again with the same text. In vi mode, you can use ? to ...


7

You can add setopt nocorrectall; setopt correct to your ~/.zshrc file to disable this behavior. It will still function for commands, but not for arguments.


7

Assuming you are using the "usual" bash with emacs bindings, using Ctrlw should work. To delete three words either press Ctrlw three times or preceed it with Alt3 or ESC3. For more shortcuts have a look at this list.


7

Most shells have a facility called keybindings. It's of course configurable, and the designers of Bash opted to use keybindings that are similar to the text editor Emacs. Here's a cheatsheet that shows all the various keyboard shortcuts one can use from within a Bash shell to move the cursor within a given prompt, as well as delete whole words etc. ...


7

You seem to need column: paste file1.txt file2.txt | column -tc2 which creates this output: hi 1 wonderful 2 amazing 3 sorry 4 superman 5 superhumanwith 6 loss 7 You can of course also write your own script to do the formatting. Here is one way using awk: awk ' NR==FNR { a[FNR] = $0 ; if (...


6

try alias sudo='nocorrect sudo'.


5

I'll focus on Ctrl+Delete first. The zsh command to delete a whole word forwards is called kill-word. By default it is bound to Alt+D. How to make Ctrl+Delete do it too depends on which terminal emulator you are using. On my system, this works in xterm and Gnome Terminal: bindkey -M emacs '^[[3;5~' kill-word and for urxvt, you should do: bindkey -M ...


5

History expansion actually works on the current command as well, using the event designator !#. Combine this with the word designator for the last argument - $ - to get the parameter you just typed. And you can use all the regular modifiers over it, so if, e.g., you are renaming a file in a far away directory, you can just type: mv path/you/do/not/want/to/...


5

If I've planned ahead, I use brace expansion. Here is another approach using the default readline keyboard shortcuts: mv foo/bar/poit/soid/narf.txt: start Ctrl-w: unix-word-rubout to delete foo/bar/poit/soid/narf.txt Ctrl-ySpaceCtrl-y: yank, space, yank again to get mv foo/bar/poit/soid/narf.txt foo/bar/poit/soid/narf.txt Meta-backspaceMeta-backspace: ...


5

In tcsh (which I suppose is what you're calling "C-Shell" if you're not totally masochist) in emacs mode (usually the default), you can use Ctrl-W. That's the kill-region widget which deletes between the mark (set with Ctrl-Space but defaults to the beginning of the line) and the cursor. In that regard, its behaviour is closer to emacs' than with bash(...


5

Use read -e: $ read -e -n 5 13acX read -e means that: Readline (see Command Line Editing) is used to obtain the line. When you do that, you can edit the input in any of the ways you would when writing at the regular shell prompt, including backspace, Home, and so on.


5

This feature can be tuned with ZLE_REMOVE_SUFFIX_CHARS and ZLE_SPACE_SUFFIX_CHARS shell parameters. If the ZLE_REMOVE_SUFFIX_CHARS variable is set, it should contain a set of characters that, when typed, will cause automatic suffixes from the completion to be removed. If ZLE_REMOVE_SUFFIX_CHARS is unset, the default behaviour equates to ...


5

In Emacs-mode type sudo $(locate create-tables.sql), Esc,Control+e See shell-expand-line in Bash Reference Manual: Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions


4

sed -i "/^version =/s/'[^']*'/'NEW_VERSION_IS_HERE'/" your_file


4

If you mean keyboard shortcut at the prompt of interactive bash shells, you could bind the shell-backward-word and shell-forward-word to some sequence of characters sent upon some key or combination of key presses. Like if pressing Ctrl-Left sends the sequence \e[1;5D on your terminal like it does in xterm, you could do: bind '"\e[1;5D": shell-backward-...



Only top voted, non community-wiki answers of a minimum length are eligible