Copy Paste for Vim in Slackware

23 Oct 2016

What better way to start off the blog, than to write a post on vim. I did most (all) of my vim learning from my workstation at work, even vimtutor (the first 25 times). And on that machine, if I felt like stealing/borrowing someone else's code snippet from the web, I'd do a selection with the mouse and then get into INSERT mode, then middle click where I want to paste my selection in.

A few months back I switched completely to Slackware, and I decided to go only-vim with it. To my surprise, I couldn't copy-paste. Everytime I tried to paste something in, it'd paste in a 0 (that should've been an indication to most people, but I'm a brick). It turned out that when compiling and packaging vim for slackware, Pat decided to compile it without X11 support. This was apparent when I finally thought of doing a vim --version, than ask google for everything.

$ vim --version
-clipboard       +insert_expand   +path_extra      +toolbar
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+digraphs        +mksession       +scrollbind      -X11

The - in the snippet above means, the support for it is not present in our vim installation. Vim ninjas would be happy with this, but I have yet to reach that level of genjutsu. But the good news is, we could grab the vim source package from a slackware ftp somewhere, manually add the changes and replace our current vim installation.

Let's Start

I'm using Slackware 14.2. So I'll download the entire vim source tree for 14.2 from a slackware ftp and put it somewhere on our computer. wget helps me with recursive file downloads.

$ cd tmp/src/
$ mkdir vim
$ cd vim
$ wget -r --no-parent --reject index.html* $MIRROR/slackware/slackware-14.2/source/xap/vim-gvim/

Usually, source based application installs involve something like

$ ./configure
$ make
$ sudo make install

The problem with this method is that, it becomes a pain in the behind, to manually take care of package management. Say a new update came out for a package, one would have to uninstall the existing installation, track all changes and then perform the same steps or sometimes more steps of the initial install, to update the package. Imagine if one has a few hundred of such application installs. This is why people prefer binary package management.

Luckily for us mortals, Slackware has a methodology called Slackbuilds, that makes compiling from source, a walk in the park. In the vim source we downloaded, find the file called vim.SlackBuild and open it in an editor. Find the line that goes config_vim --without-x --disable-gui. In the file which I downloaded, it was at line 133. Change that to config_vim --with-x. Exit from the editor and then do

$ chmod +x vim.SlackBuild # only if we can't execute the script
$ ./vim.SlackBuild

When the script finishes, it'll tell us that it created an installable package in our file system. In my case, it pointed to /tmp/vim-7.4.1938-x86_64-1.txz. Remove our existing vim install and install our new package as root.

# removepkg vim
# installpkg /tmp/vim-7.4.1938-x86_64-1.txz

That's it!. When the installation completes, we can copy and paste into vim. Do a vim --version just to confirm, if the options have changed. If you're wondering what the vim way of pasting is, it's a bit quirky. While in INSERT mode, press Ctrl-R-+. Vim will paste the last item in your clipboard when you do this. Vim makes use of things called registers for doing its magic and + is one of them. The above keystroke brings in content of the + register to the currently open file. Read more on vim registers here.

Happy vimming and have a great day!