Some very useful commands I use to make working with vim much more elegant and easier.

Settings

show / hide line numbers
:set number
:set nonumber
enable / disable syntax highlighting
:syntax on
:syntax off
If vim does not recognize the filetype, set the filetype manually
:set filetype=filetype
example
:set filetype=php
show ruler (cursor coordinates)
:set ruler
show vim mode (INSERT / REPLACE / ...)
:set showmode
show matching parentheses
:set showmatch
replace tabs with spaces
:set expandtab
number of spaces per tab
:set shiftwidth=2
As expandtab is not always desired (e.g. for Makefiles tabs are necessary and would lead to a syntax error when replaced by spaces) you can use autocmdto set it only for certain filetypes. example
:filetype on
:autocmd FileType php :set expandtab
automatic indentation (e.g. code blocks between braces)
:set cindent
Use this option with caution (same as with expandtab) case insensitive search
:set ignorecase
show invisible characters
:set list

Commands

custom shortcuts for string insertion
The following command sets a custom String that will be inserted every time shortcut and a word delimiter (like space or enter) is entered in insert mode.
:abbreviate shortcut string-to-be-inserted
example
:abbreviate iios #include <iostream><RETURN>

If you want to return directly into command mode after insertion, append

<ESC>to the string-to-be-inserted
custom shortcuts for complex commands
With the mapcommand you can store complex command sequences in a shortcut.
:map shortcut command-sequence
Unmap the command (free the shortcut)
:unmap shortcut
If you use :noremapinstead of :mapthe mapped command only applies in command mode and will not be evaluated at the right side of another map expression (this avoids that if you have some map expression that contains it its name the name of another map expression not both will be applied). example
:map FN o<ESC>30i*<ESC>0i/<ESC>o * function description<ENTER>
<ESC>i/<ESC>30i*<ESC>0i <ESC>ofunction {<ENTER><ESC>k$i
This example inserts with [SHIFT] + [F] + [N] a comment block and the skeleton for a new function definition and places the cursor after the function keyword. Consult some vim reference to understand the particular commands. The output looks like this:
/******************************
* function description
******************************/
function {
macros
To avoid having to type down the whole command above before seeing what comes out, you can "record" with macros what you're typing while usual work with vim.
Enable macro recorder a
qa
Disable macro recorder a
q
Apply recorded macro a
@a

Now everything you did between enabling and disabling the macro recorder has been recorded and can be reapplied.

formatting / editing
Export source code (or whatever) as syntax highlighted html
enable syntax highlighting
:syntax on
display line numbers in html
let html_number_lines=1
format html using css
let html_use_css=1
generate html code (opens in a new vim window)
:so $VIMRUNTIME/syntax/2html.vim
finally, export to a html file
:w filename.html
(to close the html window afterwards, enter :q) Code blocks indentation
To indent a whole code block (between braces), enter the following in command mode
>i{
unindent (shift to left) a code block
<i{
Find the corresponding parentheses (command mode)
%
Enter special characters
[CTRL] + [K] + character combination
find out the corresponding character combination
:digraphs
example (insert Ä)
[CTRL] + [K] + [A] + [:]
Autocompletion for keywords (e.g. for variable names)
[CTRL] + [N]

If there are more that one possibility, step through them with

[CTRL] + [N](forward) [CTRL] + [P](backward).
executing
Insert content of an external file
:r filename
Insert output of external shell command
:r !command
example (insert date)
:r !date
Set the shell to be used for !
:set shell=sh
Executing external commands
:! command
example (save and php syntax with the shortcut [SHIFT] + [T])
:noremap T :w <ENTER>:!php -l %<ENTER>
% will be replaced with the file name of the edited file.

Config file

To make settings persistent and to avoid having to enter all settings again and again everytime vim is started, you can put them all in a file called .vimrc in your home directory.
Lines beginning with " are comments.
To generate a .vimrc file with the current settings instead of entering them manually to the file, use the following command.
:mkvimrc
example .vimrc
" automatic indentation
set cindent

" replace tabs with spaces
set expandtab
" number of spaces per tab
set shiftwidth=2

" case insensitive search
set ignorecase

" whow line numbers
set number

" syntax highlighting
syntax on

" show cursor coordinates
set ruler

" executing shell
set shell=sh

" show matching parentheses
set showmatch

" show INSERT/REPLACE/...
set showmode

Random Quote

Das Schicksal nimmt nichts, was es nicht gegeben hat. (Sophokles)

» ...

koffeinfrei on identi.ca

icon
2012-02-01 09:13:03
wrote a short post about capistrano deployment for a sinatra app, summing up the scattered documentation... http://identi.ca/url/65862527
icon
2012-01-27 16:25:29
stop internet #censorship, sleazy bastard #acta http://www.stopp-acta.info, it's not over #sopa
icon
2012-01-27 14:04:03
wat! on ruby and javascript. hilarious: http://identi.ca/url/64793583
icon
2011-12-29 23:23:20
nice: "git meld" enables "git diff" in external diff viewer http://identi.ca/url/63405956
icon
2011-12-04 21:29:39
test runs & cats & rainbows. genius. http://identi.ca/url/61578085
icon
2011-11-23 22:28:55
vimtutor: a really great intro to vi(m).
icon
2011-11-23 22:25:40
RT @thoughtbot "The vim learning curve is a myth." http://t.co/mgBCxJQW
icon
2011-11-16 13:36:29
@Spotify services that require a facebook account shall all die a painful death!
icon
2011-10-31 22:29:17
"Wish you could write your Ruby in XML? Has the fact that Ruby is not “enterprise” got you down?" http://identi.ca/url/56208722
icon
2011-10-14 21:28:44
Attending "A Free Digital Society - Richard Stallman" http://identi.ca/url/54104004
icon
2011-09-30 15:29:15
... and the standalone .net library too: http://ur1.ca/593sg
icon
2011-09-30 15:28:05
gave up waiting for the broken minus api v1 to get fixed, updated the library myself -> new minus share version: http://ur1.ca/593q3
icon
2011-09-28 21:08:31
"User-Led Innovation Can't Create Breakthroughs; Just Ask Apple and Ikea" http://identi.ca/url/39222176
icon
2011-09-28 20:38:50
"Logging out of Facebook is not enough" http://nikcub.appspot.com/logging-out-of-facebook-is-not-enough
icon
2011-09-22 07:10:58
nice mobile emulator (chrome extension) http://ripple.tinyhippos.com/download
icon
2011-09-15 11:03:48
"hello world" in trollscript :-) "Because Brainfuck is so last year, right?": http://tinyurl.com/3twg2xp
icon
2011-09-10 21:31:07
8. bottom line from @frontendconfch #fec11: auto-reload firefox page with guard-mozrepl https://github.com/guard/guard-mozrepl
icon
2011-09-10 21:27:59
7. bottom line from @frontendconfch #fec11: no more inspiration @smashingmag http://ustre.am/:19ZEP
icon
2011-09-10 21:27:45
6. bottom line from @frontendconfch #fec11: css3 for backgrounds @LeaVerou http://ustre.am/:19Z2a (47:22)
icon
2011-09-10 21:27:28
5. bottom line from @frontendconfch #fec11: more cursors in css3 @LeaVerou http://ustre.am/:19Z2a (32:55)
icon
2011-09-10 21:27:05
4. bottom line from @frontendconfch #fec11: css3 gradients @LeaVerou http://ustre.am/:19Z2a (36:10)
icon
2011-09-10 21:26:47
3. bottom line from @frontendconfch #fec11: custom checkboxes in css3 @LeaVerou http://ustre.am/:19Z2a (28:18)
icon
2011-09-10 21:26:27
2. bottom line from @frontendconfch #fec11: javascript unit testing with buster.js @cjno http://ustre.am/:1a01x
icon
2011-09-10 21:25:52
1. bottom line from @frontendconfch #fec11: make designs in the browser, not in photoshop! @bastianallgeier @LeaVerou @jng5 @smashingmag
icon
2011-08-25 21:34:27
Andrew Lawrence: "I admire these phone hackers. I think they have a lot of patience. I can't even be bothered to check my OWN voicemails."
icon
2011-08-25 21:02:59
Why MSTest is the IE6 of unit test frameworks: http://osherove.com/blog/2011/8/24/why-mstest-is-the-ie6-of-unit-test-frameworks.html
icon
2011-08-15 11:41:28
great advertising... http://www.youtube.com/watch?v=rJRiz9aSHFQ
icon
2011-08-05 10:43:52
My diploma work was published as a book: http://tinyurl.com/3ujy8db. A bit outdated matter though...
icon
2011-07-20 14:28:24
how standards proliferate: http://xkcd.com/927/
icon
2011-05-10 12:06:13
#minusshare was added to the official min.us tools page: http://min.us/pages/tools
icon
2011-02-19 01:25:04
Share files on min.us from windows explorer context menu: https://github.com/koffeinfrei/MinusShare
icon
2011-02-01 21:32:52
[zueribad-wintray] http://bit.ly/eBD2LT lex - fixed license file
icon
2011-01-30 19:46:28
[zueribad-wintray] http://bit.ly/dZ02k8 Alexis Reigel - * release 0.1.3
icon
2011-01-30 19:46:24
[zueribad-wintray] http://bit.ly/h30HJw Alexis Reigel - * updated icon * added license and autostart to setup
icon
2011-01-29 23:05:38
[zueribad-wintray] http://bit.ly/fLoUAB Alexis Reigel - * version 0.1.2
icon
2011-01-18 08:12:19
Used to working on a terminal (linux)? Windows console sucks. http://tinyurl.com/23ll4l a pretty decent windows console replacement.
icon
2010-11-30 18:29:10
Jason Fried: Why work doesn't happen at work: http://www.youtube.com/watch?v=5XD2kNopsUs
icon
2010-09-12 13:40:22
[batchreplacer] http://bit.ly/cCYITS koffeinfrei - 3 commits
icon
2010-07-26 11:46:49
Everybody needs a fishbowl: “YouTube - Barry Schwartz: The paradox of choice” — http://www.youtube.com/watch?v=VO6XEQIsCoM
icon
2010-06-18 09:07:19
@kentbrew: what i'm i missing? the #identica-badge doesn't show my entries on http://koffeinfrei.org/
icon
2010-06-16 08:00:30
“YouTube - BP Spills Coffee” — http://www.youtube.com/watch?v=2AAa0gd7ClM
icon
2010-06-01 20:03:29
"The surprising truth about what motivates us”: http://www.youtube.com/watch?v=u6XAPnuFjJc&feature=player_embedded

Ying and Yang

where I am
where I should be
Fork me on GitHub