The VIM Text Editor
Most users who are familiar with the command line have heard of or had some experience with vi. In this tutorial, I presented the most popular and advanced of the vi clones: vim. The tutorial consisted of a slow introduction to vim, with an emphasis on *how* to learn the editor. A more advanced discussion on effective editing (with a case study in C programming) followed this talk.
VIM for Beginners
Why Learn VIM?
- Console or GUI
- Encourages touch typing
- vi written by Bill Joy (founded Sun Microsystems)
- vim written by Bram Moolenaar (now works for Google)
- Latest Version (7) released May 2006
- h = left
- j = up
- k = down
- l = right
- Normal (Default)
- Others. . .
- To escape to normal mode (Esc) (or better yet ctrl-[ )
- Navigate the document
- Copy, paste, delete text
- Most other editors are always in this mode
- Save, load, etc.
- Set options
- Special Functions
- Select text to copy, delete, edit, etc.
Some essential commands
- :write (:w)
- saves your document
- :quit (:q)
- quits vim
- fails if current document isn't saved â€“ to force, use :quit! (:q!)
- save and quit
Some essential keys (normal mode) - x
Delete character under cursor
Delete current line
The most important keys for beginners - Esc ( ctrl-[ )
Goes back to normal mode, you can't hit this too many times
Vim is exceptionally well-documented
How should I learn vim? - vimtutor
This is a well written introduction to all the essential features of vim - I encourage everyone to take a look (simply type vimtutor in your console).
- Read the help docs
- Force yourself to use it - If something feels tedious, you are probably doing it wrong â€“ look for a
More on Keys - In vim, almost every key is mapped
type carefully â€“ a mis-typed key can cause frustration
- Avoid remapping keys that are already used
vimrc .vimrc is loaded upon starting vim - ideally is located in your home directory Syntax highlighting :syntax on :syntax off Line numbering :set number
To turn off just about any option, prepend the option name with "no" Example: :set nonumber
Words Watch as I navigate through this sentence by using the 'w', 'b', and 'e' keys. There are also uppercase versions of these characters, which navigate through whitespace delineated words(for_example_a_'W'_would_skip_over_all_of_this).
Sentences Sentences. Can be navigated. by the ')' key. Paragraphs Sentences. Can be navigated. by the '}' key.
Character Searches f navigate to next typed character t navigate until next typed character Try f( and t( on the line below. Note the difference. Try typing dt) when on the first " printf("Starting up my amazing program\n");
Text Objects What is the best way to delete a sentence? For example, If I were to ask you to delete the sentence that you are currently reading, what is the best way to do it? It might surprise you how simple it can be. (Try typing das when over one of the sentences above)
<A>Before some tag</A><Some_tag>The value of said tag</Some_tag><A>After some tag.</A> (Try typing dat when over one of the tags above)
"Inside of quotes" (also works for parentheses) (Try typing di" when inside the quotes above)
Jump histories :jumps Ctrl-o = reverse through this list Ctrl-i = forward through this list Change histories :changes u = undo Ctrl-r = redo Command history q: search history q/
gq - beautifies the selection/motion to which it is applied = - indents the selection/motion to which it is applied
- Word Completion
Ctrl-n completes a word Ctrl-x-f completes a file name (in the current directory)
This is only required if you live off campus or have extended access granted.