CLI Editors 2
CLI Editors 2
Type 📒 Lecture
Date @February 22, 2022
Lecture # ?
Lecture
URL
Notion https://21f1003586.notion.site/CLI-Editors-
URL 77dfbc4e33a9426498d94207eaea1962
Week # 5
CLI Editors 1
Features
Scrolling, view modes, current position in the file
Cut-Copy-Paste
Search-Replace
Plugins
ed
CLI Editors 2
Command Format → [starting-address[,ending-address]command[command-parameters]]
press % → refers to all the lines, i.e. any action we are doing applies to all the
lines
press , (comma) → represent the entire buffer, i.e. the whole file
press ; (semicolon) → refers the end of the text file from the current position
and it shows the number of bytes in the file, instead of the contents of the file ... ayo
wut
CLI Editors 3
CLI Editors 4
CLI Editors 5
Run a bash command, read the bash command’s output and write it to the file
Delete the last line of the file and write the changes to the file
CLI Editors 6
Append a line to the file (press . then enter to exit)
File name
CLI Editors 7
Print the current line
Move the current line after the given line # (We are moving the current line below
line 1 here)
CLI Editors 8
Add a prefix to all the lines and then modify the prefix on some lines
ed/ex commands
CLI Editors 9
readlink
Prints the resolved symbolic links or canonical file names, but what does that mean?
If we have file which is a symbolic link to file which in turn is another symbolic link to
a file and so on ...
The readlink command will display the actual file the initial symbolic link is referring
to
Example usage
readlink -f /usr/bin/pico
Output
/usr/bin/nano
.bashrc
nano
CLI Editors 10
CLI Editors 11
CLI Editors 12
CLI Editors 13
CLI Editors 14
CLI Editors 15
Source: https://www.nano-editor.org/dist/latest/cheatsheet.html
Modes in vi editor
i will insert the characters from the current position of the cursor
CLI Editors 16
a will append the text
vi help
These work only in the Command mode
To exit out of vi
:w → write out
If nothing else works, cry and smash your keyboard, and then rage quit
vi command mode
Screen manipulation
CLI Editors 17
Ctrl + D → Scroll down half screen
Moving around
Changing text
cw → Change word under the cursor, from the current character till Esc
Ncc → Change the next N lines, starting from the current till Esc
Deleting text
CLI Editors 18
dNw → Delete N words, from the character under the cursor
D → Delete the rest of the line, from the character under the cursor
Ndd → Delete the next N lines, starting from the current one
Nyy → Copy the next N lines, including the current, into the buffer
Searching text
emacs
Moving around
CLI Editors 19
C-n → Move down by one line
Source: https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf
emacs commands
Exiting emacs
Searching a text
CLI Editors 20
Syntax for emacs → emacs -nw filename
Make sure to pass the -nw flag to make it open in terminal mode instead of the GUI
CLI Editors 21