Vim Primer
Essential Info (Advanced Users)
If you're already using Vim, here's what you need to know. If you haven't used it before, skip this section and start with the Overview, below.
- To syntax highlight and indent .slag files in Vim for Plasmacore programming:
- Download slag.vim and save it in your c:\Program Files\vim\vimfiles\syntax or ~/.vim/syntax folder.
- Download this different slag.vim (updated September 26, 2009) and save it in your \vimfiles\indent or ~/vim/indent folder.
- Add the following lines to your _gvimrc / .gvimrc:
au BufRead,BufNewFile *.slag set filetype=slag
filetype indent on
- There is a nice graphical Vim "cheat sheet" available here: http://www.viemu.com/vi-vim-cheat-sheet.gif
- There's also a Dvorak-layout cheat sheet: http://www.egr.nau.edu/~ap27/vi-vim-cheat-sheet-dvorak.gif
Overview
Something along the lines of a word processor, Vim is one of the most frustrating, hardest-to-learn text editors available. But it's worth it. It's extremely powerful and is designed to make editing programs fast and easy once you know it. If you want to do as much as possible with as few keystrokes as possible you should give it a shot.
The secret to Vim's power (and difficult learning curve) is twofold. First off, there are two modes of operation: Command Mode and Text Edit Mode. In Command Mode, every key on the keyboard is a different editing command. Secondly, these commands may be strung together and combined in certain ways, making Vim a little programming language itself - a language that deals with text editing, with key-press statements that modify your text file in the same way that statements in other languages might draw graphics to the screen.
Vim was programmed by Bram Moolenaar and resides at http://www.vim.org.
Installing Vim
- Download and run the gvim72.exe installer.
- Add Vim's directory to your system path. To do this, click Start -> (My) Computer -> Properties, find Advanced System Settings, and click "Environment Variables" at the bottom. Find "Path" in the System Variables list, double-click it to edit it, and add something similar to the following in front of (not instead of) what's already there:
c:\Program Files\vim\vim72;
-
Now you can run gvim from the command line ("gvim game.slag") and run the vim tutorial by typing "vimtutor".
-
See Configuring Vim, below, for further customization options.
Macs come with a command-line version of Vim already installed, but consider using the Mac-customized MacVim instead.
- Download MacVim 7.2 or better and install the MacVim app in the Applications folder.
- Create a folder in your home directory (e.g. "abe" if your username is abe) called "bin" and drag the "mvim" file that was also in the download into it.
- Bring up a Terminal window (Command+SPACEBAR, type in "Terminal" or else double-click Terminal in Applications->Utilities). You'll be in your home folder.
- Type "vimtutor" to learn the basics of the command-line Vim so that you know enough to finish installing mvim.
- Type "vim .profile" (without the quotes but including the period in front of "profile" - that makes it a hidden file) to edit your command-line configuration file. Type "i" for insert and then type in the following line to make the "bin" folder we made one of the default places the system looks for commands. Replace "abe" with your own username:
PATH=/Users/abe/bin:$PATH
Next, hit ESCAPE and type ":wq" (without quotes). The cursor should jump to the bottom of the screen when you type the colon and then wq writes (saves) and quits.
- Open another terminal window so that our change takes effect. Now you can type "mvim game.slag" (etc.) to edit source code!
- See Configuring Vim, below, for further customization options.
There's a good chance Vim is available for your Operating System at http://www.vim.org
Configuring Vim
Vim gets its configuration values from the file "_gvimrc" (Windows) or ".gvimrc" (Mac).
Here's an example configuration file to get you started. Click on the link and make a copy of all the text: gvimrc
Now, type one one of the following at the command prompt:
gvim "c:\Program Files\vim\_gvimrc" (Windows), or
mvim ~/.gvimrc (Mac)
to start editing your configuration file. Type "i" (no quotes) to enter insert mode, then paste the copied code in (just do Edit->Paste from the menu).
Using Vim With Plasmacore
Save the following syntax file in the folder "C:\Program Files\vim\vimfiles\syntax":
http://www.plasmaworks.com/files/slag/slag.vim
Next, save this indentation file in the folder "C:\Program Files\vim\vimfiles\indent":
http://www.plasmaworks.com/files/slag/indent/slag.vim
From a terminal, type the following:
cd ~ mkdir vim mkdir vim/syntax mkdir vim/indent
Save the following syntax file in the "vim/syntax" folder of your home directory:
http://www.plasmaworks.com/files/slag/slag.vim
Next, save this indentation file in the "vim/indent" folder of your home directory:
http://www.plasmaworks.com/files/slag/indent/slag.vim
Finally, type in the following to change the vim settings folder name from "vim" to ".vim" (which is the proper name but makes it hidden, which would have complicated the downloading process):
mv vim .vim
If you are using the configuration file listed above then highlighting and indenting will be automatically active the next time you edit a .slag file!
Quick Reference Sheets
- There is a nice graphical Vim "cheat sheet" available here: http://www.viemu.com/vi-vim-cheat-sheet.gif
- There's also a Dvorak-layout cheat sheet: http://www.egr.nau.edu/~ap27/vi-vim-cheat-sheet-dvorak.gif
Common Commands
- Remember that you begin in COMMAND MODE. The following commands are available in COMMAND MODE. All commands are case sensitive.
- This is by no means a comprehensive list of commands, but rather a useful starter set - type ":help" in Vim to access the full documentation.
Inserting
These commands will take you into TEXT-EDIT MODE. To return to COMMAND MODE hit the [ESC] key.
|
Delete, Cut & Paste
|
Miscellaneous
|
Moving the Cursor
|
Saving
|
Vim Family History (in a nutshell)
Vim (rhymes with "him") was based on a popular earlier program called "vi" (letters are spelled out "vee aye"). Many of the following commands work in "vi" as well as "vim".
Vi itself is a visual mode extension to an old line editor called "ed". Designed in the days when a computer's output was printed on an actual printer, ed was designed to allow you to specify a range of lines to print or modify. For example, to get a list of all lines matching a certain regular expression (re) and then print them to the printer, you'd type:
:g/re/p
- Login to post comments
