Spellchecker in VIM

Only recently I’ve started using VIM as my default editor and… I’m amazed.

I’m not advocating here for its superiority over any other text editor. You might be into design or simply wish for a graphical interface. I’m into not-using-mouse too much, so it actually fits quite well my purposes. Having said that, it took me a while to discover it with more commands than saving and exiting.

One of the features that from the outsider point of view, i.e. myself a month ago, that it couldn’t possibly ever have is spellchecker. Not that I actively thought that vim doesn’t have a spellchecker, but rather that passively ignoring the idea of suggesting corrections in a terminal. I was wrong. Vim has spellchecker and it’s pretty good.

The magical command is:
:setlocal spell spelllang=XX
where for English XX is one of {en, en_au, en_ca, en_gb, en_nz, en_us}. If you have a problem with setting up British, like I had, try command:
:setlocal spell! spelllang=en_gb
i.e. with extra exclamation mark.

Actually I suggest mapping command to some keyboard key, so when you press it turn on/off highlighting mode. To do this edit your .vimrc file (Ubuntu: ~/.vimrc) and add following line:
:map :setlocal spell! spelllang=en_gb
which means that whenever you press key F7 it will toggle command.

Once you have this set and someone introduces mistakes into your text/code, you can simply navigate between these using ]s and [s for next and previous, respectively. Obviously you can also just navigate using keys or hjkl, but who doesn’t want to feel like hacker?

Assuming someone has played with your text and make it less perfect, you have two options:

    z=   acceptance of the mistake and listening for looking up some suggestions, or
    zw   teach your dictionary this new fabulous word, or
    zg   denial, blissful ignorance, snooze button.

If you change your mind with your last command you can undo it using zuw or zug. I suggest quick read about these commands in Quick Start from spell documentation or :help spell.

Now! The default setting for spellchecking performance are against large files/projects, like PhD thesis. If you notice that after certain line spellchecker doesn’t inform you about the obvious mistake then you should use this StackOverflow advice and increase your syn sync parameters. In short, but I suggest reading the SO question and answers (and comments), you can increase minlines and maxlines in (Ubuntu) ~/.vim/after/syntax/tex.vim with:

syn sync maxlines=20000
syn sync minlines=500

Easy clipboard in bash

Those who know me, know that I’m not a fan of using mouse. Whenever possible I try to avoid using it. Although, after years of experience, I am fluent in keyboarding there are still some tasks that I need mouse. Well, until quite recent.

The number one of annoying tasks is copying things from terminal to clipboard. Depending what exactly I needed to do with it I’d either select something with mouse and then copy, or stream output to file and then select it within editor. Some people found it weird, but yes, often copying through editor is much faster.

Revolution came with `xclip`. I’m not yet fluent in doing everything with it, but even with limited experience that I have it feels like a superpower. This program allows to copy into/from X clipboard.

Most unix distro have it installed by default or at least in package manager. In case of Ubuntu one can install it with:
$ sudo apt-get update
$ sudo apt-get install xclip

Copy current directory into clipboard:
$ pwd | xclip

Paste whatever you have in clipboard:
$ xclip -o

Copy to global clipboard so you can use in any other program:
$ echo $PATH | xclip -selection clipboard

If this is too long to type, one can always use aliases, i.e. setting shorter name for long command. Either type directly into terminal (but that is only for current terminal), or update your ~/.bashrc file with:
alias "c=xclip"
alias "v=xclip -o"
alias "cs=xclip -selection clipboard"
alias "vs=xclip -o -selection clipboard"

Then copying content of a file to a clipboard:
$ cat file.txt | cs

… and CTRL+V wherever one wishes.

Yes, this is awesome!

StackOverflow: How can I copy the output of a command directly into my clipboard?