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 ...


17

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 ...


14

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

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

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


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

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 ...


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 ...


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

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

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 ...


7

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 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 ...


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.


6

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. ...


6

try alias sudo='nocorrect sudo'.


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

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

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 ...


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

I generally use the clipboard for this kind of thing $ some_command | cb $ cb_edit $ `cb` #or paste it with your paste button/shortcut The magic: cb() { if [ ! -t 0 ]; then #if somebody's piping in reproduce input and pipe a copy to the clipboard tee >(xclip -selection c) else #otherwise, print the contents of the clipboard xclip ...


4

Since this problem occurs on different terminal types, and occurs at a command prompt but not when some other program is reading from the terminal, this is a configuration problem in your shell. You've accidentally defined bindings for a and c. Assuming that your shell is bash (the default interactive shell on Ubuntu), check the two relevant configuration ...


4

pr I'd probably go w/ pr: printf %s\\n hi wonderful amazing sorry \ superman superhumanwith loss >/tmp/file #^what is all of that, anyway?^ seq 7 | pr -tm /tmp/file - pr can -merge input files (here /tmp/file and - stdin) line-by-line like paste column-wise, but it can take many other parameters besides. By default it will print headers ...



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