Tag Info

Hot answers tagged

13

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


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


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

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

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


7

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


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.


6

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.


6

try alias sudo='nocorrect sudo'.


6

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.


5

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


4

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.


4

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


4

When writing complex one liners in bash, it is handy to use readline's edit-and-execute-command (bound to C-xC-e by default in emacs mode). Hitting C-xC-e opens current commandline in the editor of your choice with all its fancy features. After saving it, bash will execute the contents as shell commands. Alternatively, issue bash's builtin fc to open last ...


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


4

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


4

See man zshzle for the pound-insert and vi-pound-insert widgets. The first will toggle a pound sign at the beginning of the buffer, the second at the beginning of the current line. Only pound-insert is bound by default, and then only in the vicmd key map, to #. To bind pound-insert, add this line to your .zshrc: bindkey '\e#' pound-insert


4

Try Alt + Backspace. From bash documentation: backward-kill-word (M-DEL) Kill the word behind point. Word boundaries are the same as backward-word.


4

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


3

Using history expansion, you can access the words of the previous command with !:n where n starts at 0 with the command name. !^ is equivalent to !:1. In this case, you want !:2 $ echo foo bar & [1] 10750 foo bar $ echo !:2 echo bar bar [1]+ Done echo foo bar


3

\e-\e. (or pressing - and . while holding alt/option) inserts the second last word. Similarly, \e-2\e. inserts the third last word, and \e2\e. inserts the third word.


3

What you want can be accomplished by just pressing Esc after or Alt+j or Alt+k but if you want to save that 1 keystroke, then adding the following to your .zshrc can help you. vi-cmd-up-line-history() { zle vi-cmd-mode zle up-line-or-history } zle -N vi-cmd-up-line-history bindkey -M vicmd '^[k' vi-cmd-up-line-history bindkey -M viins '^[k' ...


3

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


3

Playing around I got this to work: mv foo/bar/poit/zoid/narf.txt Hit Enter to store the last parameter. Now use ↑ to get last typed in line back. Enter a space and to get the last used parameter use: Alt + . I hate provoking an error, but it gets the job done in this use case.


3

One way using perl: Assuming infile has content that you pasted in your question. Content of script.pl: use warnings; use strict; use Getopt::Long; ## Check arguments. die qq[Usage: perl $0 <file> [--version=<num>] [--release=<num>]\n] unless @ARGV > 1; my ($version, $release); ## Get value of arguments. GetOptions( ...


3

Here is how you can do it if using GNU screen: Put a file called "zf" in your $PATH with: #! /usr/bin/env zsh zmodload -i zsh/zle trap 'printf "\03"; exit' INT HISTSIZE=100 while a=; vared -p "${2:-zle> }" -eh a; do { s=$(stty -g) stty -echo -iexten -isig lnext '' werase '' eof '' rprnt '' kill '' printf "%s\r" "$a" print -rs -- "$a" stty "$s" ...


3

Have you tried rlwrap sh -c 'while read line; do echo "i read $line"; done' rlwrap needs a command it can run, which a () syntax-induced subshell is not. sh -c ... is a command however. Replace sh with bash or whatever shell you prefer.


3

To deactivate the selection, run set-mark-command with a negative argument: ESC - Ctrl+Space. To copy the region and deactivate the selection, write a function that performs the two actions, then declare it as a widget with zle -N and bind that widget to a key. copy-region-as-kill-deactivate-mark () { zle copy-region-as-kill zle set-mark-command -n -1 ...



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