to jump to the first line of the file, to paste the just deleted line, <'><'> (2 single quotes) to return to the last editing position. Finally hit to end the recording. Now you can just do <@> on every line you need at the start of your file. Easy, isn't it? :) Additionally <@><@> repeats the last macro execution (so you even don't need to remember the register you stored it in).
Uppercase letters
There are a lot of helpful shortcuts on your keyboard, which you might not know about. Every VIM user should now, that deletes something, (yank) copies something and changes something (delete and start inserting) in VIM (all in command mode). Furthermore, most people know that e.g. deletes the next word, etc.. What I did not know for a long time was, that , and are shortcuts to perform the desired operation until the end of the current line. For instance, simply type to change the contents of the current line from your cursors position on.
Where am I?
If you have a large resolution (e.g. mine is 166x1200), you sometimes loose your cursor when looking at something else in the room. The new customization features of VIM 7 allow you to add a nice finding help: Add the lines autocmd InsertLeave * se nocul and autocmd InsertEnter * se cul to your .vimrc and you will get the current line underlined as soon as you enter insert mode.
Regex driven commands
Regular expressions belong to every VIM users toolbox. What some people might not know (so didn't I) is, that you can not only do replacements with them in VIM, but also address lines you want to perform commands on. Simply do :s//= to execute the given on each text portion that matches .
Magic regex
Those of you who are used to PCRE syntax (and I hope all of you PHP developers out there), will often struggle over VIMs POSIX style regex and forget toescape parenthesis and other stuff. Usually VIMs regex work in so called magic mode, which means that VIM treats only a limited set of characters as magic inside a regex (that applies e.g. to ., matching any character, and * as a quantifier). Other characters, like (, ) and | are per default not considered magic and have to be escaped to make them magic (i\(, \) and \|). While this might be convenient insome cases (like simple text replacements without back-references), it becomes quite ugly, if you need to refer to a lot of capturing parenthesis. For this cases, it makes sense to switch VIM into very magic mode, using \v at the beginning of your regex. The opposite of this switch is \V, which makes the regex very nomagic. Because VIM is normally in magic mode (which corresponds to setting \m, if you change the default behaviour), there is also a nomagic mode, which considers less, but still some, characters as magic. Some simple examples:
s/(foo)bar/1/ does not work, () must be escaped
s/\v(foo)bar//1/ does work, regex is considered very magic
s/.*bar$/foobar/ replaces a line with foobar, that ends on bar
s/\V.*bar$/foobar/ replaces a line with foobar, contains literaly ".*bar$"
---
Below is taken from
http://www.vim.org/tips/tip.php?tip_id=12
To insert space characters whenever the tab key is pressed, set the
'expandtab' option:
set expandtab
With this option set, if you want to enter a real tab character use
Ctrl-V key sequence.
To control the number of space characters that will be inserted when
the tab key is pressed, set the 'tabstop' option. For example, to
insert 4 spaces for a tab, use:
set tabstop=4
After the 'expandtab' option is set, all the new tab characters entered
will be changed to spaces. This will not affect the existing tab
characters. To change all the existing tab characters to match the
current tab settings, use
:retab
To change the number of space characters inserted for indentation, use
the 'shiftwidth' option:
set shiftwidth=4
For example, to get the following coding style,
- No tabs in the source file
- All tab characters are 4 space characters
use the following set of options:
set tabstop=4
set shiftwidth=4
set expandtab
---
Splitting a line
----------------
i+return+esc
. (period) after that
keymap in ~/.exrc (or .vimrc?) to say 'F8' is '"i" + "return" + "esc"'