"Programmer is like an artist. His favorite paintbrushes may be different.."
******************** Special Thanks ********************
Me, Myself
***************************************************
SECTION 1 Text editors in Linux
When you stand in front of console and are gonna write some poetries in the files and you have to use these text editors to modify the files instead using other remote editors like Notepad, EditPlus and so on.
This terminal shows you how to add texts in file without using any text editor.
Since gedit and vim can't be installed and the artist might be laz.. Therefore, he shows you nano and vi respectively. GNOME extends vi with a very graphical interface known as gvim and KDE offers kvim.
↞ vi section ↠
These 2 clips show you how to use vi and please find more details when to use :wq!
Searching for Text in vi
The table describes the most important commands used when searching for text in vi. The ENTER key should be pressed after typing the search pattern.
Command | Usage |
/pattern | Search forward for pattern |
?pattern | Search backward for pattern |
The table describes the most important keystrokes used when searching for text in vi.
Key | Usage |
n | Move to next occurrence of search pattern |
N | Move to previous occurrence of search pattern |
Key | Usage |
a | Append text after cursor; stop upon Escape key |
A | Append text at end of current line; stop upon Escape key |
i | Insert text before cursor; stop upon Escape key |
I | Insert text at beginning of current line; stop upon Escape key |
o | Start a new line below current line, insert text there; stop upon Escape key |
O | Start a new line above current line, insert text there; stop upon Escape key |
r | Replace character at current position |
R | Replace text starting with current position; stop upon Escape key |
x | Delete character at current position |
Nx | Delete N characters, starting at current position |
dw | Delete the word at the current position |
D | Delete the rest of the current line |
dd | Delete the current line |
Ndd or dNd | Delete N lines |
u | Undo the previous operation |
yy | Yank (copy) the current line and put it in buffer |
Nyy or yNy | Yank (copy) N lines and put it in buffer |
p | Paste at the current position the yanked line or lines from the buffer. |
Below is result after pressing Enter of command :%s/line/LINE NO./
↞ emacs section ↠
The table lists some of the most important key combinations that are used when starting, exiting, reading, and writing files in emacs.
Key | Usage |
emacs myfile | Start emacs and edit myfile |
CTRL-x i | Insert prompted for file at current position |
CTRL-x s | Save all files |
CTRL-x CTRL-w | Write to the file giving a new name when prompted |
CTRL-x CTRL-s | Saves the current file |
CTRL-x CTRL-c | Exit after being prompted to save any modified files |
The emacs tutorial is a good place to start learning basic emacs commands. It is available any time when in emacs by simply typing CTRL-h (for help) and then the letter t for tutorial.
The table lists some of the key combinations used for changing, adding, and deleting text in emacs:
Key | Usage |
CTRL-o | Insert a blank line |
CTRL-d | Delete character at current position |
CTRL-k | Delete the rest of the current line |
CTRL-_ | Undo the previous operation |
CTRL- (space or CTRL-@) | Mark the beginning of the selected region. The end will be at the cursor position |
CTRL-w | Delete the current marked text and write it to the buffer |
CTRL-y | Insert at current cursor location whatever was most recently deleted |
↞ Summary ↠
- Text editors (rather than word processing programs) are used quite often in Linux, for tasks such as for creating or modifying system configuration files, writing scripts, developing source code, etc.
- nano is an easy-to-use text-based editor that utilizes on-screen prompts.
- gedit is a graphical editor very similar to Notepad in Windows.
- The vi editor is available on all Linux systems and is very widely used. Graphical extension versions of vi are widely available as well.
- emacs is available on all Linux systems as a popular alternative to vi. emacs can support both a graphical user interface and a text mode interface.
- To access the vi tutorial, type vimtutor at a command line window.
- To access the emacs tutorial type Ctl-h and then t from within emacs.
- vi has three modes: Command, Insert, and Line; emacs has only one but requires use of special keys such as Control and Escape.
- Both editors use various combinations of keystrokes to accomplish tasks; the learning curve to master these can be long but once mastered using either editor is extremely efficient.
Reference:
{陳爱平 KevinChen} - JAYz
No comments:
Post a Comment