Wednesday, August 24, 2016

Edit command from the history list with vi or emacs using fc

fc command is used to edit, re-execute and list previously entered commands from the history list.

With fc you can made a quick open of your favorite editor and edit a previously entered command.

If the command you want to edit just has been resently executed just type:
fc
This open the default editor with the command to edit inside.

Execute with the option -e to choose the editor you want. For example to open with vim, execute:
fc -e vim
If you are inside the editor and you no longer want to execute the command, just quit without saving. For vim editor type :cq.
:cq 
If you want to edit a command that is some lines up of the history list, first use the option -l to show the command list with the line numbers. Then execute fc plus the line number of the command you want to edit. For example:
$ fc -l
994  ls
995  vim main.cpp 
996  set -o vi
997  clear
998  cat myexample.txt
999  cd ..
1000  set -o emacs
1001  ls -l
1002  fc -l
1003  rm 
1004  ls -l
1005  vim test.txt
1006  cd Development
1007  rm mytest
1008  fc -l
1009  mv mytest.txt sometest
$ fc -e vim 998
The former will open the vim editor with the command cat myexample.txt wainting to be edited.

Friday, August 12, 2016

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Search This Blog

Powered by Blogger.