How Neovim Made me a Better Economist

2024-01-27

Despite the fact that I have been coding on and off for almost a decade, I am neither a software engineer, nor a computer scientist. With limited exceptions, every line of code that I have written was written (with or without the help of AI) to be useful in a particular project with a limited scope and lifespan. As a result, while I am capable of using many languages to do many things, the holes in my understanding of software engineering are massive, and substantially limit the market value of my coding skills. At least they were, until the (anti-competitive) merger of ShareLaTeX and Overleaf caused me enough mild inconveniences that I range-quit some great tools and (somewhat) accidentally find an even better one.

My Coding Background and how I came to rely upon ShareLaTeX

For most of the 2010s, I missed much of the "learn to code" trend. While I learned some of the fundamentals of computer science with a breadboard in high school, the closest I came to coding anything were completing codeacademy's free HTML course in the 10th grade, and editing the visual basic script for an excel macro I recorded to properly implement a trapezoidal Riemann sum in my summer job.

All of that changed the summer before my junior year of college. I was about to take an introductory econometrics course, and the syllabus made it clear that we would have to learn to code with something called Stata. Surveying my friends studying economics at other colleges, I found that some of them were using R, and others were using Python.

At that, I somewhat panicked. How was I supposed to learn to code something as complex as OLS regression in only a semester. To allay that fear, I spent some of my time that summer learning how to estimate multivariate linear regression in all three tools.

But, whenever I found a tutorial online, I would always see references to terms or procedures that I did not understand. Googling them led me to quickly understand just how powerful a tool coding could be. As a result, I started intermittently taking free online coding tutorials, but there was a persistent problem: as a full-time student interested in learning to code for economic modeling, tutorials on web or game development were not that interesting to me. As a result, I didn't prioritize these extracurricular lessons as much as I did everything else that goes along with college. I had learned a few techniques, and could make plots with matplotlib and command line tools to do basic math, but that was about it. The one exception to those limited skills was making LaTeX documents.

For those of you who do not know, LaTeX is a typesetting language that is commonly used in academic environments. This is because it excels at displaying math and managing citations. Unfortunately, in producing a pdf, it creates a lot of intermediate files, if you are writing a paper with a script, you lose the ability to see what you get the instant you type it, a feature that had been standard with every text editor1 I had ever used. Enter ShareLaTeX.

ShareLaTeX was a free website where you could compile and download LaTeX documents with a preview that updated as frequently as you wanted it to, while making the writing process easier with great autocomplete, unlike the default LaTeX script editor that comes bundled in the download. It also had nice error messages that seemed much friendlier than the ones I would get when I had tried to compile my papers from the command line. As a result, I started to write all of my papers and problem sets for every class with it.

I became very good at using it. I learned the keyboard shortcuts and snippet triggers became muscle memory. By the time I graduated college, I had become so enamored with it that I used it to write my resume and every cover letter I used to apply for jobs. When I came to grad school two and a half years later, ShareLaTeX was still there, my tool of choice. Of course, things were not quite the same.

An Anti-Competitive Merger

While I intend to write a more in depth takedown of anti-trust enforcement under the Trump administration, there was one merger, announced in 2017 that caused me particularly acute pain: that of ShareLaTeX and Overleaf. While the merger was announced shortly after I had started using ShareLaTeX, it took a while to be executed, so the market before the announcement was the one that I learned how to use ShareLaTeX in. In that market, there were two cloud-based free to use LaTeX compilers: ShareLaTeX and Overleaf. Overleaf was slightly larger, and while they offered roughly the same features, each member of this duopoly had a dramatically different default user interface.

Following the merger, there was one provider of that service, but the newly rebranded Overleaf v2 took pains to make users of the old platforms comfortable. When I started grad school, while both sites now directed to Overleaf's, the only change to users whose accounts had been created with ShareLaTeX was that the free plan offered fewer collaboration features.

Then, in the fall of 2022, disaster. They merged the two services they offered, and, most importantly to me, changed the default keyboard shortcuts and snippet triggers. Throughout that semester, I found completing my homework to be a more arduous task than it would otherwise be (and this was the semester I took Graduate Econometrics II, so the homework was hardly easy to being with). As a result, I resolved to spend winter break figuring out a better solution. I didn't want my workflow to be beholden to someone so removed from me.

From VSCode to Neovim

At the time, VSCode was my text editor of choice for the little coding I could do. It seemed a good choice. There were LaTeX plugins to give the functionality of ShareLaTeX. Unfortunately, however, there were two problems: It was slow and buggy, and defining snippets was complicated.

In retrospect, both of these problems were simply skill issues, but at the time, my limited technical skills prevented me from taking advantage of everything VSCode had to offer. It was probably slow because I did not appreciate how electron apps use memory, and had loaded my configuration up with plugins to meet every single task that I had attempted in the last three years. The interactions of these plugins, combined with my poor understanding of how VSCode worked probably contributed to the bugs I experienced.

As to the problem I had defining snippets, I think that the design choices made with the goal of making snippets as capable as possible came at the expense of usability. For example, to define a snippet that would trigger from beq, following the official guide, I would have to navigate several menus to what would be a blank file. To this file, I would have to add:

{
    "Equation": {
        "prefix": ["beq"],
        "body": [
            "\\begin{equation}\\label{$1}",
            "\t $2",
            "\\end{equation}$0"
            ],
        "description": "Set up an equation environment"
    },
}

This syntax isn't terrible, but it is hardly inviting.

Therefore, I decided to follow the advice of one of my professors: I switched to vim. But it was 2023, and almost everything I saw said that Neovim was superior. It was winter break, and I had time, so I loaded up vimtutor.

The motions were not as scary as twitter memes had led me to believe, and by the time the semester started, I was able to cobble together a configuration that replicated the functionality I got from ShareLaTeX. It runs fast, and my snippets are in a file called tex.snippets, with the equation environment encoded as:

snippet beq
	\begin{equation} \label{$1}
		$2
	\end{equation}

Since them, I have continued working on my configuration, and it is now more functional than ever. Still, I am more than 1200 words into this blog post, and I still haven't addressed the title.

How Neovim Made Me a Better Economist

While I am less than four years into my PhD, I think that I have learned enough about economics as a practice to know which skills are most valuable for it. Coding is far from the most important one. Still, if you aren't good enough at math to push the boundaries of theoretical knowledge (and I am not), you had better be able to code adequately.

That is because whoever's work you are building upon, they will have coded some part of it, and to make a substantive advance upon their work, you will almost certainly need to adapt what they wrote. And if you are adapting their code in a Neovim environment that you have configured for yourself, you will almost certainly have an easier time.

Your Editor is the State

What I have learned about software engineering is that, unless you are writing purely functional code, managing the state of your program is vitally important. If you are trained as a software engineer, you will have this drilled into you. If you learn how to use a programming language to estimate different types of regression, or implement value function iteration, you could easily miss it.

That is where your editor as the state comes into it. Neovim, after a fresh install is a seemingly simple program. But, by configuring it, you choose which events will trigger functions, and this fact is not abstracted from you. You can see the direct results of calling a function on the state of the program.

Configuring Your Editor is the type of Project that helps you Learn

Unlike many of the free online coding tutorials that focus on learning the fundamentals of a language, or how to complete a generic project, configuring Neovim to make my life easier was something that actually interested me. As a result, not only was I able to stay at it, but the combination of the editor's documentation, the documentation of particular plugins, and comments in the subreddit, I was able to pick up concepts that had been alien to me. This greatly increased my understanding of why code is written the way it is, and made it easier for me to read it.

Complementarity in Math and Code

I have always been pretty good at math. But the math being used in academic economics is fairly complicated, and while I can say that I have a basic understanding of most of it, there are core concepts that I still find tricky. Over the last year, however, that has been less of an issue, because I am able to look at computational implementations of the code, and by reading through the code, thinking about how the program creates and changes its state, I have been able to deepen my understanding of the math.

With this approach, I have become much better at dynamic programming and Bayesian statistics. Vim motions are also great, as are many terminal tools like tmux, fzf, zoxide, and lazygit. Neovim introduced me to all of them, but the truth is that the greater understanding of coding that I developed in configuring it reduced the amount of time I spent coding every day. Now, when I write code, what I write is more efficient, and I can reuse much more of it for similar problems.

So, I am a better coder, and better at math, and have full control of my text editor. I would still not consider myself a good economist, but I am much better than I was at the end 2022, and a good part of that is due to Neovim.

Footnotes

1

I know that programs like Microsoft Word, Google Docs, and LibreOffice are better referred to as word processors, but at the time I did not know the difference.