jump to content
Snippets and tips
  1. Home
  2. Holiday
  3. Posts
  4. Tools
  5. Tags
  6. Categories

Gvim

The general goto editor if nothing else is better.

Gvim is the graphical version of vim with lots of functionality.

In fact, Gvim is the editor I used to write these pages.

Startup #

The following is part of my .bashrc. It can handle several files I want to edit. It creates the necessary directories just as Visual Studio Code does and only opens one instance.

1
2
3
4
5
6
7
edit() {
  for F in $*
  do
    mkdir -pv $(dirname $F)
    /usr/bin/gvim --servername gvim-me --remote $F
  done
}

Customization #

The real power in vim comes from the customization. Previously, I wrote a lot of C and C++ code. Hence, I had several function key mapping that invoked make from the command and the edit mode. Vim also recognizes the error format and jumps to the related lines. Now, I am using vim more like a regular editor and do programming stuff in more adapted IDE’s.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
map <F8> :make ^V^M
map! <F8> ^[:make ^V^M
map ^[^[ :x^V^M
set autoindent
set backspace=2
set shiftwidth=2
set list listchars=tab:→\ ,trailset list
set expandtab
colorscheme blue
set number

Line 1 maps the Function key 8 to make. I used to have a mapping from line 2. Now, I am mostly using line 3. Line 1 executes make when I press F8. In order to enter this into .vimrc, one has to type map followed by Ctrl-V and F8, a space and then :make finished by pressing Ctrl-V and Enter. Line 2 starts similar, but after the space one has to press Ctrl-V and Esc to get this ^[. In the vim editor, all those ^[, ^V and ^M are just one character.

Line 7 shows me tabs and trailing whitespaces, since most of the stuff I am currently working with, are complaining about those.

Plugins #

I have been using plain gvim for decades, but recently I am fond of NERDtree which includes a file explorer in a split window.