EMACS AS TEXT EDITOR

deepak kathuria
5 min readOct 17, 2021

The Emacs editor is the very versatile and powerful editor and it understand a LISP which is commonly used language for artificial intelligence programming. It is one of the oldest programming languages still in relatively wide use.Lets take example let say we invent a new programming language and we want to code in this programming language using Emacs but as its a new language so Emacs does not know about it ,so we can write a small LISP program as package and we can load this package to Emacs as we know Emacs Understand LISP so after adding package to Emacs then Emacs can Understand our programming language we would not need to update its binary to be able to code in this programming language

Unlike the vi editor, the Emacs editor does not use an insert mode, and it is by default in editing mode, i.e., whatever you type will directly be written to the buffer, unless you manually enter command mode by using keyboard shortcuts.

1.                sudo apt-get install emacs2.                emacs3                 emacs --version
  • 1. to install emacs
  • 2. to open emacs
  • 3. to check emacs version
emacs open after typing emacs
1.                        emacs new.txt2.                        ctrl+x ctrl+f3.                        ctrl+x s4                         ctrl+x ctrl+s5                         ctrl+s ctrl+w6                         ctrl+x ctrl+c
  1. It creates a file called new.txt if it doesn’t already exist
  2. opens a file, asks for filename if it can’t find file it creates the file
  3. save the file with prompt
  4. save file without prompt
  5. save file with different name it will asks for name(not work in me)
  6. for quits emacs and asks for save
creted file with new.txt

Everytime you save a file, Emacs creates another file with the name “filename~” .This (~) file is the previous version of the file. It will be in the same dir. Also, Emacs auto-saves everything you type to a file with the name “#filename#”. If you quit Emacs without saving, you can see this auto-save file. I can show this with help of images

  1. I created file new (name of file ) with help of above command
new(name of file)
terminal from which i am using emacs

2. I will quit from emacs and save the file using above commands and run ls in terminal

ls

3. Now I open same file and edit and then save the changes

edit the file with “bbbbbbb” and save changes

4. I quit the emacs and then do ls command

(new) -> new version and (new~)->previous version

so ,everytime you save a file, Emacs creates another file with the name “filename~” which is previous version.

5. If you want to see difference between the two version the do

diff <filename> <filename2>diff new new~
diff between two files

OTHER SCENARIO

1.In this now i created file called blob and i will exit withou saving from emacs

2. now do ls in terminal

#blob# auto save file created

Emacs auto-saves everything you type to a file with the name “#filename#” if you save emacs without saving

MORE COMMNADS

1.                       Ctrl+k2.                       ctrl+y3.                      ctrl+space
|
4. ctrl+M w
5. ctrl+w6. ctrl+a7. ctrl+e8. ctrl+/9. esc+>10. esc+<

Saving a region involves hitting ctrl+space to start selecting ,and then hitting M-w or C-w to copy or cut it into the clipboard, and then hitting ctrl+y to paste it. If you don`t like the region you are selecting,hit ctrl+g.

“ctrl+a “ move cursor to the beginning of line

“ctrl+e” move cursor at the end of line

EXECUTION

file with cursor at e

ctrl+k

ctrl+k delete word in 1 line after cursor

ctrl +y

i will just copy “ctrl+y” text in this blog and then paste using ctrl +y in my file

ctrl+y is my copying text

ctrl + space

mark up activate i selected these 4 lines

ctrl+m w

for copying these 4 and to see output paste using ctrl +y

paste 4 times selected using ctrl+ space(markup) copying using ctrl+m w and then paste using ctrl+y

ctrl+a

my cursor is at the end

when i press ctrl+a cursor comes into beginning as shown

ctrl+e

it moves the cursor to the end of line

ctrl+/

it is like undo

esc+> and esc+<

is used for moving at the beginning and end of the file

SO THESE ARE SOME BASIC COMMANDS TO USE EMACS

--

--