Typing a command like:

cat somefile
  1. Press enter and run the command.

  2. Then searching for it using ESC + k, allows me to bring it back.

I want to go back and edit the command while still typing in the prompt. From what I understand, ESC + o would allow me to type over or go back what I wrote in the command.

However, those hotkeys do not seem to work, after the initial press. Though I am however able to edit after a few key presses of the arrow keys. Is there another way to edit command in the prompt that is retrieved using ESC + k?

  • 1
    What kind of shell are you talking about? (If you are unsure have a look here) – michas Apr 21 '15 at 19:14
  • Are you using Zshell? Sounds like you have set vi mode on. – zer0rest Apr 21 '15 at 19:14
  • ksh is the shell am I referring to. – Juan Davila Apr 22 '15 at 15:28

When you get the commandline-prompt, you are ready for inserting code:
You are in the vi edit mode.
You can look up a vi manual, here some commands for the commandline:

  • ESC Leave the insert mode and enter the command mode.
  • ESC /somecommand ENTER n n Look for somecommand. n n are looking for the next twice
  • ESC wwb3w Go forward 2 words, back 1 word and forward 3 words
  • ESC dwxx Delete word and two timews 1 character
  • ESC lllcw 3 positions to the left, change word
  • ESC wrs Go forward 1 word and replace character by an s
| improve this answer | |
  • What I am referring to is the command prompt in the shell, like ksh. For example: $ cat somefile – Juan Davila Apr 22 '15 at 15:27
  • Yeah me too. The above examples all work on the command line. When you stand at the end of the line $ cat omefile and you see you forget an s, press ESC bis ENTER (Escape, 1 word back, insert, letter s and execute) – Walter A Apr 22 '15 at 17:52

Yes, There is. You can use "!!" for previous command. For Example:

$ cat file.txt
$ !! file2.txt # this will output both file.txt and file2.txt

Also you can pipe them to other commands.

$ !! | some_command  # it will pipe just previous command's output to some_commands

AND... If you want to execute 5th previous command

$ !-5

if you don't know the order of that command then,

$ history
233 cat file.txt
234 ls
235 date
$!234 # this will execute ls command
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.