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)
ed
ex
(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
kate
kwrite
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
vi
andemacs
editors 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 ed
doesn’t give much info . Useinfo ed
ed test.txt
shows a number indicating number of bytes read into memory1
displays the first line$
displays the last line,p
and%p
shows the contents of the entire buffer2,3p
range - 2nd to 3rd line/hello/
matches and shows first occurance of the pattern+
and-
to scroll by line;p
from current position to end of buffer.
displays the current line!date
running the date command withined
r !date
read output of date command to buffer at current positionw
writes the file (saves it)d
delete current linea
to append after current line. Press.
andenter
when dones/appended/Appended/
Substitute - Search and replace from current line.f
shows the name of the file being editedp
shows the contents of the current linej
for joining lines . Usage5,6j
to join line 5 and 6m
to move a line to a particular position. Usagem1
to move current line to just below line 1.m0
to move it right to the topu
to undo previous changeTo add something to every line
%s/\(.*\)/PREFIX \1/
\1
is the back substitution\(.*\)
indicates any character that can be matchedPREFIX
is 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 |