Difference between revisions of "HowToUseVim"
Jason Parmer (talk | contribs) (→Multiple Windows) |
Jason Parmer (talk | contribs) (→Editing Multiple Documents) |
||
| Line 52: | Line 52: | ||
===Editing Multiple Documents=== | ===Editing Multiple Documents=== | ||
Since the undo buffer works better if you never exit out of vim, it is very handy to have multiple files open in one vim session and switch between them. ctrl-z to suspend vim and fg to get back into it are very handy. | Since the undo buffer works better if you never exit out of vim, it is very handy to have multiple files open in one vim session and switch between them. ctrl-z to suspend vim and fg to get back into it are very handy. | ||
| − | :bn - buffer next. Switch to the next buffer. | + | * :bn - buffer next. Switch to the next buffer. |
| − | :bp - buffer previous. Switch to the previous buffer | + | * :bp - buffer previous. Switch to the previous buffer |
| − | \be - Buffer Explorer. Shows a list of open edit buffers, arrow keys and enter will select he buffer to switch to. | + | * \be - Buffer Explorer. Shows a list of open edit buffers, arrow keys and enter will select he buffer to switch to. |
===Multiple Windows=== | ===Multiple Windows=== | ||
Revision as of 06:47, 5 July 2007
This is just a start, hopefully this will get you on your way to being a vim power user
Contents
Why vim?
It works well in screen and is reasonably powerful programmer's editor. In addition, it is usually on every box in some form or another.
Minimal Custom Vimrc for Developers
Vim defaults are great in most cases, but some options need to be set. This is currently incomplete, but is a start.
version 6.0 # enable later-version vim functions set nocompatible # get rid of crufty vi compatibilites set expandtab # tabs can't be different on different systems if they don't exist syn on # enable syntax highlighting set autoindent # help with formatting set incsearch # TODO set hlsearch # TODO set fo=cqrt # TODO
Modal Editing
Vim is a modal editor, meaning that unless you are in insert mode characters you type will not show up in the input buffer. I cannot stress enough that unless you are actually typing something in, you should be in command mode. This is very non intuitive for beginners.
If you get stuck, jamming on the
Commands that start with : need to be finished by hitting
Quitting Vim
- :q - quit vim
File Operations
- :w - saves the file
- :wq - saves the file and quits vim
- :e
- edit filename - :e . - open a file browser
Command Mode
command mode is the default mode for vim.
- i - insert
- lets you type into the buffer. hit
when done to return to command mode
- lets you type into the buffer. hit
- u - undo
- will undo any commands. The undo buffer goes back to when you started your editing session and is really good, so it is better to stay in the habit of having an editor open for a long time and use ctrl-z and the fg command to drop to a shell
- ctrl-r - redo
- redoes something that has been undone
- ct
- change till - replace the text from here to the character with what you type. Puts you in insert mode
- cw - Change Word
Insert Mode
This is the mode you are in when you use the insert or change commands. Characters entered at the keyboard are inserted directly into the document, with automatic indentation for recognized source code constructs.
- ctrl-n - completion. Use multiple times to cycle through available completions. Can use ctags, to do project-wide completions.
Editing Multiple Documents
Since the undo buffer works better if you never exit out of vim, it is very handy to have multiple files open in one vim session and switch between them. ctrl-z to suspend vim and fg to get back into it are very handy.
- :bn - buffer next. Switch to the next buffer.
- :bp - buffer previous. Switch to the previous buffer
- \be - Buffer Explorer. Shows a list of open edit buffers, arrow keys and enter will select he buffer to switch to.
Multiple Windows
The most basic usage will be described here. All of these commands are from command mode.
- ctrl-w n - create new window, split horizontally
- ctrl-w v - create new window, split vertically
- ctrl-w w - switch window
- :q - quit a window. If multiple windows are open, will just switch to the next window instead of exiting.
ToDo
- Document copy / paste / selections
- Vertical Insert
- plugins / links / documentation
