Category Archives: Code

vim: Binding C-i bad for tab

Note: This entry has been restored from old archives.

In the unlikely case that anyone made use of the C-i binding I suggested for toggling vim 7.0 spell-checking they may have noticed that it messed with the use of their tab key! So it turns out that tab and C-i are the same thing from vim’s point of view!

Choose a different combo. Like C-c for *c*heck, or C-s for *s*pell, that’s surely better! Meta maybe?

I’m now using C-a:

" Set spelling language.
set spelllang=en_gb
" Toggle spell checking for the current buffer with Ctrl-i
map   :setlocal invspell
imap   :setlocal invspella

Note 1: The ‘i‘ at the end of the imap is now an ‘a‘ so that the insert position comes back the same.

Note 2: The C-i is only a problem for the imap and if you remove that you can then use C-i or tab in command mode to toggle spelling and live without the ability to toggle spelling when in edit mode. This’ll clash with any other command mode binding of tab of course, but I have none. I like to toggle in edit mode though so I’ll stick with C-a for now (hrm, what does it clash with?).

Update

Of course, a few minutes later I try to use C-a for it’s normal purpose, incrementing a number under the cursor. I use this surprisingly often. *sigh*

Vim 7.0 Can Spell!

Note: This entry has been restored from old archives.

I’ve been using an external spell-checking plugin for vim for some time now. Today I upgraded my systems to vim-7.0, to do this on Debian Sarge (stable) add to /etc/apt/sources.list:

# Backports  - A "Pin" in preferences file required is to prefer backport pkg.
deb http://www.backports.org/debian sarge-backports main

And add to /etc/apt/preferences:

Package: vim
Pin: release a=sarge-backports
Pin-Priority: 999

Package: vim-common
Pin: release a=sarge-backports
Pin-Priority: 999

Then do an apt-get update and apt-get install vim.

Start up vim and do :help spell for full documentation! The first thing you’ll want to know to play with it is turning it on: setlocal spell spelllang=en_gb (for real English, surprisingly it also has en_au). It will highlight unknown words, for suggestions sit the cursor on the word and type z=.

I didn’t see anything immediately obvious in the doco for simple on-off toggling of the spell-check mode. So I knocked up this little bit of vim-code to toggle the spellcheck with Ctrl-i (more obvious combos already taken) for the current buffer (i.e. on/off is maintained independently for each buffer). This is now^W^Wwas in my .vimrc:

" Toggle spell checking for the current buffer
function ToggleSpell()
    if &l:spell
        setlocal nospell
    else
        setlocal spell spelllang=en_gb
    endif
endfunction
map   :call ToggleSpell()
imap   :call ToggleSpell()i

It’s a good thing that vim can spell, because I shore can’t.

Update:

A quick scan of some vim doco moved me to simplify the above toggle to:

" Set spelling language.
set spelllang=en_gb
" Toggle spell checking for the current buffer with Ctrl-i
map   :setlocal invspell
imap   :setlocal invspelli

Duh. 🙂

Update 2:

Silly me, there is a slight problem with binding C-i in vim.