Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use vi to edit a command in terminal on Linux?

When typing a very long command, I'd like to first edit the command in a text editor(e.g. vi) then execute in case of typos. Is there a way to edit the command directly in a terminal and run instead of invoke vi by typing vi then type the command?

like image 550
lil Avatar asked Mar 26 '14 08:03

lil


People also ask

How do I edit text in vi?

Press the Insert or I key on your keyboard, and then move the cursor to the location where you want to edit. 4. Modify the file based on your needs, and then press the Esc key to exit the input mode.

What is vi editor command in Linux?

The default editor that comes with the UNIX operating system is called vi (visual editor). Using vi editor, we can edit an existing file or create a new file from scratch. we can also use this editor to just read a text file. Syntax: vi filename.


1 Answers

If you're using bash, try the edit-and-execute-command command. By default, this is assigned to Ctrl-x Ctrl-e (type ctrl-x, then ctrl-e).

This should open whatever editor is specified in your environment. Whatever is in the buffer when you exit will execute in the shell - including multiple-line commands.

like image 59
Ian Petts Avatar answered Oct 06 '22 01:10

Ian Petts