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

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.


7

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


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

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


6

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


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

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


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

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

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


3

I have found it out now. I should have read it more carefully before asking this. The man page says: edit-and-execute-command (C-xC-e) Invoke an editor on the current command line, and execute the result as shell commands. Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order.


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

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


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

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


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

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


2

If $X is the parameter where the new version is stored, ed file << EOF g/^version =/s/.*/version = '$X'/ g/^release =/s/.*/release = '$X'/ w q EOF This assumes $X has a reasonable value, like 1.2.3-foo, and no characters that are special to the ed command interpreter.


2

rlwrap needs a program to execute, it can't interpret the commands itself. You can wrap the shell code you want in a bash -c command: rlwrap bash -c 'while read line; do echo "line: $line"; done' Note that depending on what code you want to use for this, the quoting could become somewhat ugly.


2

I don't know who's "responsible" for that Alt+d behavior: I don't know if it's the terminal or if it's the shell (Bash in my case). It's bash, specifically the default command-line editing setup. Here is a nice page on what commands can be bound, and how to change the default bindings. The default binding for Alt-d is kill-word which is supposed to ...


2

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


2

By default shells are in emacs mode. Pressing alt+B will send the cursor back one word on the command line. Pressing alt+F will send the cursor forward. Running bindkey -v will switch to vi mode. You'll need to press esc then vi commands will work. Running bindkey -e will switch to emacs mode.


2

Zsh's autocorrection only has limited configurability, but this should be enough for your use case. Set the CORRECT_IGNORE variable to match the strings you want to ignore in autocorrection. CORRECT_IGNORE='.build' (I'm assuming you aren't using correct_all. With correct_all, I think being endlessly prompted about things that don't need correcting is ...


2

This will enable completion on plain mysql server: mysql --auto-rehash For rlwrap, check if you have RLWRAP_HOME set. See here for more info. The page also reports possible race conditions if your system is too busy.


2

If you ran the command itself by mistake, in emacs editing mode you can use up-arrow to move to the last command, and edit it to a new command undoing the mistake. But note that not all commands can be cleanly undone, perhaps installing those packages installed others as dependencies or made other changes. Depending on the exact commands (here package ...



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