My transition from VSCode to Neovim

I’ve always liked the idea of using a tiling window manager and customizing the hell out of it, you know, the kind of stuff you see by searching for the linuxPorn hashtag… My main problem with them is that I am very very used to GUIs, while I am fairly competent on a terminal, I have never learned to use emacs or vim. I am in the middle of transitioning to CLI based programs, on a previous post I described ncspot and mpsyt, I’ve also been looking at gomuks and ranger

I know that a lot of people use them and once you’re over the steep learning curve you can be very productive with just a keyboard, but it was only recently that I took an interest because a friend of mine pointed out that you can have auto-completion and other cool stuff in neovim (if I understand correctly it is a rewrite of vim) by means of tweaking the setup and some plugins, very much á la VSCode, which is my main text/code editor of choice.

I know, I know, I’m late to the legit text editor party but I always assumed vim/neovim was just ugly/simple text editor… I’ve been living a lie

The Neovim setup

So I took a deep dive and with some pointers from my friend I installed neovim and proceeded to tweak. This post will attempt to document the process. I use Manjaro linux but I can imagine the process would be similar for other distros. I’ll try to include some links.

I started by installing neovim:

sudo pacman -S neovim  

Then, I was pointed to to an easy way to deal with plugins: vim-plug, careful, there’s a different section for vim and neovim

sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
       https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

Then proceeded to create init.vim (kinda like neovim’s .bashrc), the complete path is HOME/.config/neovim/init.vim

" lopeztel vim config

call plug#begin('~/.vim/plugged')

Plug 'plasticboy/vim-markdown'
Plug 'arcticicestudio/nord-vim'
Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'

call plug#end()

To install the plugins within neovim, change to COMMAND mode (press ESC) and type:

:PlugInstall

This splits the window to the left, it displays the plugin list and installation status.

some useful things to know:

  • to edit files in vim/neovim, change to EDIT mode (press I)
  • to save files in vim/neovim, change to COMMAND mode (press ESC) and type :w
  • to close/quit in vim/neovim, change to COMMAND mode (press ESC) and type :q, :q! to discard any unsaved changes

A bit on the plugins:

  • Changing to COMMAND mode and typing :NERDTree will split the window to the left and show a file tree (VSCode like), see nerdtree for more info
  • nord-vim and vim-airline are more eye candy than anything, the first one installs the Nord theme‘s color palette, and the second one makes the status/tabline in neovim more visually pleasing

This is the overall look:

On to the functional stuff, since most of my work is C/C++ I decided to install Conquer of Completion or coc.vim, which according to their github it is supposed to “Make your Vim/Neovim as smart as VSCode.”.

First I had to install nodejs, their page provides a one liner but it didn’t work for me, so I did:

sudo pacman -S nodejs

Also, a language server is necessary, I found that either ccls or clangd are options, I installed ccls based on a quick online search

sudo pacman -S ccls

After that I installed the coc plugin with the vim-plug method described above (adding the line Plug 'neoclide/coc.nvim', {'branch': 'release'} to the corresponding section in init.vim). It is important to append the text from the example vim configuration to init.vim (quite long so I won’t put it here)

There are some other configurations needed for specific language support, a config file can be opened by changing to COMMAND mode and typing

:CocConfig

Which opens a file called coc-settings.json, contained in the same path as init.vim, here’s how mine is configured for C/C++:

"languageserver": {
    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "objc", "objcpp"],
      "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
      "initializationOptions": {
         "cache": {
           "directory": "/tmp/ccls"
         }
       }
    }
  } 

More configurations in the coc.vim wiki

Now what?

Now that I have a fully working installation it is time to learn to use neovim, I’ll probably spend some time on the tutorial (:Tutor in COMAND mode). In the meantime I’ll still use VSCode when in a rush to get things done

More eyecandy

My discovery of the Nord theme led me down a rabbit hole and I had to apply it to the gnome terminal and VSCode to match the look and feel. I also installed the powerlevel10k theme to my Zsh, while I was at it

Day 45 of my 2020’s

Join 100DaysToOffload!

By lopeztel

Mexican, wannabe maker and overall linux distro enthusiast. I enjoy playing around with electronics, running, painting and reading. I started blogging as therapy and got more invested recently.

13 comments

  1. @lopeztel heh, my c programming setup is extremely similar! I’m using neovim, with ccls, and even the nord theme 😃 the only real difference is I am using dein instead of vim-plug, but I’m not even really sure why I went with dein.

Reposts

  • Nicholas :elementary:

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.