Redefining my vim workflow

I use vim for my everyday things. No, actually I use vim for everything.

And today I rewrote large parts of my vim configuration. Here's why.

Dead mappings

I removed a lot of mappings from my vimrc that I did not used. For example: I had a mapping in normal mode that'd fire up fzf for the complete filetree I was in. I didn't use it in months, maybe more, because I use netrw (the vim-builtin file manager).

I don't need plugins

Well, at least you don't need the most of them. First, I removed maybe three or four plugins I didn't use at all, for example the “linux-kernel-style” plugin or “Goyo” and “Limelight”. Not because I didn't like them (I do, believe me), but because I simply did not use them at all. I also removed everything with snippets, because I barely used them. So “UltiSnips” and all the snippet packages are gone now.

Then, for example, I had the vim plugin “vim-indent-guides” with a great snippet of viml I found online:

" Simple replacement for vim-indent-guides
"
" unicode characters explained:
" tab: \uBB == ">>"
" trail: \uB8 == "-" in red box
exec "set listchars=tab:\uBB\uBB,trail:\uB7,nbsp:~"
set list

This does the very same as indent-guides and even does more, because I can have a dot (unicode character \uB7) if there is trailing whitespace at the end of a line. I really like that!

vim as server

Because I'm running XFCE, as explained in another post for some time now (and I still like it), I figured that I could use gvim instead of commandline vim. But gvim startup time is not that great – so I figured that I could use the awesome vim server capability to have only one running vim instance.

So I re-configured my aliases to be

alias vim="vim -g --servername VIM --remote-tab-silent";

for example, so I automatically start in a running gvim instance (which has the name VIM by default). If no vim instance is running, this automatically starts a new gvim instance.

But because I'm a notorious :q-hitting vimmer, I remapped :q:

if has("gui_running")
  cnoremap <silent> wq<CR> w<bar>bd<CR>
  cnoremap <silent> q<CR>  bd<CR>
  cnoremap <silent> x<CR>  bd<CR>
  nmap <Leader>q :bd<CR>
endif

So when I hit :q it actually executes bd, which just closes the current buffer. If the current buffer is the last buffer, it enters an anonymous buffer instead. This is really awesome! To actually close my vim session, I have to :quit now, which is longer and therefor I have more time to stop myself from doing that.


Edit 2017-03-06:

The code above did not completely work as intended, so I changed it to the following:

if has("gui_running")
  fu! CloseWindowOrBuffer()
    if winnr('$') == 1
      if bufnr('$') == 1
        :echo "Closing last instance not allowed"
      else
        :bd
      endif
    else
      :close
    endif

  endf
  nmap <Leader>q :call CloseWindowOrBuffer()

  cnoremap <silent> wq<CR> w<CR>:call CloseWindowOrBuffer()<CR>
  cnoremap <silent> q<CR>  :call CloseWindowOrBuffer()<CR>
  cnoremap <silent> x<CR>  bd<CR>
else
  nmap <Leader>q :q
endif

I'm still not sure whether this is what I want.


env!

Finally, I set my $EDITOR and $GIT_EDITOR variables to

export EDITOR="vim -g --servername VIM --remote-tab-wait-silent"
export GIT_EDITOR="vim -g --servername VIM --remote-tab-wait-silent"

To get the best experience when calling vim through scripts or other programs like git.

What I want to get from this

Well, I made my vim installation a lot less bloated. By removing a bunch of plugins I made vim start up way faster, and by using only one vim instance for all the things, even more. Using gvim, I can have pretty fonts and so on.

I wonder how these things work out for me...

tags: #desktop #linux #vim