Sunday, December 4, 2016

Linux: Chapter10: Text Editors





"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.
CommandUsage
/patternSearch forward for pattern
?patternSearch backward for pattern
The table describes the most important keystrokes used when searching for text in vi.
KeyUsage
nMove to next occurrence of search pattern
NMove to previous occurrence of search pattern


KeyUsage
aAppend text after cursor; stop upon Escape key
AAppend text at end of current line; stop upon Escape key
iInsert text before cursor; stop upon Escape key
IInsert text at beginning of current line; stop upon Escape key
oStart a new line below current line, insert text there; stop upon Escape key
OStart a new line above current line, insert text there; stop upon Escape key
rReplace character at current position
RReplace text starting with current position; stop upon Escape key
xDelete character at current position
NxDelete N characters, starting at current position
dwDelete the word at the current position
DDelete the rest of the current line
ddDelete the current line
Ndd or dNdDelete N lines
uUndo the previous operation
yyYank (copy) the current line and put it in buffer
Nyy or yNyYank (copy) N lines and put it in buffer
pPaste 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.
KeyUsage
emacs myfileStart emacs and edit myfile
CTRL-x iInsert prompted for file at current position
CTRL-x sSave all files
CTRL-x CTRL-w
Write to the file giving a new name when prompted
CTRL-x CTRL-sSaves the current file 
CTRL-x CTRL-cExit 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:
KeyUsage
CTRL-oInsert a blank line
CTRL-dDelete character at current position
CTRL-kDelete 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-wDelete the current marked text and write it to the buffer
CTRL-yInsert 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 viemacs 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 from within emacs.
    • vi has three modes: CommandInsert, 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