What I use VIM for?
I am not a big fan of “Use everything in Terminal”. Not because I am not comfortable with terminals and TUI, but I understand and miss the lacking features of GUI in a TUI in this twenty first century. Let’s talk about the details and causes for this on some other post for now.
I use VI/VIM only when I had to edit a file quickly and I am in a terminal for some work. So, for this reason, I do not need to turn VIM into an IDE like IntelliJ of Visual Studio. All I want is a very simple editor with just the basic information I need to make my editing comfortable while I am in a terminal.
So, this are the features I need in a text editor:
- (Obviously) Vim keybindings.
- Syntax highlighting with as much languages supported as possible. Because I will not know what type of file I have to edit!
- Very simple configuration overhead. I want to manage just a single file with easy setup. As you might see, I will be trying to avoid some configuration paradigm. So that, when I am in a new setup, I will install VIM (from now, NeoVIM), download and put the file where it is needed and I am all set.
- Autocompletion for popular languages.
Why I wanted to switched to NeoVIM?
There are tons of reasons anyone can find in online to switch from VIM to NeoVIM. So in this section, I am not going to restate or go over those. I am pointing just some key points that I must had to say:
- Better API and well documented. So if I ever wanted to debug a plugin written for NeoVIM, or wanted to contribute to my daily used text editor, I will have the benefits.
- Extensions support any language! (which was not the case in VIM where you’ll have to learn vim script)
- Front and Backend is decoupled. This opens possibility to embed NeoVIM anywhere you want!
- As I can see in the internet, the world is moving on. So why not me.
Lets switch!
Before starting the switch, here is the old vimrc
I use.
|
|
Now, first things first. Install NeoVIM. You can look over their website to know how to install in your operating system. As I am using arch based distro, the command is:
|
|
I found most of the “switch to NeoVIM” blog posts mentioning that it has no problem starting up with the existing vimrc
file. But I got a lot of error messages (I solve some of them, but it became cumbersome at a moment, see image below) starting up NeoVIM after installation. As I had time, I preferred to manually move all the configurations from the old vimrc to NeoVIM.
VIM basically uses ~/.vimrc
file for its startup. I used to use a trick to move this .vimrc
file from ~
(home) to ~/.config/vimrc
. The trick is to put these 2 lines in any of your init files (in any linux OS). I put them in my ~/.zprofile
.
|
|
This works because, VIM uses VIMINIT
environment variable to execute. If VIMINIT
is not set in your path, then it looks for ~/.vimrc
. This is also same for NeoVIM (I am not 100% sure about this though).
But NeoVIM follows the XDG Base Directory Specification out of the box. So it used ~/.config/nvim/init.vim
file for its init configuration. I do not need those 2 lines anymore.
As I am using vim-Plug for plugin management, I need to set it up first. In vimrc
, I used the auto-installation code snippet if found here. What it does, is it automatically installs vim-plug if it is not already installed in VIM. Vim-Plug does not have any snippet in their tips page for NeoVIM. After digging a bit, I found this issue where some people suggested similar snippets. After some inspection, I picked the snippet below:
|
|
After this, I copied and pasted all the Plug '...'
commands in the right places. The only plugin that did not work for me was vim-eunuch. This plugin adds some UNIX shell commands to use inside vim to do sudo
operations.
I searched if there is any alternative plugin for NeoVIM, but unfortunately found this issue. Also another very similar plugin SudoEdit.vim stated the following in their FAQ:
Plugin doesn’t work in neovim, how to make it to work?
Yeah, it is a known problem that neovim broke compatibility here. Since I am not using Neovim, I am not able to fix it.
So, I gave up hope and started using sudo nvim
to edit files which I am not the owner of. If you knew any better way or a plugin, I will really appreciate to know 😄.
vim-system-copy is a plugin I use to copy the visual selection from vim to the system clipboard. Vim needs to be compiled with an additional flag to support system clipboard management. On the other hand, NeoVIM supports system clipboard management without any additional compile flags. Inside NeoVIM, there is a variable named clipboard
you can use.
So instead of using that plugin, I put this line in my nvim/init.vim
file.
|
|
Finally after removing unnecessary lines, the bare-bones config file for my NeoVIM is given below:
|
|
Conclusion
As stated in the beginning of this article, I am not a hardcore vim user. I just like the modal editing of vim. So switching to NeoVIM truely does not impact my workflow that much. But everytime I try to edit a file now, I face this issue:
Old habits die hard. Though there is a workaround to use alias vim=nvim
, but I prefer to make the alias in my mind.
Thanks for reading this article. Please share anything you do different than my method to switch from vim to neovim.