A quick fix for loading big Vim add ons

November 30, 2014

Reading time ~1 minute

Getting spelling right with AutoCorrect()

One of my favorite tools in vim is AutoCorrect. It works almost seamlessly with files that contain both code and writing, like Rmarkdown files, and is very good at fixing my more common typos (t-e-h, sep-e-rate and so on). Additionally, it is very satisfying to watch typos disappear as I write them.

However, there is one small issue that I could not get over - when AutoCorrect loads Vim hangs for a second or two. Not severe, but still aggravating. In fact, just aggravating enough that right on the github page it points out that calling it in the

1
.vimrc
is not the best idea. It’s just enough time that you lose focus on what you were about to do.

Losing focus

The good news is that Vim knows if it is in focus or not, i.e., it knows if you are the Vim window is the active window. This gives the chance to write a nice little bit of code:

   "How many times has focus been lost (initially = 0)
   let g:autoCorrect_run = 0

   "automatically call autocorrect if focus is lost
   function! AutoAutoCorrect()
      if g:autoCorrect_run == 0
         call AutoCorrect()
         let g:autoCorrect_run = 1
      endif
   endfunction

   au FocusLost * :call AutoAutoCorrect()

the first part creates a global variable and sets it to 0. The function

1
AutoAutoCorrect()
calls
1
AutoCorrect()
as long as the value of that global variable is 0 and then changes the value of that global variable to 1. Finally, the
1
au FocusLost
command calls
1
AutoAutoCorrect()
when focus is lost, meaning that the first time focus is lost it will call
1
AutoCorrect()
but there after it will do nothing.

All I wanted to do was use Vim and Python together

Python and Vim working together in screen. Continue reading

Running R code in secure shell using Vim

Published on October 27, 2014

Vim as a blogging tool

Published on October 20, 2014