Vim

Auto Complete

http://www.vim.org/tips/tip.php?tip_id=11 In insert mode, type Ctrl-N Ctrl-P

Tips

Editing

Finally, some editing commands!

Command Purpose
J Joins two lines

Indenting Lines of Code

Command Line

View command line history:

:his

View search history (Think of the forward slash as representing the search command)

:his/

Help

The help for vim is really helpful, but just like the rest of the application, you should learn how to use it.

vim help

Inserting Text

Key Command
I insert text at beginning of line (before first blank)
i insert text before cursor
A insert text at end of line
a

Configuration

Windoze

  • Make sure you have a %HOME% environment variable set up.
  • In your %HOME% directory, put a _vimrc file w/your settings in it.

Unix / Linux

Edit $HOME/.vimrc, and put preferences in there.

Configurable Options

Get a list of options and their descriptions:

:options

General

Command Description
. Repeat last command

Clipboard (Cut, Copy, Paste)

Registers

Multiple Files

Movement

Ctrl-U, Ctrl-D : Move Up/Down one screen

You can move to X percent of the file with

X% 

Move to line X

XG

Code Navigation

Key Purpose
% jump from an open brace to its matching closing brace. Actually, % can jump to many different matching items. It is very useful to check if () and {} constructs are balanced properly.
[{ jump back to the ”{” at the start of the current code block.
gd jump from the use of a variable to its local declaration.
[[ or ]] Forward / backward next section. (Use for C functions?)

Previous / Next Position

CTRL-O takes you back to older positions, CTRL-I to newer positions.

Information

Ctrl-G Shows the cursor's location / line number as a % of the file

Marks

Tabs

Open a new tab

:tabedit

Recent Files

Jumps / Changes

Jumps are the last X places that you've jumped to. When looking at the list of jumps / changes, the ”>” character shows what jump/change you're on. You have to use Ctrl-O or Ctrl-I depending on whether you want to move back in the list from the ”>” point. Kinda complicated.

Command Description
:changes Show list of changes
:ju[mps] Show list of jumps
`` Jump to last mark
'' Jump to start of the line of the last mark
`. Jump to last modification
[n]Ctrl-0 Jump to n previous position
[n]Ctrl-I Jump to n next position
[n]g; cycle thru recent changes (oldest first)
[n]g, cycle thru recent changes (newest first)

External Commands

Execute an external command:

:! <command>

Example:

# Changes mode of current file in vi to 755
:! chmod 755 %

Suspending Vi

Two ways to suspend Vi: FIXME Why is this? What's the difference?

Ctrl-Z

Suspend Vim by typing Ctrl-Z. Shell will appear.

Use 'jobs' to list processes

> jobs
[1]+  Stopped                 vim do.pl
[2]+  Stopped                 vim dookie.pl

Use 'fg' to bring last background process to foreground

> fg 

Or, use fg x where x is the process number to bring process number x to foreground.

> fg 1 

will restore do.pl from example above.

:sh

Use :sh to go to shell

:sh

Use exit to go back to vi (Although why anybody would want to go back to vi is beyond me)

> some shell comand
> exit

Search / Find / Replace

Buffers/Files

Geek term for “files”

Command Description
:e <filename> Open a new file in current buffer
:e! Reloads current file without saving changes. “Revert” or “Reload” would be more appropriate of a command name.
:w [filename] Saves changes to current file, or if filename is supplied, runs Save As filename on current buffer
:1b Goto buffer 1
:buffers, :ls, :files Show buffers
:bn goto next buffer
:bp goto previous buffer
:[n]b goto n buffer listed in :buffers output
:[n]bd[elete][!] Remove buffer n from buffers. Postfix with ! to force.

Windows

Windows are actually the text/divided things inside a Vim “window”.

vim windowsß

Rectangle / Column Mode

  • Ctrl-V puts vim in column mode.
  • Any movement will then select text.
  • Press o to move cursor from beginning of selection to end.
  • Press O to move cursor to opposite corner of selection.
  • Press gv in Normal mode to restore your previous selection.
  • Beginning/end of selected text is referenced using ’< and ’>.
    • To write contents of selected text to a file, use :’<,’> write joke.txt

Tutorials

Backspace Key

Backspace key doesn't want to erase stuff in insert mode sometimes. FIXME

Undo / Redo

  • u Undo
  • control-R Redo

Characters

You can find the HEX, Octal and Decimal value of the char under the cursor by using

ga

Customizing

~/.vimrc

From http://www.ph.unimelb.edu.au/~ssk/vim/options.html

The environment variable "$VIM" is used to locate various support files, such
as the on-line documentation and files used for syntax highlighting.  For
example, the main help file is normally "$VIM/doc/help.txt".

To avoid the need for every user to set the $VIM environment variable, Vim
will try to get the value for $VIM in this order:
1. The value defined by the $VIM environment variable.  You can use this to
   make Vim look in a specific directory for it's support files.  Example:
>	setenv VIM /home/paul/vim
2. For MSDOS and Win32 the environment variable $HOME is used, when defined.
   Works just like setting the $VIM environment variable.
3. The path from 'helpfile' is used, unless it contains some environment
   variable too (the default is "$VIM/doc/help.txt": chicken-egg problem).
   The file name ("help.txt" or any other) is removed.  If it then ends in
   "/doc", this is removed too.
4. For MSDOS, Win32 and OS/2 Vim tries to use the directory name of the
   executable.  If it ends in "/src", this is removed.  This is useful if you
   unpacked the .zip file in some directory, and adjusted the search path to
   find the vim executable.
5. For Unix the compile-time defined installation directory is used (see the
   output of ":version").

See Also

PageDescriptionTags
Command Line Window This is one of the most annoying things that happens to me. <http://www.vim.org/htmldoc/usr_20.html#20.5> I always accidentally type q: in normal mode, and it…
Cursor Line Many editors have the ability to highlight the entire line that your cursor is on. In Vim, you can do this by using :set cursorline You can turn it off by us… , , ,
Fuzzy Finder One of the best Vim plugins that I've used. Allows you to easily search for files by name, like Cmd-T in TextMate and Find File in Project in UltraEdit * <… , ,
Fuzzy Finder Kludge I'm a fan of the Fuzzy Finder plugin for Vim. I have written a kludge to the Fuzzy Finder that will trim really long directory names from the entries that you … ,
Fuzzy finder textmate An excellent Vim plugin that improves on FuzzyFinder plugin. <http://github.com/jamis/fuzzyfinder_textmate/tree/master> I wish that foos_controller.rb would b… ,
Highlighting Search Text in Vim I generally like to highlight text that I search for. But, there's times where I don't. In the example below, I think there's too many highlighted def stateme… ,
IdeaVIM Allows you to use Vim-interface from within IntelliJ IDEA. * <http://ideavim.sourceforge.net/> You get the code formatting features of Idea, as well as som… , ,
IdeaVIM Readme I copied the README file from version .11.6 for IDEA 7.x. See also the help file that's installed with the plugin. After you install the plugin, go to the IDE… , ,
Lookupfile Lookupfile is a Vim plugin that searches for files as you type criteria. For example, if you type “b”, then lookupfile will show all files that start with … ,
Netrw Netrw is the name of vim's file-browser. * <http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html> Netrw has a lot of functionality, but it's like Vim in tha… ,
Text/Terminal Mode I like the text-based dialogs better than the GUI ones. Mainly because it keeps the dialogs consistent whether I'm using MacVim or Vim from a terminal. Anothe…
URL Helper I put this note here to help myself gain an understanding of rails and how everything fits together. <http://api.rubyonrails.com/classes/ActionView/Helpers/Url… , ,
Vim - Convert To HTML In MacVim, you can go to the Syntax Menu, and select “Convert To HTML” This will take the current file that you have open, and create an HTML document with… , ,
Vim Best Of This is my own version of best of Vim. It is meant for real Vim “addicts”, and people who are text-editor dorks. I compiled it as a list of references to … ,
Vim Capture Command Output Sometimes, you'll issue a command in Vim, and the output is piped to more, so you can't really search/filter through the output. For example, try :set all An… , ,
Vim Clipboard One of the biggest things that confused me about Vim was how to copy/paste stuff from other programs into Vim and vice-versa. Vim was designed in 1976?, way be… ,
Vim Colorschemes <http://www.vim.org/htmldoc/usr_06.html> This website <http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-c.html> is a great place for previews of colors… , , ,
Vim Customizing There are thousands of ways of customizing Vim, which is both good and bad. * You can customize your settings: Vim Settings * For a list of keys that are … , ,
Vim Defaults Very good basic article on configuring best defaults in Vim: * <http://items.sjbach.com/319/configuring-vim-right> Notesmine External vim
Vim Diff Vim can be used to show diffs From <http://mamchenkov.net/wordpress/2004/05/10/vim-for-perl-developers/2/> Vim will show both files in vertical split window m… , , ,
Vim Formatting Vim has some pretty cool formatting things. The gq command formats the {motion} that you tell Vim to do. gq is used to format “normal” text (as opposed to… , ,
Vim Help * <http://www.truth.sk/vim/vimbook-OPL.pdf> * Use :help <command> to get help for a particular command. Default is to get help for the normal mode comma… ,
Vim Insert-Mode Completion Also known as “Autocomplete”, and “Code Completion” See <http://vimdoc.sourceforge.net/htmldoc/insert.html#ins-completion> After using text editors/ID… ,
Vim Keyboard Mapping The :verbose map command shows where a key sequence was mapped. This is handy for resolving key conflicts. Shows where ;1 was mapped, if at all. :verbose map… , ,
Vim Motion This is a huge area, and my favorites are for coding, where you can jump back & forth to the start of if .. then blocks, methods, and start/end of classes. The… , , ,
Vim Obscure This page is a list of the “obscure” commands in Vim. (Yes, I realize that most commands in vim are obscure) :history : list of all your commands… , ,
Vim Options Much of Vim's functionality is done through options. You can see the value of an option by using the :set command, with a question mark after the setting. Thi… ,
Vim Plugins Plugins extend the functionality of Vim. Plugins for any software tool are often tricky to install/use, sometimes have bugs, etc. However, if a plugin is wide… , , , , , , ,
Vim Rails Great vim plugin for rails applications. There's an excellent Tutorial on , and I recommend you navigate through that to learn how to install and use. I liste… , , , , , , , , ,
Vim Rails Screencast I might create a screencast showing how to use Vim w/Rails. * Show Vim setup? -- No * Show where to get Rails & related plugins? - Yes * Create Rails ap… , ,
Vim Scrolling One of the coolest things about Vim is its ability to show you where you are easily. The commands on this page do not move your cursor, instead they move the t… , , ,
Vim Settings Vim has a gazillion settings/options that you can use. With Vim, there's not really any “Options” window. You have to set the options yourself, or use a c… , , ,
Vim Sorting I got this tip from here: <http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim#comments> One of my favorite vim commands, and a powerful one, is this: I…
Vim Terminal Background Sometimes Vim's syntax looks horrible. For example, you're using a white background, and the characters are all light yellow, light red, etc. Try one of these… ,
Vim Todo This is just a page w/my TODO notes regarding Vim. It's meant to keep myself from yak-shaving when I find an aggravating thing in Vim. * Currently Ctrl-HJKL… ,
Vim Tricks There are plenty of Vim tips/tricks pages out there. Here's some of my own. Say you have some text like below, and want to eliminate the blank lines: def s… ,
Vim Visual Mode Visual Mode means working with highlighted text. When you only use v to highlight text, then Vim will only copy what's highlighted. This is annoying if you wa… , ,
Vim Whines * Requires large amount of tweaking for minor, yet annoying things. * Giant white status bar that blazes your eyes out. * Plugins are nice, but usually h… ,
gvim and vim fonts Bad. Font is sketchy/broken up, and too slim. I think this looks good: :-) Related Pages on Notesmine External Pages gvim, and, vim, fonts , , ,
my vim setup Just a page to list my Vim shortcuts, so I don't forget them, or have to use ”:map” to find them. * Ctrl = Control Key * D = Apple Key Current Vim Sh… , ,

TODO

  • Find out how to move the current file to a new location.
  • Find out how to check/run Perl/Ruby scripts
  • Get current file's path onto the clipboard.
    • Get better at clipboard.
 
vim.txt · Last modified: 2008/09/26 17_21 by tookelso
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki