[ code. keyboards. terminals. cyber. ]




Now that we can use Vim to some extent, let's screw around with Vim a bit. The central config file is the .VIMRC. Here you can configure the complete behavior of Vim, plugins to be loaded at startup, syntax highlighting, the colorscheme, keymapping, etc. The .VIMRC is written in Vim's own script language VIMSCRIPT.
So we use Vim to edit the .VIMRC:

  vim ~/vim/.vimrc

As with most Linux tools, the behavior, appearance and the extension by functions of Vim is controlled and configured here. The .VIMRC is written human-readable and can be easily modified accordingly (provided you know the variables). Here are a few simple entries that make the use of Vim much nicer and more pleasant.

  syntax on (activate syntaxhighlinghting)
  set number (activate linenumbers)
  colo iwtb (use the iwtb colorscheme)
  filetype plugin on (auto highlighting with filetype)
  set laststatus 2 (activate statusline)
  set history=1000 (save the last 1000 commands)

With the 6 entries Vim can be used already better and looks much better and no longer B/W. The IWTB Colorscheme gives it by the way HERE.
These are simple extensions or options that Vim brings by default - so quasi basic configs. No extra plugins need to be installed here. But if we want to use plugins, we need an entry for the used plugin manager (in my case Pathogen). I've already gone into plugins themselves in Part IV of the little Vim series here.
To make Pathogen the plugin manager it needs the following .VIMRC entry:

  execute pathogen#infect()
  call pathogen#infect()

... and already Pathogen acts as a plugin manager.


In the .VIMRC also keys or keys can be remapped. The ESC key, for example, as an exit from the modes, still comes from keyboards of the ADM-3A computers on which vi was developed. Here ESC was right next to "Q", so much easier to reach than on modern keyboards where ESC has slipped into the bar with function keys. So why not map ESC to another key for faster switching between modes.
For this the following entry in the .VIMRC is sufficient:

  inoremap jj <ESC>

With this entry the INSERT mode can be left with the key sequence "jj". Here it makes sense of course to take a string that does not occur often in written text. The key sequence "er" would be quite fast annoying.
The basic syntax of the remapping is as follows:

  map_mode <what_you_type> <what_is_executed>

There are three options for the map_mode:
- inoremap (mapped keys in INSERT mode)
- nnoremap (mapped keys in NORMAL mode)
- vnoremap (mapped keys in VISUAL Mode)

With these options the keys can be defined very precisely.
So best to play around with Vim and pay attention to where can be adjusted and improved.

Who uses the NERDtree plugin can save the ":NERDtree" typing and map NERDtree to one of the F-Keys:

  nnoremap <F3> :NERDTreeToggle<cr>

But not only the mappings and basics are configured in the .VIMRC but also the behavior of plugins. I use the plugin "startify" - that makes Vim pretty when it is opened without a file. In "startify" you can show the last opened files but also static links to frequently used files like the .VIMRC, xmonad.hs or the xmobar-configfile - if you are creative you can add some cool ASCII art. What exactly "startify" is configured in the .VIMRC. This saves us a separate config file and the annoying search afterwards if you want to change something. My "startify" config looks like this:

  let g:startify_custom_header = [
  \ '   88  88 888888 888888 88   88 88 ',
  \ '   88  88 88  88 88     88  88  88 ',
  \ '   888888 888888 88     8888    88 ',
  \ '   88  88 88  88 88     88  88     ',
  \ '   88  88 88  88 888888 88   88 88 ',
  \ ]
  let g:startify_lists = [
  \ { 'type': 'files',	'header': ['    last modified:'] },
  \ { 'type': 'bookmarks', 'header': ['    bookmarks:'] },
  \ ]
  let g:startify_bookmarks = [ {'w': '~/vimwiki/'}, {'v': '~/.vimrc'}, {'x': '~/.xmonad/xmonad.hs'}, {'b': '~/.config/xmobar/xmobarrc0'}]

This is how Vim looks when it is started without any files to open:

So quite little code for quite a fancy result.


The statusline is a feature that every editor needs and the end-user:in needs too - be it simply to look how many lines of code you have written. The statusline can - who would have thought it - be configured in the .VIMRC.
First, as described above, the statusline is activated with "set laststatus=2" and displayed in Vim. The statusline can either display left info only, right info only, or left and right. The .VIMRC entry then looks like this:

  set statusline+=\ %F\ %M\ %Y\ %R
  set statusline+=%=
  set statusline+=\ ascii:\ %b\ hex:\ 0x%B\ row:\ %l\ col:\ %c\ percent:\ %p%%

What does all this junk mean now?
The line "set statusline+=\ %F\ %M\ %Y\ %R" starts on the left to write the assigned parameters into the statusline. The variables stand for:

%F - Shows the full path to the opened file
%M - Shows whether the file is saved or not
%Y - File type
%R - Indicates if the file is read-only

The next line ("set statusline+=%=") that follows works as a separator to split the statusline into two parts.

After that, the right side of the statusline is configured. This is done in the same way as for the left side. Let the same display as on the left side makes of course little sense:
That's why the next line looks a bit different: "set statusline+=\ ascii:\ %b\ hex:\ 0x%B\ row:\ %l\ col:\ %c\ percent:\ %p%%"

%b - Shows the ASCII/Unicode character under the cursor.
0x%B - Shows the hexadecimal poicehn under the cursor.
%l - Shows the line number the cursor is in.
%c - Shows the splat number the cursor is in.
%p%% - Shows the position of the cursor in percent.

For more information and parameters, it is always worthwhile to take a look at the help. To do this, the help file can be displayed in Vim (in NORMAL mode) with the following command. Here at the example of the Statusline Helpfile.

  help: statusline

As you can see, basic functions, colorschemes, plugins and also the statusline can be configured conveniently in one file. This is only a tiny part of the possibilities that are possible with the .VIMRC. The easiest way to find out what others have in their .VIMRC files and what you would like to have is to check out Github or Gitlab. Have fun configuring and playing around with the .VIMRC.