Week 5 Notes
Command Line Editors
Working with text files in the terminal
Editors
Line Editors (Present in almost every flavour of UNIX / GNU Linux)
edex(improved version of ed)
Terminal Editors
pico(Came along with the pine email application)nano(Features added to pico)
vi(most popular and complex)emacs
GUI Editors
KDE
katekwrite
GNOME
gedit
sublime
atom (popular among github users)
brackets (Popular for those writing html code)
IDE
eclipse
Bluefish
NetBeans
Features of text editors
Scrolling , view modes, current position in file
Navigation (char,word,line,pattern)
Insert, Replace, Delete
Cut-Copy-Paste
Search-Replace
Language-aware syntax highlighting
Key-maps, init scripts, macros
Plugins
Both
viandemacseditors satisfy all the above requirements
ed commands
Action |
Command |
|---|---|
Show the Prompt |
|
Command Format |
|
Commands for location |
|
Commands for editing |
|
Execute a Shell command |
|
edit a file |
|
read file contents into buffer |
|
read command output into buffer |
|
write buffer to filename |
|
quit |
|
Using ed
man eddoesn’t give much info . Useinfo eded test.txtshows a number indicating number of bytes read into memory1displays the first line$displays the last line,pand%pshows the contents of the entire buffer2,3prange - 2nd to 3rd line/hello/matches and shows first occurance of the pattern+and-to scroll by line;pfrom current position to end of buffer.displays the current line!daterunning the date command withinedr !dateread output of date command to buffer at current positionwwrites the file (saves it)ddelete current lineato append after current line. Press.andenterwhen dones/appended/Appended/Substitute - Search and replace from current line.fshows the name of the file being editedpshows the contents of the current linejfor joining lines . Usage5,6jto join line 5 and 6mto move a line to a particular position. Usagem1to move current line to just below line 1.m0to move it right to the toputo undo previous changeTo add something to every line
%s/\(.*\)/PREFIX \1/\1is the back substitution\(.*\)indicates any character that can be matchedPREFIXis the replacement string
3,5s/PREFIX/prefix/substitutes prefix for PREFIX from line 3 to 5
Commands for editing in ed / ex
Command |
Action |
|---|---|
f |
show name of file being edited |
p |
print the current line |
a |
append at the current line |
c |
change the line |
d |
delete the current line |
i |
insert line at the current position |
j |
join lines |
s |
search for regex pattern |
m |
move current line to position |
u |
undo latest change |