aos linux tutorial
play

AOS Linux Tutorial Editors: Emacs and Vim Michael Havas Dept. of - PowerPoint PPT Presentation

AOS Linux Tutorial Editors: Emacs and Vim Michael Havas Dept. of Atmospheric and Oceanic Sciences McGill University October 5, 2010 Outline 1 Text Editors 2 VIM 3 EMACS 4 Next Time Text Editors Why text? Everything is text! Code. Email.


  1. AOS Linux Tutorial Editors: Emacs and Vim Michael Havas Dept. of Atmospheric and Oceanic Sciences McGill University October 5, 2010

  2. Outline 1 Text Editors 2 VIM 3 EMACS 4 Next Time

  3. Text Editors Why text? Everything is text! Code. Email. The web. Configuration files. Papers.

  4. Text Editors A Full Hour? Only an hour? Fancy text editors: Move code around. Help you write code faster. Reduce errors. Integrate with other tools. Have a steep learning curve with great benefits.

  5. Text Editors Plan Text or Word Processors A plain text file is represented and edited by showing all the characters as they are present in the file. Documents created by a word processor generally contain fileformat-specific control characters. Don’t use MS Word or OO Writer to edit plain text files.

  6. Text Editors Features Search and replace. Cut, copy and paste. Undo and redo. Syntax highlighting. Clever automatic indentation. Jump to definitions of functions. Code folding.

  7. Text Editors Tips Use search tool instead of moving the cursor. Don’t use the mouse. Be one with the editor. Learn the basics of regular expressions for search and replace. Integrate your editor with your tools. Find a plugin for your specific language.

  8. Outline 1 Text Editors 2 VIM 3 EMACS 4 Next Time

  9. VIM What’s a vim? An extension to Bill Joy’s VI text editor written by Bram Moolenaar in 1991. Benefits? KISS. Small in size. Fast. Runs everywhere. Is everywhere.

  10. VIM Modes Vim has multiple modes: Normal-Mode For entering keyboard-shortcuts to manipulate text. Insert-Mode For typing text into the text file. Command-Line-Mode For issuing a command via the command-line. Prefixed by :. Always be in Normal-Mode. Esc goes to Normal-Mode

  11. VIM Quitting Quitting :q Quit. :q! Quit and don’t warn me about saving. :wq Save and quit.

  12. VIM Moving the Cursor Character-by-Character h Left. j Down. k Up. l Right. By more than one character e End of word. b Beginning of word. w Next word. :n Go to line n .

  13. VIM Inserting Text Steps Move your cursor. Press i to enter insert-mode. Type text. Press Esc to go back into normal-mode. More advanced Replacing i with the following leads to more advanced techniques: Press a to insert text after the cursor (append). Press I to insert at the beginning of a line. Press A to append at the end of a line.

  14. VIM Deleting Text Deleting Text x Delete character. dw Delete word. dd Delete the whole line. d$ Delete until the end of the line. ˆ Delete until the beginning of the line. dap Delete a paragraph. dtX Deletes to the character ’X’. di” Deletes content inside quotes. di) Deletes content inside parentheses.

  15. VIM Operators, motions and counts Most operations can apply on motions. Ex: d (delete) can apply on motion: w Word. $ End of line. ˆ Beginning of line. ap A paragraph. tX to character X. i) In parentheses. i > In angled brackets. i” In quotes. Operators can also take a numerical argument. Ex: d5w deletes five words.

  16. VIM Undo, Redo and Repeat Undo and Redo u Undo U Undo changes on whole line. Ctrl-R Redo. :earlier 10m Go back in time 10 minutes. :later 10m Go forward in time 10 minutes. Repeat . Repeats the last command. Really useful!

  17. VIM Visual-Mode Visual mode v Enter visual mode. V Enter visual mode selecting rows. Ctrl-v Enter visual mode selecting columns. Operators can act on selected text

  18. VIM Cut, Copy, Paste y Yank (Copy). d Delete (Cut). p Put (Paste). P Put above.

  19. VIM Changing Text Command: c Deletes motion and puts vim in insert mode.

  20. VIM Search Searching / Search forward. ? Search backward. * Search for word under cursor. n Repeat search. Use regular expressions. Examples of regular expressions Some examples: ˆabc Word “abc” at the beginning of the line. abc$ Word “abc” at the end of a line. abc.* Word “abc” followed by any number of characters.

  21. VIM Search Searching / Search forward. ? Search backward. * Search for word under cursor. n Repeat search. Use regular expressions. Examples of regular expressions Some examples: ˆabc Word “abc” at the beginning of the line. abc$ Word “abc” at the end of a line. abc.* Word “abc” followed by any number of characters.

  22. VIM Substitution Substitution :s/blah/foo Substitute first occurrence of blah for foo on the line. :s/blah/foo/g Substitute every occurrence of blah for foo on the line. :%s/blah/foo/ Substitute ever occurrence of blah for foo in the file. Useful with visual-mode. Use regular expressions.

  23. VIM Getting Help :help Open the help window. :help command Get help on command .

  24. VIM Configuration Configuration file: ∼ /.vimrc : """ General """ s e t nocompatible "get out of vi-compatible mode filetype on " detect the type of f i l e s e t h i s t o r y =1000 " lines of history to remember filetype plugin on " load f i l e t y p e p l u g i n s s e t showmatch " Show matching parentheses. Configuration directory: ∼ /.vim/ : Setup backup directories here. Install your vim plugins here.

  25. VIM Useful Plugins vim-latex Makes editing L A T EX a breeze. http://vim-latex.sourceforge.net/ Surround Provides mappings to easily delete, change and add such surroundings in pairs. http://www.vim.org/scripts/script.php? script_id=1697 Snipmate Provides text-mate like snippets to vim. http://www.vim.org/scripts/script.php? script_id=2540

  26. Outline 1 Text Editors 2 VIM 3 EMACS 4 Next Time

  27. EMACS What’s an EMACS? A text editor which began development in the mid-70s whose development continues today originally as Editor MACros. What are its benefits? Everything at reach. Larger set of features than vi. Extensible and customizable. Can emulate vi.

  28. EMACS Preliminaries Emacs does not have vim-like modes. Emacs has lots of keybindings: Control (C) The control key. Meta (M) The alt key.

  29. EMACS Moving Around Character-by-Character C-f Forward. C-b Back. C-p Previous line. C-n Next line. Word-by-Word M-f Forward one word. M-b Back one word.

  30. EMACS Moving Around Line-by-Line C-a Beginning of line. C-e End of line. Sentence-by-Sentence M-a Beginning of a sentence. M-e End of a sentence. Page-by-Page C-v Page forward. M-v Page backward.

  31. EMACS Numeric/Prefix Arguments Most Emacs commands can take alternate or numeric arguments. For example: C-u 4 * Insert 4 “*”s. C-u 4 M-f Move forward 4 words. C-4 M-f Shortcut: Move forward 4 words. C-u M-f Shortcut: Move forward 4 words.

  32. EMACS Terminology Frame Similar to the concept of a Window in regular graphical user interfaces. Window Sections of the frame that display buffers. Buffer Contains text normally representing a file. Mini-Buffer The last line of emacs designated for entering commands.

  33. EMACS File Operations File Operations C-x C-s Save file. C-x s Prompt to save each buffer. C-x C-f Find/Open file. C-x C-c Quit.

  34. EMACS Window Operations Window Operations C-x 3 Split the current window vertically. C-x 2 Split the current window horizontally. C-x 1 Close all windows but current. C-x o Go to next window. C-M-v Move down a page in the other window. C-M-V Move up a page in the other window.

  35. EMACS When Things Go Bad If emacs becomes unresponsive C-g C-g C-g Or, if you are in recursive-editing mode Esc Esc Esc

  36. EMACS Deleting and Killing Deleting does not copy text to kill-ring C-d Delete character. M-d Delete word. M- backspace Delete word backwards. Kill is like cut C-k Kill from point to end of line. M-k Kill from point to end of sentence. Highlight copy/cut Set mark by C- spc . Move point. To cut: C-w To copy: M-w

  37. EMACS Yanking Text and Undo Yanking text All killed text is placed in the kill-ring. To yank/paste back most recent kill: C-y To yank back earlier kill: M-y Undo C- is undo.

  38. EMACS Buffer Management A window can switch the buffer it is displaying. C-b Switch buffer. C-x b List buffers. C-x k Close buffer.

  39. EMACS Search and Replace Search C-s Search forward. C-r Search in reverse. Replace M-% Query-Replace String. Recursive Editing While query-replacing string, C-r to enter a recursive edit. Do work. Leave the recursive edit using C-M-c .

  40. EMACS Modes Modes affect the operation of emacs. major-mode Only one major-mode can be active at a time. minor-mode Many minor-modes may be active at once. Can change modes using M-x mode .

  41. EMACS Useful Modes Minor Modes: flyspell Check spelling on-the-fly auto-fill Automatic indenting. Major Modes: org-mode An organizational mode (AMAZING!) latex-mode A mode for writing L A T EX. http://www.gnu.org/software/auctex/ dired A mode for file management. gnus An email/news/rss client. fortran-mode A mode for fortran. To find out more information about a mode, switch to the mode and hit M-x describe-mode .

  42. EMACS Getting Help Help! C-h Main help. Use ? for all options. C-h c Quick info on a shortcut key. Displays in minibuffer. C-h k In depth info on a shortcut key. C-h f In depth info on a function. C-h a Looks up all command names that contain keyword. Online! http://www.emacswiki.org/

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend