By neildaemond, an 'any-stack' hacking grasshopper.
Taking notes while tinkering with:
'Vim as My IDE' Continued: New Plugin Manager & Intellisense via coc.nvim + LSP
The Quest Continues
In 2012, I started blogging about Vim As My Ide. At that time, I was also going to try and focus on Scala as it was all the rage. However, I didn’t like using clunky IDEs like Eclipse to develop in the Java world, and I didn’t have any pressing reason to continue. Today, I’m back on board the Scala train for work purposes and will leverage some of the newfound support for Scala that Vim has.
Thanks to VSCode, we have the Language Server Protocol (LSP)
VSCode pioneered the usage of LSP, and it seems that Vim’s version 8.0 (partial support) and 8.1 can now connect to Language Servers, providing the Holy Grail that programmers search for: Intellisense (code completion, function lookups, etc.)
The Vim Plugin, which enables the most advanced support at the moment, appears to be coc.nvim.
At the moment, I’m preparing Vim as my (Scala) IDE so I look to Metals - a “Scala language server with rich IDE features”.
Upgrading vim to 8.1 for coc.nvim compatibility
My package manager on Ubuntu 18.04 didn’t have vim 8.1, so I had to install from source (where I was able to enable more goodies like python, lua, and ruby). I followed this gist:
# remove current vim | |
sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-gui-common | |
# removes current link for vim | |
sudo rm -rf /usr/local/share/vim /usr/bin/vim | |
# add ppa for newest version of ruby (currently, as of 06/06/2017, ruby v2.4) | |
#sudo apt-add-repository ppa:brightbox/ruby-ng | |
sudo apt-get update | |
# installs everything needed to make/configure/build Vim | |
sudo apt-get -y install liblua5.1-dev luajit libluajit-5.1 python-dev python3-dev ruby-dev ruby2.5 ruby2.5-dev libperl-dev libncurses5-dev libatk1.0-dev libx11-dev libxpm-dev libxt-dev | |
#Optional: so vim can be uninstalled again via `dpkg -r vim` | |
sudo apt-get -y install checkinstall | |
# clones vim repository so we can build it from scratch | |
cd ~/software_from_src #or whereever you keep things which are built from source | |
git clone https://github.com/vim/vim | |
cd vim | |
git pull | |
# In case Vim was already installed. This can throw an error if not installed, | |
# it's the nromal behaviour. That's no need to worry about it | |
make distclean | |
# update to use the correct python 2.7/3.x config path also change 'YOUR NAME' to | |
# your real name | |
./configure \ | |
--enable-multibyte \ | |
--enable-perlinterp=dynamic \ | |
--enable-rubyinterp=dynamic \ | |
--with-ruby-command=/usr/bin/ruby \ | |
--enable-pythoninterp=dynamic \ | |
--with-python-config-dir=/usr/bin/python \ | |
--enable-python3interp \ | |
--with-python3-config-dir=/usr/bin/python3 \ | |
--enable-luainterp \ | |
--with-luajit \ | |
--enable-cscope \ | |
--enable-gui=auto \ | |
--with-features=huge \ | |
--with-x \ | |
--enable-fontset \ | |
--enable-largefile \ | |
--disable-netbeans \ | |
--with-compiledby="Neil Pahl <neil@neilpahl.com>" \ | |
--enable-fail-if-missing | |
# this this is the compilation step. It should also create the symlink of the binary | |
# one /usr/bin folder | |
make && sudo make install | |
# To be able to access the new vim instaltion we need to refresh bash/zsh/fish | |
exec bash # or exec zsh or exec fish | |
#check vim version | |
vim --version | head |
A new plugin manager?
Amongst the research, I’ve discovered a new Plugin Manager in Town.
Since 2012, I’ve used various vim plugins and I’ve been installing them using Pathogen plus a Ruby script which downloads plugins off of GitHub. My vim setup is kept on neildaemond/np-vim and as of today, the README contains the following:
Generally, I use The Pathogen plugin to manage my plugins, and I strongly reccomend you switch to using it too. | |
The update_bundles script was written by Tammer Saleh, and published by him in his blog post which talks about why we should switch to Pathogen plugin for vim: | |
http://tammersaleh.com/posts/the-modern-vim-config-with-pathogen | |
His update_bundles script will remove plugins from the bundle folder, then grab the most updated version from their respective git repositories. You can modify that script to include/exclude your vim plugins which reside in ./bundle | |
//no longer using scala... so ignore the following block | |
//I have added scala support for exuberant-ctags by adding a .ctag file containing regex expressions found on | |
// | |
//http://latestbuild.net/scala-ctags-and-vim-tagbar | |
// | |
//to add scala support to ctags, copy the .ctags file to ~/.ctags. | |
// | |
//update_external_configs.sh will copy files such as .vimrc and .tags to their locations outside this folder. Be carefull that you don't overide your own settings. | |
In the .vimrc, "set tags=/usr/local/src/tags" loads the tags which I made from various source code kept in /usr/local/src. The 'tags' file is made using exuberant-ctags: | |
cd /usr/local/src/ | |
tags -R * | |
you can adjust this to suite your own source code locations. | |
I've started using neocomplete for elm development, but that requires vim to be compiled with lua. To install vim that is compiled with lua and other goodies, see https://gist.github.com/neildaemond/1fb83611a84c4ea19ec1fd462e47d081 | |
Otherwise, you'll have to comment out the neocomplete related items in .vimrc |
vim-plug is the real deal
Although through the years my ‘Pathogen + ruby script’ plugin strategy has served me well, It seems like the modern way of doing plugin management in Vim is via vim-plug. The major benefit of using this plugin manager is that you can install based on the plugin repo’s branch/tag/commit. The benefits listed on the GitHub page are:
- Easier to set up: Single file. No boilerplate code required.
- Easier to use: Concise, intuitive syntax
- Super-fast parallel installation/update (with any of +job, +python, +python3, +ruby, or Neovim)
- Creates shallow clones to minimise disk space usage and download time
- On-demand loading for faster startup time
- Can review and rollback updates
- Branch/tag/commit support
- Post-update hooks
- Support for externally managed plugins
So far, I’m really enjoying the balance of simplicity and power that it offers.
Still wrestling with coc.nvim
I’ve been trying to use coc.nvim over the past week or so, but it’s been quite unstable for me so far - I’m pretty sure it has to do with my configuration. I’ve been trying to set it up to work for a variety of languages and filetypes right away, and I think all of the settings and npm packages are conflicting with each other at times.
I think I had better start using it for a language and fine-tune the configurations over time to ensure a more stable environment.
Therefore, for now, I’ll settle for the ‘out-of-the-box’ experience that VSCode can provide. See From Vim to VSCode
This way, I can focus on getting things done first and over time, ideally, I will tweak my vim setup for specific languages as I go along.
#Vim #Metals #Scala #IDEs #Vim-Plug #Coc.nvim