Abandoned

I’m ditching WordPress in favor of Jekyll/Github pages. Details can be found here on my new site. This WordPress site will no longer be maintained.

Advertisements

Why I switched from Vim to Emacs

EDIT:

As pointed out on reddit (both in r/emacs and r/vim), many of my criticisms of Vim are unfair. Everything I posted about was based purely on my personal experience with the two, but much of my critique was steeped in ignorance. That said, I won’t delete the post because I’ve learned a lot from the comments here and from the comments on r/Emacs and r/Vim. Maybe someone else who has similar issues could learn something too. I did, indeed, underestimate the Vim community! Summary: Take everything you read below with a grain of salt!

ORIGINAL POST:

When I first started using GNU/Linux, I tested both Vim and Emacs. Vim seemed
pretty intuitive and its keybindings were efficient; Emacs seemed impossible to
learn and its keybindings made little ergonomic sense. On a Stack Overflow
thread, I read about the pros/cons of both Vim and Emacs. One user noted that
you will never really be satisfied with your Emacs setup, you will constantly
be making modifications, and you will be useless if ever working from someone
else’s setup. Because of all these things, I chose Vim and became a Vim
proselyte.

Over time, however, I started finding inefficiencies in my workflow, and my
approach to using a terminal, editor, and IDEs was not sufficient. As I started
looking for solutions, I realized that Emacs held the key to all of them. I
hesitated on trying Emacs because I was well-entrenched in Vim and did not have
time to spend hours upon hours in a config file (even though deep down inside
all GNU/Linux users really do want this). Eventually, the bottleneck became
unbearable, and I stumbled upon this video which completely changed my
perspective on Emacs. The speaker in the video mentioned that Vim users could,
almost seamlessly, switch from Vim to Emacs with Spacemacs. I tried it and I was
hooked.

Below I go into more detail about the inefficiencies I found in my Vim-dependent
workflow and why I now use Emacs. For clarification, I do use the Spacemacs
distribution of Emacs, which has many features that Vanilla Emacs does not. My
explanations will focus on solutions specific to Spacemacs, but in theory what I
explain is distribution agnostic, and everything could apply to your individual
Emacs setup should you take the time to implement it.

Reasons why I switched

I didn’t have to stop using Vim

That’s right. I really didn’t switch to Emacs. I still use Vim keybindings for
everything inside Emacs. There are several ways to use Vim keybindings in
Emacs (Evil mode, Spacemacs, others?), and in my opinion, only a mad wo/man
would use Emacs keybindings long term. ‘Emacs pinky’ is no joke, though people
often seem to treat it as one. When I was considering making the switch to
Emacs, I was having considerable wrist and forearm pain (unrelated to Vim), so
an ergonomic editor was important to me. With Spacemacs, I could keep the
efficient keybindings of Vim while using something with more features.

Copying/yanking and paste from one window into another

Using Vim keybindings in Emacs through Spacemacs is such a beautiful experience.
Not only can you use Vim keybindings when writing code, you can use these
keybindings anywhere in Emacs including in shells. This is more convenient
than you might think. Say for example, you produced a typo (or multiple typos)
when issuing a shell command such as:

rn /home/user/folder1/folder1/folder3/folder4/folder5/some-file.txt

that was supposed to be written as:

rm /home/user/folder1/folder2/folder3/folder4/folder5/some-file.txt

Here, I needed to make two changes: ‘rn’ needed to be changed to ‘rm’ and the
second instance of ‘folder1’ needed to be changed to ‘folder2’. If you wanted to
modify this in a traditional terminal emulator, you would probably use the up
arrow to retrieve the last command, use the left arrow (or Ctrl-Home) to get to
the beginning of line to modify ‘rn’, then use the right arrow (perhaps in
combination with Ctrl) to modify the second instance of folder 1.

This is way easier with Emacs. Simply retrieve the previous command, get to the
beginning of the line with ‘0’, change ‘rn’, then navigate to second instance of
the number 1 using ‘/’ (or get there with ‘f1f1’). With both typos, ‘r’ can be
used to replace the errant character, instead of using a combination of arrows,
backspaces/deletes, etc. This is a Vim-approach to the terminal, all within
Emacs.

When I was using Vim, I used the terminal emulator ‘Terminator’, and would
frequently have 4-5 windows open with a combination of shells and files. Now
what if I wanted to copy a terminal command from one window and place it in a
code file? Or copy a command from one code file and place it into another code
file? The only way I really figured out how to do this was by selecting text
with the mouse (which I absofruitly abhor), using Ctrl-Shift-c to copy, and
Ctrl-Shift-v to paste in the new window. With spacemacs this is incredibly
simpler. Simply navigate to the window with your shell, use ‘yy’ to yank the
line you want, and navigate back to your code file. Switching windows in
Spacemacs is effortless (e.g., ‘SPC-1’ gets you to the first window), it can be
done without leaving the home row, and all of this copying/yanking and pasting
can be done {without the mouse}.

Trying to use Vim as an IDE

For a while, I was using Vim as my editor and debugging code in IDEs like
RStudio and PyCharm. Even though you can use Vim keybindings in both of these
IDEs, it was a pain switching back and forth between code, the console, the
variable explorer, etc. I also spend a great deal of time in the terminal, and I
use multiple languages in single projects, so having a language-specific IDE was
inconvenient. Because of this, I tried to turn Vim into an IDE with NerdTree and
Airline, but I never was able to get debugging to work inside Vim (some claim
to have accomplished this, but I never could get these solutions to work).

Some may argue against using Emacs as a full-fledged IDE, but it works fine for
me. For example, I can use Emacs as an R IDE with the Emacs Speaks Statistics
(ESS) package. I can edit, step line by line, and debug a code file; use
R-dired as a variable explorer; and enter console commands all within one
frame. It all feels like a more customizable experience that I have more control
over than a pre-packaged IDE. Emacs is more than an editor and even more than an
IDE; some view Emacs as basically a entire operating system (more on this in
the Tetris section).

Duplicating my setup

I work on many different machines and I like consistency. Unfortunately, I am
also very picky about my setup. Duplicating my Vim setup on a new machine
involved installing Vim, cloning my .vimrc from my Github dotfile repository,
creating a symbolic link from my cloned .vimrc to my ~/.vimrc, downloading the
several Vim themes I like to work with, installing Vundle, and then using Vundle
to install my Vim packages! Nightmare.

This is somewhat easier with Emacs (but still not without a little manual
labor); here, I first install Emacs (which you have to build from source on
Ubuntu to get an up-to-date version that will work with Spacemacs, which is why
I ultimately switched to Arch Linux. That’s right, I changed operating systems
because Emacs is easier to install on Arch. My next post ought to be ‘Why I
switched to Arch Linux’), clone my .spacemacs from my Github dotfile repository,
and create a symbolic link from this .spacemacs to ~/.spacemacs. Upon starting
Emacs, everything is installed for me, including themes. No installing a
package manager like Vundle manually. No downloading theme files individually
(this could be automated with Bash, I admit, but this would still be more work
than it is with Emacs). Installing packages in Emacs, in general, is very easy.

Philosophical approach

Some people hate the ‘philosophical baggage’ of the Free Software Foundation
(FSF) (of which Richard Stallman, the creator of Emacs, is Founder and
President), but I think the philosophy is very important. Then again, I am an
idealistic academic. Ironically, I see few academics committed to producing Free
Software (let alone using Emacs) though most of them are in publicly funded
positions. That said, Emacs introduced me to the FSF and its philosophical
goals, which align with my goals as an academic (the FSF probably wouldn’t like
that I’m using Arch Linux, but it’s certainly better than Ubuntu).

Community

The Vim/Emacs debate is often heated, but from what I can tell, Emacs users are
more passionate. There are a number of Emacs meetups around the country where
users share their setup and demonstrate useful tricks. Maybe this exists for
Vim, but the Emacs community is more visible. Vim is an incredibly useful tool.
But Emacs is a lifestyle. That was corny, I know.

Vim doesn’t have Tetris

Emacs has Tetris and Vim does not. The debate ought to end here.

But seriously, for someone who finds their workflow driven by the terminal, the
editor, and/or the IDE, this exposes an important aspect of Emacs – You can
live inside it. Here are some things I do in Emacs that I could not do in Vim:

  • Use the terminal (through eshell)
  • Check the weather (using forecast.io/dark sky API)
  • Use Google (using helm-google)
  • Check/send email
  • Write academic papers (using org-mode)
  • Keep track of my todo list and calendar (using org-mode)

Instead of using the terminal to launch Vim and open specific files, Emacs is
always open, and the items above are opened in buffers within Emacs. Some
people complain about the long load time of Emacs, but this is a non-factor for
me. My workflow is driven by Emacs; I rarely ever close it!

Org mode

Org mode is absofruitly incredible. Some people use Emacs just for org-mode,
including people who are not programmers. I first learned about some of the
features of org-mode as a tool for writing in this video, but these
videos would also be good starting points for org-mode.

Org mode is a tool for writing, creating outlines, keeping track of your
calendar, and much more. In fact, this post was created exclusively using
Spacemacs/org-mode and then exported to html.

Emacs is fun to learn

Any Vimscript that I learned was purely out of necessity, and most of the
Vimscript I used was simply copied from the internet and pasted into my .vimrc.
This was a pretty laborious process that I did not enjoy. Emacs is different.
Creating an Emacs configuration is fun. I find that I actually look forward to
learning Emacs-lisp, and doing so feels more meaningful than learning Vimscript.
I’m often shocked at what is available in Emacs, and I’m constantly finding new
ways to improve my workflow with it.

Conclusion

After being a Vim proselyte and then switching to Emacs, I’ve come to this
conclusion: Vim is not really an editor; it is set a keybindings. Sure, it can
be used as an editor (and I still use it as such occasionally), but Vim’s main
contribution is its keybindings, which are in fact, the best, and utterly
irreplaceable to me (I even use Vim keybindings in my web browsers).

Emacs is not really an editor to me either. The more I use Emacs, the more I
agree that it is virtually an operating system. It can be used as an editor, an
IDE, a terminal, an email client, a word processor, a calendar, a todo list, and
a life organizer. The Spacemacs motto sums up the Vim/Emacs debate perfectly:
“The best editor is neither Emacs nor Vim, it’s Emacs and Vim!” The two are
not mutually exclusive. In fact, they work wonderfully together.

Despite this, Spacemacs/Emacs is still not perfect, and I do still find some
barriers when using Emacs:

  • I haven’t found an Emacs terminal that I am completely sold on; that said, my
    ideal terminal might not exist yet. Eshell has 95% of what I need (and I use
    it the most often) but lacks support for shell input redirection, for example.
    When I need this, I open terminator instead. I always have issues getting Vim
    keybindings, among other things, to work in Ansiterm and Multiterm, and in
    general these emulators seem clunky.
  • I’m having problems with org-agenda that currently have me relying on Google
    Calendar as my main scheduler.
  • Email often has HTML content (which can’t be rendered in Emacs as far as I
    know), so I often use a web client instead.
  • Using interactive shells such as the Mongo Shell (MongoDB) and Psql
    (PostgreSQL) often don’t work as intended, and some of these projects are not
    maintained
  • Not everyone uses Emacs, so collaborating on projects can result in extra time
    conforming/converting to de facto industry standards. For example, I
    frequently share manuscripts with colleagues, and exporting from the de facto
    industry standard word processing program (which will go unnamed) is not ideal
    from Emacs. Because of this, I am currently exporting .org documents into
    LibreOffice (which works quite nicely) before sending to colleagues. After
    sending to colleagues however, I have to stick with either LibreOffice or the
    unmentionable de facto industry standard so that I can view comments, respond
    to comments and track changes. I’ve seen rumors on the internet that this can
    be resolved, but I have yet to figure it out.
  • Leaving Emacs to use a web browser is not the end of the world, but it would
    be nice to have a high quality web browser inside Emacs.

I have a feeling that much of this could be resolved if I either searched harder
for a solution, or created solutions myself. All in all, I am much happier with
my workflow not that I’m using Emacs. If you have recommendations on how I could
better use Emacs, please let me know!

Installing and QGIS and PostgreSQL/PotsGIS on Ubuntu

I work on many different machines and somehow find myself frequently getting a hold of new computers, reinstalling OS’s, etc. It’s a pain to reinstall some of my commonly used software as it often involves consulting multiple sources to get the configuration that I’m looking for. Further, many step-by-step installation instructions on blog sites don’t worked for me.

Lately I’ve been better about keeping track of the specific packages/sources/respositories I use, and someday I hope to be able to simply execute a bash script after an OS re/install that adds a set of repositories and installs a list of software packages automatically (it would also be nice to execute a script that creates symbolic links to my .rc and config files in my cloud storage as well.. know anything about this or have any tips? Let me know!).

This guide will serve as a future reference for myself and will hopefully help others as well.

PostgreSQL/PostGIS

The lines below install PostgreSQL 9.4 with PostGIS 2.1 (along with some other stuff like PG Admin 3). This method is taken in bits and pieces from the PostGIS users wiki.

 
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt trusty-pgdg main" >> /etc/apt/sources.list'
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.4-postgis-2.1 pgadmin3 postgresql-contrib-9.4
sudo apt-get install postgis

 

For some reason, certain tools, like shp2pgsql are not included in the packages listed in the fourth line of code above, but

 sudo apt-get install postgis

takes care of this and completes the installation for me. Occasionally, you may need to do

sudo service postgresql restart

after installation. Also, you will need to create a user name with something along the lines of

sudo -u createuser -s desired_user_name

It is often convenient to use the same user name as your Ubuntu user name.

QGIS

The following lines of code install the current unstable version (QGIS 2.14 Essen) on Ubuntu 14.04. This installation method is an agglomeration of those from the QGIS docs and a @DPSSpatial GIS Stack Exchange answer .

sudo sh -c 'echo "deb http://qgis.org/debian trusty main" >> /etc/apt/sources.list' # add repository to sources.list
sudo sh -c 'echo "deb-src http://qgis.org/debian trusty main" >> /etc/apt/sources.list' # add repository to sources.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 3FF5FFCAD71472C4 # add verification key (you'll get an error on all apt-get in the future without this)
sudo apt-get update # update repositories
sudo apt-get install qgis python-qgis qgis-plugin-grass # install qgis with pyqgis and grass as well

 

After this, I immediately install several plugins:  Load QSS – UI Themes (for the dark theme) and Open Layers (for basemaps).

Ubuntu Essentials for Productivity

Six months ago I made the switch to Linux (Ubuntu 14.04). Since then, my productivity has increased exponentially. I’m still learning and finding new tools all the time, but below are some of the tools that have aided me (in no particular order). My philosophy in choosing research tools is centered on efficiency, reproducibility, and accessibility. I try to use the terminal as much as possible and the mouse as little as possible.

1. Terminator

This is my favorite terminal emulator. With it you can split terminal windows vertically or horizontally (or both). Other terminal emulators, such as Guake and Final Term, have similar features (see 20 Useful Terminal Emulators for Linux). For more information on Terminator see Terminator Introduction (the image and installation method below is from this site).

terminator-mad.png

To get it, type:

sudo apt-get install terminator

2. Vim

Vim is a text editor that runs directly in the terminal (and works nicely with Terminator). It has innumerable keyboard shortcuts for navigating/editing documents, syntax highlighting galore, and can easily be customized. Some complain that the learning curve is steep, but my advice is this: bite the bullet and go for it. In the long run it will pay off. After one full day of using Vim, I couldn’t really imagine using gedit or nano again.

Selection_002

Many distributions of linux come stock with Vim, but in case yours does not:

sudo apt-get install vim

Many users have uploaded their own vim color schemes that you can use. My personal favorite is behelit (shown below):

Selection_001

3. Gnome Desktop

I really like the look and feel of Unity (Ubuntu default), but I’ve had more success/fewer issues with Gnome. This might be due to the fact that I’m using multiple monitors including one that is 21:9 (for which Gnome possibly has better support).

To get gnome desktop type:

 

sudo apt-get install gnome-shell  
sudo apt-get install ubuntu-gnome-desktop

 

Be sure to select the ‘gdm’ option if/when prompted. Gnome has a nice shortcut for moving windows between monitors: Ctrl – Alt – 4 (move to left monitor) and Ctrl – Alt – 6 (move to right monitor). You can snap windows to the left or right side of the screen with Ctrl – Super – left/right (also works in Unity).

4. Glances – system monitor

This is a system monitor that runs in the terminal and looks absolutely rad. It’s great for monitoring CPU usage, RAM usage, and temperatures. And let’s be honest – it just looks amazing.

Selection_001

To get it, type:

sudo apt-get install python-pip build-essential python-dev
sudo pip install Glances
sudo pip install PySensors

(method taken from this Ask Ubuntu question)

To start glances, simply type ‘glances’ in the terminal.

5. Google Chrome with Vimium

Nothing against Firefox; I just like Chrome. You can watch Netflix in Ubuntu on Chrome, and the Vimium extension is fabulous. By hitting the ‘f’ key, Vimium maps a keyboard combination to every possible link, button, and textbox on the page making web browsing much faster. The commands are similar to those in Vim, hence the name.

To get Google Chrome, you can download the .deb file from Google and double click on it in Nautilus, or you can run the following commands:

cd /tmp
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get -f install

(Method taken from this Ask Ubuntu question)

You can find Vimium here. Below, the yellow boxes reference the key combination to navigate to each respective link. These are toggled on/off with f/Esc.

Selection_003

6. Zsh with Oh my zsh

This is my most recent addition, and I absolutely love it. I may be slightly theme obsessed judging by how much time I spend tweaking my .vimrc, .zshrc, and terminator config. Oh my zsh wonderfully feeds my addiction. Zsh with Oh my zsh is customizable to no end, works well with other plugins, and looks fantastic. It also has (arguably) better functionality than bash, such as efficient tab completion and autorcorrect.

To get it, type

 

sudo apt-get install zsh 
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" 

 

It will prompt you for your password, automatically change your default shell to zsh. Below are some sample Oh my zsh prompts:

agnoster-vim-theme

kolo-vim-theme

junkfood-vim-theme

If you have recommendations for tools that have helped you in Linux, feel free to post below!