<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="presenter.xsl"?>
<slideshow>
	<title> Vim Essentials</title>
	<slide> <!-- title slide -->
		<body>
			<h1 style="color:blue;margin-top:100px;margin-left: 100px; font-size: 36pt;margin-bottom:0px">
			Vim Essentials
			</h1>
			<h4 style="font-style: italic; color: darkblue;margin-left: 200px;margin-top: 0px;"> 
			The most efficient editor around.
			</h4>

			<div style="position: absolute; right: 0px; bottom: 0px; margin: 50px;"> 
			Computer Science House
			<p/>
			Jordan Sissel<br/>
			jls@csh.rit.edu
			</div>

		</body>
	</slide>

	<slide> <title> Introductions </title>
		<body>
			Hi! Welcome to the Vim Essentials seminar/workshop!

			<p/>

			I am your geeky host, Jordan Sissel.

			<p/>

			If you have questions during the presentation, ask them and I will
			answer them. However, keep in mind that I may be answering your
			question soon in the slides, anyway.

			<p/>

			Mostly, try to focus questions on confusion about the material, rather
			than focusing on "what if foo?" type questions. Write down other
			questions and save them for question breaks, if you can.

			<p/>

			The slides can be found online at:<br/>
			<a href="http://www.semicomplete.com/presentations/vim">http://www.semicomplete.com/presentations/vim</a>

		</body>
	</slide>

	<slide> <title> Goals  </title>
		<body>
			At the end of this seminar, you should:
			<ul>
				<li> Understand the behavior of a vi-like environment </li>
				<li> Feel comfortable with basic editing tools in vim </li>
				<li> Know how to find documentation </li>
				<li> Know how to configure vim to suit your tastes </li>
			</ul>
		</body>
	</slide>

	<slide> <title> Agenda </title>
		<body>
			<ul>
				<li> What is vim? </li>
				<li> Caveat Emptor: Steep learning curve </li>
				<li> Basic Environment </li>
				<li> Editing Skills </li>
				<li> Configuration </li>
				<li> Advanced Skills and Tools </li>
			</ul>
		</body>
	</slide>

	<slide> <title> What is vim? </title>
		<body>
			Quoting www.vim.org:

			<blockquote>
				Vim is a highly configurable text editor built to enable efficient
				text editing. It is an improved version of the vi editor
				distributed with most UNIX systems.

				<p/>

				Vim is often called a "programmer's editor," and so useful for
				programming that many consider it an entire IDE. It's not just for
				programmers, though. Vim is perfect for all kinds of text editing,
				from composing email to editing configuration files.  
			</blockquote>

			It runs on many operating systems, including Windows, OSX, and Unix.

		</body>
	</slide>

	<slide> <title> Why use it? </title>
		<body>
			It is very efficient not because of execution speed, but becuase of
			its interface. The interface and environment provides a means for an
			extremely efficient editing paradigm.

			<p/>

			That is, Vim provides you a huge array of useful tools with which to
			edit text. Almost all other text editors fail to provide this.

			<p/>

			The better you know how to use Vim, the faster you will be able to
			work. Work faster, finish sooner, and have more free time?

			<p/>

			You work more efficiently, and get done faster becuase you spend less
			time being frustrated with limitations in your editing environment.
		</body>
	</slide>

	<slide> <title> Caveat Emptor </title>
		<body>
			First thing to know about vim:

			<p/>

			<b>There is a somewhat steep learning curve</b>
		</body>
	</slide>

	<slide> <title> Getting into Vim</title>
		<body>
			From Unix:
			<pre><![CDATA[vim myfile.java]]></pre>

			From Windows: <br/>
			Clicky on the vim icon?

			<p/>

			The Windows installer for Vim will give you an option add an "Edit in
			Vim" context entry for Explorer. This will let you right-click on
			files and select to edit them in Vim.
		</body>
	</slide>

	<slide> <title> What to expect </title>
		<body>
			This is what vim will probably look like when you first start it up:

			<p/>
			<center>
			<img src="vim-screenshot.png" style="border: 1px solid black"/>
			</center>

		</body>
	</slide>

	<slide> <title> Getting out of Vim</title>
		<body>
			Vim may seem scary at first, so let's learn how to quit.

			<p/>

			To quit:
			<ol>
				<li> Press escape </li>
				<li> Type ':q' </li>
			</ol>

			This will fail (with error) if the file has been modified since it's
			last save (or since opening/creation).

			To force quit (without saving):
			<ol>
				<li> Press escape </li>
				<li> Type ':q!'</li>
			</ol>

			This will tell vim to quit and ignore any warnings or normal errors.

		</body>
	</slide>

	<slide> <title> Learning the Basics </title>
		<body>
			Let's go through the vim tutor. Type this in a terminal:

			<pre>vimtutor</pre>

			We'll continue this workshop from there.

			<p/>

			If you already know how to use vi, then this section's going to be a
			smidge boring. It shouldn't take too long.
		</body>
	</slide>

	<slide> <title> Post-tutor review </title>
		<body>
			At this point, you know how to:
			<ul>
				<li> navigate </li>
				<li> open files, save and quit </li>
				<li> edit files somewhat </li>
			</ul>

			You should also understand the difference between normal (aka command) mode and insertion mode.
		</body>
	</slide>

	<slide> <title> Vim Mastery Tips </title>
		<body>
			Force yourself to stay away from your mouse and non-typeable keys:

			<ul>
				<li> Arrow keys are bad, use hjkl </li>
				<li> Page up / Page down are bad. Use ^B (page back) and ^F (page forward). </li>
				<li> Don't use the mouse, use targeted movements: hjklewbtfHMLnN </li>
			</ul>

			Old hat vi users might use Control+[ instead of escape. Thiis
			historically becuase the escape key did not send that particular key
			sequence, and thus did not break out of insertion mode.

			<p/>

			The original version of vi was designed around keeping your hands on
			the home row. hjkl was chosen becuase it lies on the home row. 
			
			<p/>
			The less distance your hands have to travel, the less time you spend
			not doing work.

		</body>
	</slide>

	<slide> <title> Arrow Keys (Don't use them) </title>
		<body>
			Arrow keys are bad. Don't use them.  
			<ul>
				<li> They don't work in normal Vi, which you may be using on some systems </li>
				<li> They work in Vim, in insert mode, but don't use them. </li>
				<li> Don't use them </li>
				<li> Trust me. Don't use them. </li>
			</ul>

			Have I drilled it in yet? Sure, arrow keys work in vim. However, it is
			NOT faster to use them. 99.99999% of the time, you will need to move more
			than one position, and breaking out of insert mode will be faster than
			fumbling around on your arrow keys.
		</body>
	</slide>

	<slide> <title> Chained commands are powerful </title>
		<body>
			The true power of vim comes from chaining simple commands together.

			<dl>
				<dt> Forgot a semicolon? </dt>
				<dd> A;</dd>
				<dt> Forgot to indent your code? </dt>
				<dd> &gt;&gt; </dd>
				<dt> Fix a swapped-letter typo? </dt>
				<dd> xp </dd>
				<dt> Swap this line with the next </dt>
				<dd> ddp </dd>
				<dt> Change a quoted string </dt>
				<dd> ct" </dd>
			</dl>
		</body>
	</slide>

	<slide> <title> Seriously.. about those arrow keys </title>
		<body>
			Don't use them.
		</body>
	</slide>

	<slide> <title> Windows </title>
		<body>
			Vim is a terminal based program, but it has a concept of windows. A window is a scrollable viewport on a buffer. Multiple windows can point at the same buffer.

			<p/>

			Run the ":help" command. Help is brought up in a second window - a split view in your terminal.

			<p/>

			Windows have a status bar at the bottom indicating what is in the window, and where you are.
		</body>
	</slide>

	<slide> <title> Window Commands</title>
		<body>
			Read :help windows

			<p/>

			<dl>
				<dt> ^Ws or :split</dt>
				<dd>Split the window with both panes viewing the same buffer</dd>
				<dt> :split e myfile.java </dt>
				<dd> Split and open myfile.java in the new window </dd>
				<dt> ^W^W </dt>
				<dd> Focus the previous window </dd>
				<dt> ^Wc or :close</dt>
				<dd> Close the focused window </dd>
			</dl>
		</body>
	</slide>

	<slide> <title> Token Completion (What/Why) </title>
		<body>
			Vim can complete tokens for you.

			<p/>

			This is useful to:
			<ul>
				<li> Save time </li>
				<li> Cure world hunger </li>
				<li> Keep your programs readable </li>
			</ul>

			Use more meaningful variable names, and not have to type them fully every single time!

			<ul>
				<li> Make your professors happier because you're following their coding standard! </li>
				<li> Cure world hunger a second time! WOW!</li>
			</ul>
		</body>
	</slide>

	<slide> <title> Token Completion (How)</title>
		<body>
			<ul>
				<li> <b>^P</b> - Complete word at cursor to first match searching backward. </li>
				<li> <b>^N</b> - Complete word at cursor to first match searching forward. </li>
				<li> <b>^X^F</b> - Complete a filename </li>
				<li> <b>^X^I</b> - Complete a token at cursor from searching through included files </li>
			</ul>

			<code><![CDATA[#include <stdlib.h>
#include <string.h>

int main() {
	str]]><font color="red"><b><i>^X^I ... ^N</i></b></font><![CDATA[
}
]]></code>
		</body>
	</slide>

	<slide> <title> Token Completion (How #2)</title>
		<body>
			<code><![CDATA[public class Foo {
   public static void main(String args[]) {
      int longVariableNamesMakeProfessorsHappy;

      long]]><font color="red"><b><i>^P</i></b></font><![CDATA[
      //completes to 'longVariableNamesMakeProfessorsHappy'
   }
}
]]></code>
		</body>
	</slide>

	<slide> <title> Programming Help </title>
		<body>
			The <i>K</i> command will look up a manpage for the word under the cursor.

			<p/>

			Try this. Insert 'strlen' and pressing 'K' in command mode while the
			cursor is over 'strlen' - this will bring up the manpage for 'strlen'

			<p/>

			While this is not immediately useful in Java and certain other
			languages, it is very useful in Perl, C, Python, and others.
		</body>
	</slide>

	<slide> <title> External commands and filters </title>
		<body>
			You can run external commands from vim:
			<code>:!<i>cmd</i></code>

			For instance, you can run ls:
			<code>:!ls</code>

			You can also filter code through external programs:
			<code>:<i>range</i>!cmd</code>

			Let's rot13 our data:
			<code>:%!tr a-z n-za-m</code>

		</body>
	</slide>

	<slide> <title> Example commands </title>
		<body>
			Sort the next 5 lines (inclusive of this line):
			<code>:.,+5!sort</code>

		</body>
	</slide>

	<slide> <title> Syntax checking yourself</title>
		<body>
			Use external commands to perform syntax checks.

			<dl>
				<dt> Java </dt>
				<dd> :!javac % </dd>
				<dt> Perl </dt>
				<dd> :!perl -c % </dd>
				<dt> C </dt>
				<dd> :!gcc -fsyntax-only % </dd>
				<dt> Bourne Shell </dt>
				<dd> :!sh -n % </dd>
				<dt> XML </dt>
				<dd> :!xmllint % </dd>
			</dl>

			The % will be expanded to the file being edited.
		</body>
	</slide>

	<slide> <title> Project building </title>
		<body>
			<h4> Help tags - :copen, :make </h4>
			The :make command will help you build your project, all from inside vim.

			<p/>

			<ul>
				<li> By default, it runs 'make' externally and tries to parse the output. </li>
				<li> If it can parse it, and there is a build error, it will jump you to the first error found </li>
				<li> Open the error window with :copen </li>
			</ul>
		</body>
	</slide>

	<slide> <title> Grep - looking for text </title>
		<body>
			<h4> Help tag - :grep </h4>

			Use :grep to search files for content. Matches are reported in the
			"error" window (:copen to view)

			<p/>

			Example - look all java files in current directory for 'Thread.currentThread':
			<code><![CDATA[:grep Thread.currentThread *.java
:copen]]></code>

			Cursor over the line you want to jump to, and press enter. This will
			jump you to the file/line matched.
		</body>
	</slide>

	<slide> <title> Delete/Change text-object commands </title>
		<body>
			<h3>:help text-objects</h3>

			Examples:

			<dl>
				<dt>das</dt>
				<dd>delete the sentence we are in. </dd>
				<dt>diB</dt>
				<dd>Delete an inner { } block</dd>
			</dl>
		</body>
	</slide>

	<slide> <title> Configuring Vim </title>
		<body>
			Vim is highly configurable through settings and other features.

			<p/>

			The commands you'll want to know about:
			<ul>
				<li> :set </li>
				<li> :syntax </li>
				<li> :map </li>
				<li> :autocmd </li>
			</ul>

			<font color="red">NOTE: You will want to store permanent settings in a
			.vimrc file in your home directory. In windows this file is in a different location.

			<p/>

			In windows, it is: path\to\your\homedir\_vimrc<br/>
			Such as: C:\Documents and Settings\Jordan Sissel\_vimrc

			<p/>

			Keep in mind that your Windows home directory may not be in that
			location above. Check with your systems administrator if you don't
			know where your home directory is located at.

			<p/>

			Don't quote me on the Windows location, though. Read :help _vimrc
			
			</font>

		</body>
	</slide>

	<slide> <title> :set </title>
		<body>
			:set lets you enable, disable, and configure many different options in vim.

			<p/>

			<dl>
				<dt> :set <i>option</i> </dt>
				<dd> Enable <i>option</i> if it is a boolean option </dd>
				<dt> :set <b>no</b><i>option</i></dt>
				<dd> Disable <i>option</i> if it is a boolean option </dd>
				<dt> :set <b>inv</b><i>option</i></dt>
				<dd> Invert <i>option</i> if it is a boolean option </dd>
				<dt> :set <i>option</i>=<i>value</i></dt>
				<dd> Set an <i>option</i> to a <i>value</i> </dd>
			</dl>
		</body>
	</slide>

	<slide> <title> :set autoindent </title>
		<body>
			Auto indent will maintain the level of indentation for new lines.

			Turn it on, and insert some text. Add a newline, put spaces or tabs at
			the beginning of the line, more text, and another newline.

			<code><![CDATA[Hello
   Foo
   X  ^]]></code>

			If the cursor is after 'Foo', pressing enter will cause vim to shift
			inward on the new line making it line up with the previous one. The
			new line will start on the 'X' location

			This is very useful for coding.
		</body>
	</slide>

	<slide> <title> :set smartindent </title>
		<body>
			Smart indent works with more intelligence than autoindent. It tries to
			recognize "code" and will indent when it deems appropriate.

			<p/>

			Disable autoindent first! :set noautoindent
			
			<p/>

			Enable smartindent and type a Java function header, press enter after
			the '{' and it should autoindent for you. Type some more, and typing a
			'}' should reduce the indent

		</body>
	</slide>

	<slide> <title> Misc options </title>
		<body>
			<dl>
				<dt> :set number </dt>
				<dd> Show line numbers </dd>
				<dt> :set list (see :help listchars) </dt>
				<dd> Show whitespace. Use listchars to configure this. </dd>
				<dt> :set nocompatible </dt>
				<dd> Disable "vi compatibility" mode </dd>
				<dt> :set incsearch </dt>
				<dd> Incremental search </dd>
				<dt> :set hlsearch </dt>
				<dd> Highlight search matches </dd>
				<dt> :set shiftwidth=NUM </dt>
				<dd> Set shift to N spaces for <b>&gt;&gt;</b> command and smartindent </dd>
				<dt> :set expandtab </dt>
				<dd> Use spaces instead of tabs when inserting. The number of
				spaces is dependent on the tabstop option </dd>
			</dl>
		</body>
	</slide>

	<slide> <title> Misc options (#2) </title>
		<body>
			<dl>
				<dt> :set tabstop=NUM </dt>
				<dd> Set tabs to be displayed as NUM spaces.</dd>
				<dt> :set showmatch </dt>
				<dd> Show () {} and [] matches while writing. (<b>VERY USEFUL</b>) </dd>
				<dt> :set backspace=indent,eol</dt>
				<dd> Enable sane backspace ability for insert mode (for my definition of sane) </dd>
				<dt> :set textwidth=NUM </dt>
				<dd> Set width of buffer before wrapping </dd>
				<dt> :set showcmd </dt>
				<dd> Show the unfinished command-mode command </dd>
				<dt> :set ruler </dt>
				<dd> Put meaningful information in the bottom line of your window </dd>
			</dl>
		</body>
	</slide>

	<slide> <title> :syntax </title>
		<body>
			Vim will do syntax highlighting if you want it to.
			<dl>
				<dt> :set background=[dark|light] </dt>
				<dd> Tell vim about your background color </dd>
				<dt> :filetype on</dt>
				<dd> Enable automatic file type detection </dd>
				<dt> :syntax on </dt>
				<dd> Enable syntax highlighting. </dd>
			</dl>

			File types are generally automatically detected. If it does not work,
			put ':filetype on' in your vimrc

			<p/>

			Vim comes standard with MANY syntax highlighting files. My count shows
			417 language syntax files. Java, C, C++, C#, Perl, Python, Ruby,
			Bourne Shell, and many many others are included.
		</body>
	</slide>

	<slide> <title> :map </title>
		<body>
			You can bind (map) keys to actions in vim.

			<p/>

			For instance, if you wanted to map Control+S to save:
			<code><![CDATA[:map <C-s> :w<CR>]]></code>

			The <![CDATA[<C-X>]]> is notation for saying Control+X.

			<p/>

		</body>
	</slide>

	<slide> <title> :map (example) </title>
		<body>
			For instance, let's map "\sp" to syntax check perl:
			<code><![CDATA[:map \sp :!perl -c %<CR>]]></code>

			<p/>

			The <![CDATA[<CR>]]> is meant literally. You type <![CDATA['<' 'C' 'R' '>']]>.
			This has vim insert an end-of-line as if you had typed it after it "types" the perl command.

			<p/>

			With this map, you do \sp (literally those 3 characters) in normal mode and it will run:
			<br/>
			:!perl -c %
		</body>
	</slide>

	<slide> <title> :autocmd</title>
		<body>
			Autocommands are those that execute automatically under given
			circumstances. For instance, if you only wanted syntax highlighting
			enabled in java files:

			<code><![CDATA[autocmd Filetype java syntax on]]></code>

			Whenever the filetype is detected as being java, it will execute ":syntax on"

			<p/>

			Auto commands are extremely useful, and have a lot of options. I
			suggest reading the help for them - :help autocmd
		</body>
	</slide>

	<slide> <title> :autocmd (mail example)</title>
		<body>
			I write mail in ~/Mail/drafts/ - let's make some automagic commands to
			configure my mail-writing preferences.

			<p/>

			<code><![CDATA[autocmd BufNewFile,BufRead */Mail/drafts/* setf mail
autocmd Filetype mail set textwidth=72
autocmd FileType mail set nosmartindent
autocmd FileType mail set noautoindent]]></code>

			This will set the filetype (setf) to <i>mail</i> when I open/create
			new files in anything that matches <i>*/Mail/drafts/*</i>.

			<p/>
			mail filetype gets textwidth=72 and disables both smartindent and autoindent.

		</body>
	</slide>

	<slide> <title> Plugins or Scripts </title>
		<body>
			Vim has a scripting language built on :foo-type commands.

			<p/>

			You can download lots of plugin scripts that extend and add features to Vim.

			<p/>

			Go to <a href="http://www.vim.org/">www.vim.org</a> - click on Search. Search for scripts.
		</body>
	</slide>

	<slide> <title> Commenter plugin </title>
		<body>
			<a href="http://www.vim.org/scripts/script.php?script_id=1218">NERD_comments plugin (id 1218)</a>

			<p/>

			This handy plugin magically comments things for you. Let's try it.

			<ul>
				<li> Search for NERD_comments on vim.org </li>
				<li> Download the latest version. </li>
				<li> Make sure this directory exists: ~/.vim/plugins/ </li>
				<li> Put the NERD_comments.vim file in ~/.vim/plugins/ </li>
				<li> Start vim! </li>
				<li> Read :help NERD_comments for instructions on how to use this </li>
			</ul>

		</body>
	</slide>

	<slide> <title> What else? </title>
		<body>
			Hi.
		</body>
	</slide>

	<slide> <title> Files </title>
		<body>
			<ul>
				<li> <a href="http://www.viemu.com">Vi/Vim keyboard reference</a></li>
				<li> <a href="http://www.semicomplete.com/misc/viquickref.pdf">vi quick reference</a> </li>
			</ul>
		</body>
	</slide>

	<slide> <title> References </title>
		<body>
			<ul>
				<li> My Brain </li>
				<li> Vim's endlessly useful documentation (:help) </li>
				<li> Keyboard-map cheat sheet obtained from <a
				href="http://www.viemu.com/">www.viemu.com</a> </li>
				<li> "Vi quick reference" layout and some content stolen from <a
				href="www.zippydesign.com/ying/linux/vi/vi-reference.pdf">www.zippydesign.com/ying/linux/vi/vi-reference.pdf</a>.
				Original author unknown. </li>
			</ul>
		</body>
	</slide>

</slideshow>

<!-- 
	vim: foldmarker=<slide>,</slide>
-->
