Table of Contents

  • Choose a color scheme
  • Bind keyboard shortcut to command
  • Where is vimfiles on Windows
  • GVIM fullscreen in WIN8
  • Cursor movement
  •     From hjkl to ijkl
  •     Remap line beginning and line end
  • How to exit insert mode without escape key
  • Basic commands
  •     :yy
  • VIM trick: yank the whole buffer without moving or changing cursor position

Choose a color scheme

Run command :colorscheme to select color scheme for VIM. You can press Tab to let VIM complete the color scheme name.

Light color scheme

Eclipse

vim color scheme light eclipse

The Eclipse.vim is based on Eclipse IDE color scheme which is suitable for light environment editing.

Louver

vim color scheme light louver

The Louver.vim is similar to default Visual Studio color scheme.

Bind keyboard shortcut to command

I want to bind Alt + Enter to toggle fullscreen mode in GVIM. Because bind F11 takes the following format

 
map <F11> <Esc>:WToggleFullscreen<CR>
 

So I guess the following should work

 
map <Alt-Enter> <Esc>:WToggleFullscreen<CR>
or
map <Alt> <Enter> <Esc>:WToggleFullscreen<CR>
 

But it didn't. The right way is

 
map <M-Enter> <Esc>:WToggleFullscreen<CR>
 

The GVIM keybinding convention makes me confusing, the Alt can be Alt, A or M. I have the same confusion in Emacs, its just takes time to be familiar with it.

Where is vimfiles on Windows

Here is the directive about how to install a plugin for vim

 
install details
Extract in ~/.vim (~\vimfiles on Windows). 
 

I have no idea where to extract.

Run the command :set runtimepath shows the vimfiles directory should located at the following structure

 
C:\BIN\VIM
├─vim72
│  ├─autoload
│  ...
├─vim74
│  ├─autoload
│  ...
└─vimfiles
 

GVIM fullscreen in WIN8

GVIM don't support fullscreen mode natively, any tool that users need to work with it for long enough time should have a decent fullscreen mode, Sublime did this well, not only a fullscreen mode also a distraction free mode. To make gvim fullscreen in Windows we need a plugin gvimfullscreen.dll, but it not works on my WIN8 system. Get this error

 
E364: Library call failed for "ToggleFullScreen()"
 

When execute this command

 
:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)
 

I'm using VIM 7.2.

Another solution is wimproved.vim at http://www.vim.org/scripts/script.php?script_id=5265.

Download the package and extract to the following structure:

 
 
C:\BIN\VIM
├─vim72
│      gvim.exe
│
├─vim74
└─vimfiles
    │  .clang-format
    │  appveyor.yml
    │  CMakeLists.txt
    │  LICENSE
    │  make.cmd
    │  package.json
    │  pax_global_header
    │  README.md
    │  run-tests.ps1
    │  wimproved.c
    │  wimproved32.dll
    │  wimproved64.dll
    │
    ├─autoload
    │      wimproved.vim
    │
    ├─doc
    │      wimproved.txt
    │
    ├─plugin
    │      wimproved.vim
    │
    └─test
        │  Take-Vim-Screenshot.ps1
        │  wtoggleclean-test.js
        │
        └─ref
            ├─desktop
            │      clean_dark.png
            │      clean_default.png
            │      default.png
            │      default_dark.png
            │
            └─server
                    clean_dark.png
                    clean_default.png
                    default.png
                    default_dark.png
 

Run :scriptnames to make sure the plugin is loaded.

Run :WToggleFullscreen to switch fullscreen mode. Run :WSetAlpha 200 to set the transparency, 255 is no transparency, 0 it fully transparency. Lets set the alpha value to 180.

gvim transparency wimproved vim

To bind F11 to WToggleFullscreen, put this to _vimrc file

 
map <F11> <Esc>:WToggleFullscreen<CR>
 

Cursor movement

From hjkl to ijkl

From the day one of using VIM, I feel uncomfortable about the hjkl for basic cursor movement. My favorite one is always ijkl, in Emacs I use C-i,C-j,C-k,C-l for the movement.

But I never rebind it in VIM, because it will affect too many commands.

To use ijkl add following lines

 
noremap i k
noremap I H
noremap k j
noremap j h
noremap h i
noremap H I
 

We swapped iI and hH, because H is goto the top of the screen, now its done by I, the i is line up, so i and I should be all about movement, we should never connect with any kind of insertion, its now done by hH.

Remap line beginning and line end

By default, go to line beginning and line end is $ and ^, its really just for memorize, but very counterintuitive for type. And to memory two keys that would be used everyday is really not a problem.

One option is to use h and ;

 
noremap ; $
noremap h ^
noremap u i
noremap U I
 
noremap H 0
 

The uU now replace iI, because I already use the ijkl, u defaults to undo, its better to use Ctrl - z instead.

How to exit insert mode without escape key

Its not a good idea to switch between insert mode and normal mode with different shortcuts, especially one of them is so far away.

I would like to use a single one shortcut to toggle between the two modes forth and back, and we should never worry about what the current mode is and decide which key to press, I can always hit the same shortcut. The visual mode will stick with the v key.

The following code use Alt-p to toggle between insert mode and normal mode.

 
inoremap <M-p> <Esc>
noremap <M-p> a
 

The first line will set Alt-p as Esc when you in insert mode, the second line set Alt-p to a in normal mode.

Maybe the Alt-i would be better, if there is no more important task for this shortcut.

Now you can press Alt-p to switch between insert mode and normal mode.

There are a lot choices to do this, but I find this one is OK for me.

Basic Commands

Simple explanation about commonly used Vim commands

:yy

Equals 0y$, in my configuration it will be hy;.

VIM trick: yank the whole buffer without moving or changing cursor position

Did you ever encountered the situation that in the middle of editing a file, you need to copy the whole buffer. There are a lot of ways to do this, for example in normal mode:ggvG$y but most of them can not retain your current cursor position. You need relocate your last position after the copy.

Here is a trick solves my problem. There is a command called normal in VIM. The only thing it do is translate everything you input after the command to key strokes. For example :norm gg is equal to press g two times.

So how to yank the whole buffer without change anything? :norm ggvG$y'', there are 7 commands here, the last one goes back to where you started.

Resources and links