[Scroll down to Step 1. for the tl;dr if you’re using any Debian based Linux distribution]
[EDIT: You should probably know the basics of how Vim works before trying this out and at least spend a few hours familiarising yourself with it]
Those of you who are in the sciences, engineering, economics etc. will probably be familiar with LaTeX. Most of us use LaTeX instead of MS-Word or Google Docs or some other word processor to type up papers, books etc., and it is the standard in scientific publishing for the most part.
However, writing in LaTeX can be extremely time consuming and irritating for many of us who aren’t great typists. I can write on pen and paper faster than I can type and so far, typing things out in LaTeX has been an extremely painstaking exercise.
Like many others, I started off with ShareLaTeX/Overleaf, which are web based LaTeX compilers. The advantage to this is that all the compilation etc. happens online and you simply download the files at the end. You can pretty much do it off any device that connects to the internet, including an iPad (which I used as my main device for a rather long time) or even a mobile phone (extremely inadvisable). The disadvantage to this is the fact that it doesn’t support macros or snippets (to the best of my knowledge in the very least) and in my experience, Overleaf’s support for some syntax can be somewhat patchy at times.
The next step for me was to use it by natively by installing TeX Live and using VSCode Studio as my editor of choice. Using various plugins etc., this was a major quality of life improvement over using an online service, although speed was still an issue.
I recently came across this blog by Gilles Castel who is a student of mathematics at KU Leuven and claims to be able to type out notes in LaTeX as quickly as the instructor is delivering their lecture in class. It’s worth going through his entire process, because it’s truly remarkable. He’s clearly spent a while in setting up his snippets and while I do not necessarily need to type fast enough to keep in a class (I can’t type that fast anyway), it convinced me that the use of snippets would greatly speed up my workflow on LaTeX.
My first instinct was to try and replicate some of that snippet functionality myself in VSCode Studio, but writing my own snippets from scratch would take a long time. Gilles’ has shared his own snippets on GitHub, but these are coded in a way to work with Ultisnips, which is a plugin that is exclusively compatible with Vim and its forks, and won’t work with VSCode Studio. [If there is a way to make them work, let me know, and it would make this pretty redundant]
Hence, I decided to bite the bullet and use Vim as my primary text editor even with its notoriously steep learning curve. What distinguishes Vim from other text editors like say, VSCode Studio or Sublime Text, is that it’s meant to be used entirely from the keyboard. In fact, natively, Vim doesn’t even care about what you’re doing with your mouse. Everything from navigation, to scrolling etc. is done exclusively via the keyboard. This necessitates a certain syntax and use of commands in Vim that other text editors and IDEs don’t require, and this does require some investment on part of the user to learn (although it’s not as daunting as it might appear at first). However, those who actually use Vim, swear that it makes them faster than anyone using a more modern text editor because they can do everything from their keyboard itself without moving their hands to reach for the mouse. Whether this setup works for you or not depends entirely on whether you want to invest that time in getting to be decent at using Vim as opposed to having to code all your snippets by yourself.
The following things will work for you if you have Linux or a Mac with an x86 processor (I’m not sure whether all of this works well with the new Macs running Apple processors, but they will work fine on the older Macs with Intel processors). Instead of going through the complexity of Windows and its Linux subsystem, and then finding out Virtual Machines kept fucking up even though I’d enabled hardware virtualisation in my BIOS, I decided to simply dualboot my desktop with both Windows and Linux. I’m using PopOS which is based off Debian like Ubuntu. I tried using Manjaro(based off Arch), but I ran into some problems earlier with that. The following steps can be replicated by copy-pasting into your terminal on a Debian based Linux distribution (PopOS, Ubuntu etc.), you’ll have to modify things a little if you’re using an Arch based distribution like Manjaro or if you’re using a Mac. I’d like to test these things out further on those platforms, but frankly, I don’t trust myself, so you’ll have to figure that out by yourselves (I’m sorry). However, if you’re still on Windows, simply download something like Ubuntu or PopOS and dualboot your computer with that. If you’re hardcore enough to use Arch, you don’t need this tutorial and you should tell me instead.
I wasted an entire day trying to get all this up and running, and I suspect that many who would benefit from such a setup are much like me, not much of computer nerds. I spent an inordinate amount of time trawling the web for resources etc., ran into multiple errors and whatnot; so the following will be a way to avoid all that (probably). This is probably a quick way to save you some time.
Step 1.
The very first thing you should do is check if Vim comes bundled with your OS or not. I’m using PopOS and it didn’t for me.
In the terminal, simply type the following and hit enter:
vim
this should either fire up vim or it will tell you that Vim is not installed and give you a list of Vim and Vim-like editors to install. If you don’t have Vim, in the terminal:
sudo apt-install vim
[btw if at any stage, your OS asks you for permission to do anything, always respond with yes i.e. y
]
Once you’ve installed Vim, you now need to install LaTeX and its compilers and everything from TeXLive package:
sudo apt-get install texlive-full
This will probably take a while. After this is done, you will need to install git, xdotool and Zathura (Skim instead of Zathura if you’re using a Mac, I guess). Zathura is going to be your pdf reader in this case.
sudo apt install git-all
sudo apt install xdotool
sudo apt-get install zathura
[You can also install zathura packages for reading djvu, postscript/ps and cb files]
This is it for Step 1. If you want a more modern looking version of Vim, feel free to install Gvim. I did this by going the app store on my distro [Pop!_Shop] and downloading that, although this is strictly not necessary. Moving on to Step 2.
Step 2.
This step is about configuring Vim to handle plugins. By default, there should be a (hidden) configuration file. Sometimes, there isn’t one. To check, do this in your terminal:
vim ~/.vimrc
If it opens up a new file, in Vim simply enter:
:wq
[: enters the command mode, ‘w’ means save and ‘q’ means quit]
Else, if you see a pre-existing file with the same name, just
:q
To enable plugins, I used vim-plug. To get this, in your terminal, enter:
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
This will enable plugins in Vim.
Now, we need to edit that vimrc file. A good basic vimrc configuration comes from Shankar Kulumani. His vimrc file doesn’t just work for Linux but also for Mac.
As before,
vim ~/.vimrc
Now, your vimrc file should be blank. We need to replace it with this config. Copy Shankar’s vimrc config on GitHub from your browser, then go back to Vim. Hit I on your keyboard (this puts us into Vim’s insert mode) and then Ctrl+Shift+V. To install Ultisnips, go the part in the vimrc file where it says
call plug#end()
Go to the line above and copy-paste:
Plug 'sirver/ultisnips'
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
Now hit :w
To install all these plugins,
:PlugInstall
That’s it, you’re done.
Wrapping Up
Now you can write LaTeX files as you please. To compile, in Vim, make sure you’re out of insert mode (you do this by pressing escape) and-
:VimtexCompile
A pdf output should be generated side-by-side Vim on Zathura. Every time you hit :w from thereon out, you should see the pdf updating as well. If you’re adding references, I think you need to compile every time you do so to run biber. Happy LaTeXing!
Some further edits:
Merely installing ultisnips is obviously not going to install those snippets. For that, you have to download Castel’s tex.snippets file to the correct directory i.e. ~/.vim/UltiSnips/
You should make the necessary edits to make the snippets work for you. You very well might find a different mnemonic works better for you than Castel’s. You can also use the template to make newer snippets.Pranav Manerikar has some useful tips
I did all of this ages ago but had to go back to texstudio etc since vim doesn't seem to have very good support for bibliography. The hacks that I tried by using zotero were unwieldy. If you could get bibtex etc to work well, let us know.