0

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?

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

2 Answers 2

0

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
2
  • What I am referring to is the command prompt in the shell, like ksh. For example: $ cat somefile Apr 22, 2015 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, 2015 at 17:52
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .