I’m very fond of Vim. It’s lean, it’s everywhere (if not, there’s vi anyway), it does the job. I also love Neovim and I’ve set it up with some plugins to ease Python development, such as vim-fugitive, a Git wrapper, and jedi-vim, autocompletion and static analysis for Python.
Undeniably, there are quite a few resources on the interwebs on how to create your “perfect” IDE out of Vim.
All nice and lovely, and it gets the job down but… sometimes some plugins let me down. They get confused, cannot find where a variable has been defined, autocompletion stops working properly and undefined vars are just not signalled. At this point I’m forced to close all my tabs and start again.
Even though it’s bearable, I got lured by some colleagues of mine to the dark side of Spacemacs, and I have decided to give that a try. Here are the bits I tweaked, to make Spacemacs feel more comfortable (to me).
The following applies to Spacemacs on Linux.
I’m still learning my ropes on Spacemacs, so it might well be that some tweaks can be done in a better way or are not effective in all edge cases. Any feedback is, of course, most welcome!
Mouse, be gone
I only use my editors in the terminal, and I tend to use the mouse the same way I use it in other terminals: selecting text copies it, the middle button of the mouse pastes it.
Spacemacs, by default, allows you to jump through the code under the mouse pointer and highlights the pointed line. This is a no-no for me.
To disable the mouse, I resorted by adding under
dotspacemacs/user-config the following line:
To completely disable the mouse, this StackExchange answer hints at downloading the
disable-mouse package and then using:
Make * and # search as in Vim
Apparently, I’m not the only one who noticed that * and # in Spacemacs do not do the RightThing(TM) out of the box: an Emacs StackExchange user asked this very question.
The answer is nice and effective: extend
There’s still an unsolved nagging, though. Searches done through * and # do not populate the search history.
Make C-a and C-x increment and decrement numbers
For this one, I had to make a compromise. C-x is used as prefix for a gazillion other commands. I didn’t feel comfortable changing the prefix of all those commands: after all, incrementing and decrementing numbers is something I do regularly, yet not very often.
I decided I could settle for C-x a to increment and C-x x to decrement. Again, StackExchange comes to help: there a user suggests that the package “evil-numbers” does just that.
dotspacemacs/user-config should be extended with these two lines:
Trim trailing spaces and newlines when saving a file
This is to comply with PEP8, mainly – though I admit I love not having trailing spaces at the end of the lines or unnecessary new lines at the end of a file.
Initially I found a solution that works fine, but is specific to plain emacs.
In Spacemacs, it turns out, there’s an easier baked-in way to do just this. Search under
dotspace-whitespace-cleanup entry and set it to
If you search some term with / and then try again later by hitting first / and then the up arrow, you’ll be disappointed to see that Spacemacs comes out of the search mode.
Fear not, for there is a solution. Extend
Display the absolute path of a file (somewhere)
I’d love to see the full path of the file I am editing.
Since C-g is not an option, given that is a pretty fundamental command in Emacs, I’d be OK settling for SPC f y as the bug report suggests.
However, to always display the path of the file being edited, you can also extend your
dotspacemacs/user-config function with:
This one is another “baked-in” value. In your
dotspacemacs/init just set
totspacemacs-line-numbers to something like
However, in the terminal, I saw that the line numbers are awfully close to the text. Others have noticed it and the fix is to add to your
dotspacemacs/user-config the following lines:
Lint as you write
In Vim I used to use python-mode.
Though sometimes it got confused and stopped working, it would catch most of the obvious issues, such as undefined names, unused variables, etc.
In Spacemacs there’s a similar checker, which is not enabled by default. For starters you have to uncomment
Once done, you can toggle the syntax checker using SPC t s.
To configure the checker (flake8, by default, if I’m not mistaken), create a
~/.config/flake8 file as described here.
You can list errors in a buffer by hitting SPC e L while there are a few other key combos worth learning.
I’ll update the post or write a follow-up on how to use pylint instead.
Opening files at a certain line
With Vim, I’d do
vim file +8 or
vim +8 file. Emacs only understand the latter:
emacs +8 file.
The reason I mention this, is because I’ve set up a function that opens a file as specified by
To give an example, suppose that
grep -rn ' x ' returns this:
somedir/fileA.txt:2873: foo x bar someotherdir/pyfile.py:28:from foo import x as y
v someotherdir/pyfile.py:28:from and be sure I’d open the file at that line.
v() function would look like:
Now, I have an
e() function that differs only by the position of the arguments:
Admittedly, it could all be done in awk, I believe, but spawning one more process is not critical in my situation.
Conclusions (for now)
There are still a few things I’m not very fond of, and I’ll try to address, namely:
- There are no tabs in Spacemacs. I simply can’t live without tabs. It’ll be a hard compromise, this one, I’m afraid.
- * and # to populate the search history – and persist across sessions! That one seems a bit fundamental to me.
- Python motions given by python-mode. I noticed [M and ]M in Vim have been translated to [[ and ]] here. Not sure how to get to classes, yet. Probably minor anyway.
- Learn how to create commands myself. Or re-learn a bunch of new commands. Again, not a biggie, I guess.
- Start-up times. Spacemacs offers you lots, but it’s a behemoth when starting up. This can be sped up I believe, by running an emacs daemon.
Overall, the first impressions are good, but there’s still some road to do before I can say I’m alright in Spacemacs.
Till next time!