Text Editors Vim Emacs Chapter 6 Chapter 7

  • Slides: 21
Download presentation
Text Editors Vim Emacs (Chapter 6) (Chapter 7) John Carelli, Instructor Kutztown University carelli@kutztown.

Text Editors Vim Emacs (Chapter 6) (Chapter 7) John Carelli, Instructor Kutztown University carelli@kutztown. edu 1

Unix Text Editors Two popular choices, Emacs and Vim Emacs • non-modal • no

Unix Text Editors Two popular choices, Emacs and Vim Emacs • non-modal • no separate editing mode • commands make use of key combinations (cntl, alt, …) • slower, complex, extensible Vim • “vi improved” • inherently modal • command vs. text entry modes • faster, simpler CSC 252: John Carelli Source: Dr. Lisa Frye 2

Basic operation Emacs • • to enter text, just start typing navigate with movement

Basic operation Emacs • • to enter text, just start typing navigate with movement commands • • key combinations (using cntl, alt, esc, …) additional commands to copy/paste, etc. Vim • to enter text, first enter “insert mode” • • • enter text return to “command mode” with esc key in command mode • • navigate, copy/paste, etc. basic commands are one character CSC 252: John Carelli 3

EMACS some basic commands CSC 252: John Carelli 4

EMACS some basic commands CSC 252: John Carelli 4

Emacs Cursor Movement CTRL-f forward one character CTRL-b ESC-f ESC-b CTRL-a CTRL-e CTRL-p CTRL-n

Emacs Cursor Movement CTRL-f forward one character CTRL-b ESC-f ESC-b CTRL-a CTRL-e CTRL-p CTRL-n ESC-a ESC-e CTRL-v ESC-< ESC-> Back one character Forward one word Back one word Beginning of current line End of current line Previous line Next line Beginning of current sentence End of current sentence Forward one page Back one page Beginning of buffer End of buffer CSC 252: John Carelli Source: Dr. Lisa Frye 5

CTRL-x CTRL-s Save file CTRL-x CTRL-c Exit editor CTRL-x CTRL f Open a file

CTRL-x CTRL-s Save file CTRL-x CTRL-c Exit editor CTRL-x CTRL f Open a file CTRL-h Help CTRL-_ Undo CSC 252: John Carelli Source: Dr. Lisa Frye 6

CTRL-k CTRL-y Delete line from cursor to end and puts it in kill ring

CTRL-k CTRL-y Delete line from cursor to end and puts it in kill ring (buffer) Yank kill ring contents to current position CTRL-s Search forward for word CTRL-_r Search backward for word CSC 252: John Carelli Source: Dr. Lisa Frye 7

CTRL-@ Esc-x set-mark also works; set Mark to current position ESC-w Copy region to

CTRL-@ Esc-x set-mark also works; set Mark to current position ESC-w Copy region to kill ring (buffer) CTRL-w Cut region and paste in kill ring (buffer) CSC 252: John Carelli Source: Dr. Lisa Frye 8

CTRL-x CTRL-b Open a new window CTRL-x b Switch to named window CTRL-x 2

CTRL-x CTRL-b Open a new window CTRL-x b Switch to named window CTRL-x 2 Split window into 2 horizontally CTRL-x 3 Split window into 2 vertically CTRL-x o Switch to the other window CTRL-x 0 Close current window CSC 252: John Carelli Source: Dr. Lisa Frye 9

Esc-l Convert word to lowercase Esc-u Convert word to uppercase Esc-c Convert word to

Esc-l Convert word to lowercase Esc-u Convert word to uppercase Esc-c Convert word to initial caps CTRL-x CTRL-l Convert region to lowercase CTRL-x CTRL-u Convert region to uppercase CSC 252: John Carelli Source: Dr. Lisa Frye 10

CTRL-x ( Start recording a macro CTRL-x ) Stop recording a macro CTRL-e Run

CTRL-x ( Start recording a macro CTRL-x ) Stop recording a macro CTRL-e Run the macro Esc-# CTRL-e Run the macro # times CSC 252: John Carelli Source: Dr. Lisa Frye 11

Vim some basic commands CSC 252: John Carelli 12

Vim some basic commands CSC 252: John Carelli 12

Vim Modes Typically starts in “command mode” • keystrokes are interpreted as commands •

Vim Modes Typically starts in “command mode” • keystrokes are interpreted as commands • edit, navigate, etc. “Insert mode” • enter with insert command • esc key • return to command mode Some Insert Commands i before current location a after current location I at beginning of line A at end of line o new line below O New line above Note: vim is based on vi, which was based on ed (more on ed here) CSC 252: John Carelli Source: Dr. Lisa Frye 13

Vim Cursor Movement l forward one character h w b ^ $ Enter k

Vim Cursor Movement l forward one character h w b ^ $ Enter k Back one character Forward one word Back one word Beginning of current line End of current line Beginning of next line Character above j e CTRL-f CTRL-b Character below End of word Forward one page Back one page CSC 252: John Carelli 14

: w Save file : wq (or ZZ) Save file and exit : q!

: w Save file : wq (or ZZ) Save file and exit : q! Exit without saving : e name Open a file : help Help u Undo r redo CSC 252: John Carelli Source: Dr. Lisa Frye 15

d$ p Delete line from cursor to end and put it in buffer Paste

d$ p Delete line from cursor to end and put it in buffer Paste buffer contents to current position /word Search forward for “word” ? word Search backward for word CSC 252: John Carelli Source: Dr. Lisa Frye 16

ma set Mark “a” to current position (can use any letter to set multiple

ma set Mark “a” to current position (can use any letter to set multiple marks) c’a Copy lines from present location to the mark into the buffer d’a Delete lines from present location to the mark and store in the buffer v Highlight a region by moving the cursor (subsequent commands work on the highlighted text) esc Remove highlighting CSC 252: John Carelli Source: Dr. Lisa Frye 17

CTRL-w CTRL-s (or : sp) CTRL-w Split window into 2 horizontally CTRL-w CTRL-v Split

CTRL-w CTRL-s (or : sp) CTRL-w Split window into 2 horizontally CTRL-w CTRL-v Split window into 2 vertically : q Close current window CSC 252: John Carelli Cycle through open windows Source: Dr. Lisa Frye 18

~ Switch case u Make highlighted text lowercase U Make highlighted text uppercase CSC

~ Switch case u Make highlighted text lowercase U Make highlighted text uppercase CSC 252: John Carelli Source: Dr. Lisa Frye 19

qa q Start recording macro “a” (can use any letter to record multiple macros)

qa q Start recording macro “a” (can use any letter to record multiple macros) Stop recording a macro @a Run macro “a” @@ Rerun last macro #@a Run the macro # times CSC 252: John Carelli Source: Dr. Lisa Frye 20

Initialization files Customize editor behavior § located in home directory §. emacs file §.

Initialization files Customize editor behavior § located in home directory §. emacs file §. vimrc file Key Mappings Colors Default behavior etc… CSC 252: John Carelli Source: Dr. Lisa Frye 21