Text Editors Vim (Chapter 6) Emacs (Chapter 7) John Carelli, Instructor Kutztown University carelli@kutztown.edu
Unix Text Editors Two popular choices, Emacs and Vim Emacs Vim 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
Basic operation Emacs Vim 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
EMACS some basic commands
Emacs Cursor Movement CTRL-f forward one character CTRL-b Back one character ESC-f Forward one word ESC-b Back one word CTRL-a Beginning of current line CTRL-e End of current line CTRL-p Previous line CTRL-n Next line ESC-a Beginning of current sentence ESC-e End of current sentence CTRL-v Forward one page ESC-v Back one page ESC-< Beginning of buffer ESC-> End of buffer
CTRL-x CTRL-s Save file CTRL-x CTRL f Open a file CTRL-h Help CTRL-_ Undo
CTRL-k Delete line from cursor to end and puts it in kill ring (buffer) CTRL-y Yank kill ring contents to current position CTRL-s Search forward for word CTRL-_r Search backward for word
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)
CTRL-x CTRL-b Open a new window CTRL-x b Switch to named window CTRL-2 Split window into 2 horizontally CTRL-3 Split window into 2 vertically CTRL-x o Switch to the other window CTRL-x 0 Close current window
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
CTRL-x ( Start recording a macro CTRL-x ) Stop recording a macro CTRL-e Run the macro Esc-# CTRL-e Run the macro # times
Vim some basic 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 Note: vim is based on vi, which was based on ed (more on ed here) 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
Vim Cursor Movement l forward one character h Back one character w Forward one word b Back one word ^ Beginning of current line $ End of current line Enter Beginning of next line k Character above j Character below e End of word CTRL-f Forward one page ESC-b Back one page
: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
d$ Delete line from cursor to end and put it in buffer p Paste buffer contents to current position /word Search forward for “word” ?word Search backward for word
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
CTRL-w CTRL-s (or :sp) Split window into 2 horizontally CTRL-w CTRL-w Cycle through open windows CTRL-w CTRL-v Split window into 2 vertically :q Close current window
~ Switch case u Make highlighted text lowercase U Make highlighted text uppercase
qa Start recording macro “a” (can use any letter to record multiple macros) q Stop recording a macro @a Run macro “a” @@ Rerun last macro #@a Run the macro # times
Initialization files Customize editor behavior located in home directory .emacs file .vimrc file Key Mappings Colors Default behavior etc…