vim vi improved a programmers text editor
play

vim Vi IMproved, a programmers text editor Bart Van Loon 31st - PowerPoint PPT Presentation

Introduction Getting started with vim Tasks Search and replace Configuration vim Vi IMproved, a programmers text editor Bart Van Loon 31st January 2012 1 / 30 Bart Van Loon vim Vi IMproved, a programmers text Introduction Getting


  1. Introduction Getting started with vim Tasks Search and replace Configuration vim – Vi IMproved, a programmers text editor Bart Van Loon 31st January 2012 1 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  2. Introduction Getting started with vim Tasks Search and replace Configuration 1 Introduction 2 Getting started with vim Introduction Starting and quitting The cursor Editing text 3 Tasks 4 Search and replace 5 Configuration 2 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  3. Introduction Getting started with vim Tasks Search and replace Configuration How it all began: vi A part of history ◮ text editor originally created for UNIX ◮ old: first release in 1976 (Open Source: BSD license) ◮ but modern: 2009 survey by Linux Journal → vi[m] most widely used text editor (36%); second place: gedit (19%) 3 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  4. Introduction Getting started with vim Tasks Search and replace Configuration How it all began: vi Modal editor ◮ vi is a modal editor: insert mode: typed text becomes part of the document normal mode: keystrokes are interpreted as commands i in normal mode: switch to insert mode; i again at this ◮ point: place an “i” character in the document esc in insert mode: switch to normal mode ◮ ◮ advantage : both text editing and command operations without requiring removal of hands from the home row ⇒ speed ! 4 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  5. Introduction Getting started with vim Tasks Search and replace Configuration How it all began: vi It breaks my fingers! Many ideas, shortcuts, keystrokes, . . . can be explained by looking at a common computer keyboard from the seventies. 5 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  6. Introduction Getting started with vim Tasks Search and replace Configuration How it all began: vi Contemporary derivatives and clones vi : traditional vi ported to modern systems vim : (“Vi IMproved”) vi with many more features elvis : once popular clone with some extra features nvi : default derivative shipped with all BSDs vile : attempt to mix emacs and vi . . . 6 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  7. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration vim Introduction ◮ first released publicly in 1991 (Open Source charityware) ◮ still actively developed and maintained ◮ cross platform ◮ additional features specifically designed for editing source code ◮ customisable through plugins and vimscript ◮ described as “very much compatible with vi ”, but not 100% ◮ huge community constantly at war with the emacs -community 7 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  8. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration vim Sooooooo many features completion, comparison and merging of files, comprehensive integrated help system, extended regular expressions, scripting languages (both native and through alternative scripting interpreters such as Perl, Python, Ruby, Tcl, etc. . . ) including support for plugins, a graphical user interface, limited integrated development environment-like features, mouse interaction (both with and without the GUI), folding, editing of compressed or archived files in gzip, bzip2, zip, and tar format and files over network protocols such as SSH, FTP, and HTTP, session state preservation, spell checking, split (horizontal and vertical) and tabbed windows, unicode and other multi-language support, syntax highlighting, trans-session command, search and cursor position histories, multiple level undo/redo history which can persist across editing sessions, visual mode, . . . 8 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  9. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Getting started Starting vim ◮ vim ; or ◮ vim < filename > ; or ◮ vim [options] < filename > One useful option is + < n > , which opens the file and immediately puts the cursor on line < n > . 9 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  10. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Getting started Modes ◮ by default you start in normal mode ◮ go to insert mode from normal mode type i to start entering text at the cursor type R to start replacing text at the cursor type o to open a new line at the cursor type O to open a new line above the cursor ◮ hit esc to enter normal mode 10 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  11. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Getting started Exiting vim ◮ commands to quit: : save and quit : x ← ֓ : q ← : just quit ֓ : q ! ← : force quit (without saving!) ֓ ◮ shortcut from normal mode: Z Z : quit and save only if changes were made 11 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  12. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Moving the cursor Relative movements: : one character left h j : one line down : one line up k : one character right l : one word forward w b : one word back Adding a digit multiplies the movement. Try 5 w , 1 2 k , 2 b , . . . 12 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  13. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Moving the cursor Absolute movements in the file: ^ or 0 : beginning of the line $ : end of the line g g : beginning of the file : end of the file G : line < d > < d > G ` . : your last edit 13 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  14. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Moving the cursor Absolute movements in the screen (visible area): : highest line on the screen H : middle line on the screen M : lowest line on the screen L ctrl-f : page (screen) forward : page (screen) backward ctrl-b 14 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  15. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Editing text Inserting text: i : insert text at the cursor : insert text after the cursor (append) a : insert text at the beginning of the line I : insert text at the end of the line A In insert mode, you can use the arrow keys to navigate the cursor, but often going back to normal mode will be much faster. 15 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  16. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Editing text Deleting text: : delete character at the cursor (delete) x X : delete character before the cursor (backspace) Replacing text: : replace the current character with < c > r < c > 16 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  17. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Visual mode For selecting areas of text, there is visual mode: : start visual mode v V : start visual line mode ctrl-v : start visual block mode 17 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  18. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Operators and motions Example operators: : delete d : yank (copy) y c : change Example motions 1 : : to end of line $ G : to end of file : to end of current word e 1 remember the part on “moving your cursor”? 18 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  19. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration Combining operators and motions Combining operators and motions generates some really powerful commands. Some examples are: : copy from the cursor until the end of the line y $ d g g : delete from the cursor until the beginning of the file Now lets add counts to increase the power: y 3 k : copy the previous 3 lines : delete the next 5 words d 5 w 19 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

  20. Introduction Introduction Getting started with vim Starting and quitting Tasks The cursor Search and replace Editing text Configuration More power Another nice operator: = : fix indenting Some other nice motions: ( : to the beginning of the current sentence : to the beginning of the next sentence ) : to the matching bracket, parenthesis, braces, . . . % 20 / 30 Bart Van Loon vim – Vi IMproved, a programmers text

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