Bisecting your .vimrc

Bisecting your .vimrc

When you have a problem with vim, but don’t know exactly where it comes from, many people recommend to bisect your .vimrc. Here is a small tutorial on how to do it.

The following gist contains my .vimrc that has a bug. The bug is that it is not possible anymore to mix d with /. For those that aren’t used to much vim, here is first an explanation of what d/ does

Gist to the .vimrc

What is d/ ?

In vim, you can compose actions (often also called verbs), and motions (often called nouns). For example, they is the action delete which has the letter d, and the motion $ which means go to the end of the line. Whenever you hit d$, it will delete text until the end of the line.

An other motion to move around is /, which is the search motion. You first enter /, than the text you want to search for, and press enter to go there. You can normally mix d (the delete action), and / (search motion), to delete text until the first occurrence of a text pattern.

For example, with the following file :

My dog is called Johny.

If your cursor is on the « M », and you press d/called<Enter> , the ending text will be :

called Johny.

Resolving the issue

Here is how I usually solve problems like that: I start opening two bash windows (I personally like to use tmux, which is a terminal multiplexer).

  • The first window will be to edit my .vimrc,
  • The second window to test whether vim behaves correctly with my .vimrc. In my case, I created a file test.txt with the following content « My dog is called Johny. » and run vim test.txt

Then I try to find a way to reproduce the issue. In my case, I hit : d/called<Enter>. I call this the run step

  • If no text is deleted, the bug is still present
  • If text is deleted, the bug is not there anymore.

In either case, I then go to the first window to edit my .vimrc. I then try to remove some code in my .vimrc, I usually start with plugins because they are most of the time the culprit. Here I would delete all code from Bundles up to the end of Bundle configuration.

In my case, if I then do the run step again, the problem disappears, so we have some reason to believe that the problem comes from one of the plugins. What I do next is to go back to the .vimrc file, and undo the delete. I then only delete half of the plugins that I have. Everytime the bug is still present, I will remove the remaining half of the plugins. If the bug disappears, I will undo my change and remove the other half of the plugins. I do this until I have only one Plugin enabled, which is then the plugin causing the issue.

I then get to a very minimal .vimrc which still has the bug

set nocompatible

" set the runtime path to include plug.vim
if has('vim_starting')
  " Required:
  source ~/.vim/autoload/plug.vim

call plug#begin()
Plug 'vim-scripts/SearchComplete'
call plug#end()

You can then report the issue to the plugin creator (Or decide not to use the plugin anymore)

Une réflexion au sujet de « Bisecting your .vimrc »

  1. I have been exploring for a little bit for any high quality articles or weblog posts
    on this kind of house . Exploring in Yahoo I eventually stumbled upon this site.
    Reading this info So i am glad to express that I’ve an incredibly good uncanny feeling
    I came upon just what I needed. I most unquestionably
    will make certain to don?t disregard this web site and provides it
    a glance on a constant basis.

Laisser une réponse

Votre adresse de messagerie ne sera pas publiée.