Commands

How to insert text at beginning of a multi-line selection in Vim

  1. Press Esc to enter 'command mode'
  2. Use Ctrl+V to enter visual block mode
  3. Move Up/Down to select the columns of text in the lines you want to comment.
  4. Then hit Shift+i and type the text you want to insert.
  5. Then hit Esc, wait 1 second and the inserted text will appear on every line.

How to insert text at end of a multi-line selection in Vim

  1. Press the v key to enter Visual mode.
  2. Move the cursor around to select lines of text.
  3. Press the : (colon) key to enter Command mode.
  4. Type norm A followed by the text that we want to insert.
  5. Press the Enter key.

Color Schemes

you can type :colorscheme . You can use tab to cycle through the installed colorschemes.

Autocomplete

CTL-p in insert mode

Ctrl-P toggles paste mode when in Insert mode do not include the two /

set pastetoggle=/ "Ctrl-P toggles paste mode when in Insert"

:set paste

:set nopaste

Removing lines

If something has double linespaced your text then this command will remove the double spacing and merge pre-existing repeating blank lines into a single blank line. It uses a temporary delimiter of ^^^ at the start of a line so if this clashes with your content choose something else. Lines containing only whitespace are treated as blank.

%s/^\s\n\n+/^^^\r/g | g/^\s$/d | %s/^^^^.*

Printing

set pdev=printer_name

HP_Deskjet_930C

Printing from Vim is not like any other application since it has both console (Vim) and desktop (GVim) versions running off the same backend. On Linux, it does not show a Print Dialog, where I can pick the printer and other print options like number of pages per side, orientation and duplex. So, I print to a PDF file, open it in a PDF viewer and print from there.

To print to a PDF file from Vim: :hardcopy > out.pdf

To print to a PS file from Vim:
:hardcopy > out.ps

Date Stamp

nmap i=strftime("%Y-%m-%d %a %I:%M %p")

imap =strftime("%Y-%m-%d %a %I:%M %p")

Now you can just press F3 any time inside Vi/Vim and you'll get a timestamp like 2016-01-25 Mo 12:44 inserted at the cursor.

For a complete description of the available parameters check the documentation of the C function [[http://www.cplusplus.com/reference/ctime/strftime/|strftime]]

vim add charcter to end of line

:%norm A*

This is what it means: % = for every line norm = type the following commands A = append '' to the end of current line