Technical Articles
Why I switched to Neovim
Update: Added Configuration Video Part 1
Update 2: Added Configuration Video Part 2
Update 3: Added Configuration Video Part 3
In my professional career, I’ve exclusively used IDEs for software development even though they:
- have long startup times
- are bloated and slow
- have inefficient key bindings
- require a mouse
The reason for that is because I desperately needed (and still need) many of their features which plain text editors couldn’t properly provide, namely:
- language features for all my used languages (go to definition, autocompletion, etc.)
- a debugger
However, I really like the features of my favourite text editor Vim, it:
- is 100% keyboard driven
- has a command centric approach with a huge amount of commands
- is modal
- does not need a GUI and can run in your terminal
- is highly configurable using simple text files
- has a low memory footprint
So instead of adapting Vim to be more IDE-like, I tried to make my IDEs behave more like Vim using plugins and keybindings. Depending on the IDE, this worked to some extend, but I was never really happy with it because a lot of commands were not supported, keystrokes were occasionally ignored, many features still required a mouse and the problem of sluggishness persisted.
My most successful attempt was using VSCode with the Neo Vim extension where keybindings are not just mapped, but a complete instance of Neovim was run inside of VSCode. It worked really well, but the bloat of VSCode, which is an Electron app, still concerned me.
VSCode also introduced two very important innovations: The Language Server Protocol (LSP) and the lesser known Debug Adapter Protocol (DAP), which solve the problem of every editor/IDE having to support every programming language. Now, an editor/IDE only needs to support the LSP and the DAP. These innovations provide unified and standardised access to language and debugger features of specific programming languages.
Vim supports the LSP and DAP through plugins. Neovim is a fork of Vim and has a more modern governance structure (many contributors as opposed to only one), allowing the development of many new features, including native support for the LSP.
And now, after so many years, I finally managed to set up both the LSP and the DAP, providing Neovim with all the language features and debuggers I need. It wasn’t easy to set up and I had to write some scripts, but it works. Finally, there’s no reason to use IDEs anymore. I made the switch.
I created a short demo, showcasing some of the features.
I managed to make Neovim’s native LSP client use the LSP server of the SAP Cloud Application Programming Model (CAP) and I added syntax highlighting for cds
files. DJ Adams‘ video on cds-lsp
was of great help for me.
I can confidently say, I learned a lot during this process and I’ve grown as a programmer. I’m finally comfortable with my development setup and I’m curious of Neovim’s future innovations.
Thanks a lot for your time and keep your programming tools sharp,
David
Now THIS is the sort of blog post that I love to see on a Monday morning! Awesome and inspiring work, David, thanks for that. And I’m already looking forward to the next installment of your video series 💪(btw, subscribed!)
Thanks a lot, DJ!
Thanks for this super interesting post, David!
It's always nice to see how other developers set up their dev environments (even though I'm happy with mouse navigation 😅).
Thanks a lot Marius Obert!
Regarding speed, I'm on the
Keyboard > Mouse > Touchpad
front 🙂I actually only use the touchpad and almost never touch the mouse 🙈
Hi David,
thanks for sharing. I'm also a fan of vim for years but missed a lot of things you mentioned in your video. Curious to read your next blog / watch your next video.
Hi Helmut,
I'm glad you found it useful, here's my video on the configuration.
Best regards,
David
Great video!!
Already copied most of it to my init.vim
Is there a repository with you configuration on github?
Can't await the next video. Don't have experience with DAP so far.
Thanks a lot, Helmut!
The configuration is available here: https://github.com/David-Kunz/vim/blob/master/init.vim
Best regards,
David
This is just such a treasure! And I thought I did pretty well with my vim configuration so far. I was so wrong 😀
I absolutely enjoy how you precisely focus and how you cover exactly what needs to be told.
Thank You!
Hi Nabi Zamani,
Thanks a lot for your kind words!
David Kunz I also use vim where possible. Some awesome ideas here which I’ve now adopted. Wondering with the LSP if it’s possible to also get the annotations editors to work.
Does the cds lsp also include annotations in the cds files?
Hi Jason,
Great to see another Vim user! I haven't tried the server for annotations yet, but in principle it should also work.
There's a plugin https://github.com/hrsh7th/nvim-cmp which should allow you to use snippets from your server.
Best regards,
David
Hi David Kunz I'm trying to work out how you have got the CDS LSP working... Watching DJ's videos shows that he's using ALE for the LSP integration; however from your init.vim file I can see you're not using that.
So where do you place the CDS syntax file and what does your "$HOME/projects/startcdslsp" script look like?
Hi Jason Scott ,
Yes, I got it working with the following configuration:
// init.lua:
and the syntax file in ~/.config/nvim/syntax/cds.vim
autocomplete
David Kunz thanks. I have it sort-of working now.
I just installed the cds-lsp via npm i -g @sap/cds-lsp and pointed the startcdslsp script to the executable.
So I can start nvim and open a cds file. Syntax highlighting works... but commands like go-to-defintion and so on only work once and then not again. After the first use I get errors like this in the file:
using {
E 2 managed, ■ Artifact “managed” has not been found
E 3 Currency, ■ Artifact “Currency” has not been found
E 4 sap.common.CodeList ■ Artifact “sap” has not been found
5 } from './common';
It can no longer resolve any CDS dependencies. So I need to exit nvim and open it again for it to work each time.
btw. I'm using an init.vim file and not init.lua - however it has the same code in it like so:
Hi Jason Scott ,
Yes, init.vim is also fine!
I think you always make sure
1) to install the dependencies, so you have a local node_modules folder
2) that the root path is correct, you can check that with :LspInfo
Best regards,
David
Hi David Kunz I think I found the issue by fluke. I simply ran :LspRestart and now it all works fine and I can 'gd' and ctrl-o back all day long.
Maybe exiting neovim is not killing the cdslsp process such that all my config changes weren't taking effect?!? All good now.
Hi Jason Scott ,
That's good to hear, glad it works!
Best regards,
David
Hi David Kunz, hi Jason Scott,
I recently updated my NeoVim to v0.6.1. Then I thought it was a good idea to switch from init.vim to init.lua configuration, install the CDS language server (was not installed before) and use it in NVIM. Everything works fine except the CDS LSP.
There are lots of changes in my environment: new NVIM, new LSPCONFIG, init.lua (instead of init.vim). So there are a lot of possible causes for errors.
Would be nice if you could tell me if it's working at your side and maybe you can have a look at my configuration an give me a hint?
Here's my configuration
NVIM: v0.6.0
nvim-lspconfig: udpated to newest version on 2022/01/06
cds-lsp: Installed newest version (2022/01/05) like described in INSTALLATION.md of the npm package.
cds-lsp config in init.lua:
After I opened a cds file into a buffer the output from LspInfo looks like this:
The language server is installed and configured but it is not attached to the buffer
Output from LspInfo
I also set the log level of lspconfig to trace and looked at the log. From there I get the following info:
lspconfig log with trace level
Best regards
Helmut
P.S. I had to change the line "local configs = require'lspconfig/configs'" from your config to "local configs = require'lspconfig.configs'". Otherwise I get an error message that lspconfig.sapcds_lsp is not defined.
Hi Helmut,
Thanks for this nice write-up! At the moment I also have problems to enable the language server in cds. It's strange that LspInfo tells us that it's running, but diagnostics are not shown.
Changing the line from
lspconfig/configs
tolspconfig.configs
is correct.I will investigate further!
Best regards,
David
Hi David,
thanks for your answer. I invested already quite a lot of time (learned a lot) and thought that it's my lack of knowledge. As you face the same problem I might invest some more time at the weekend.
I will keep you up to date if I find a solution.
Best regards
Helmut
Quick update. Just installed the new nightly prerelease build 0.7.0 of NVIM. Didn't fix the problem.
Today (a year later :-D) I fixed my problem with the CDS LSP server.
To have it easier the next time I wrote a bit of documentation (not exhaustive) and added two bash scripts.
If anyone wants to have a look at it goto this codeberg repo.
Have fun with NVIM.
Helmut Tammen David Kunz the CDS LSP also does not work for me in nvim anymore. If I follow the @sap/cds-lsp installation instructions it does not result in a cds-lsp script in the .bin folder so something is wrong with the latest cds-lsp.
@jasonscott Please have a look at the comment above I made a minute ago.
Hi,
I've noticed that the latest version (@sap/cds-lsp@7.4.0) is not working as expected.
While executing this one an older version, the process keeps running as expected:
When looking at the instructions in `doc/CONTRIBUTING.MD` it is referring to 2 SAP internal github locations to report an issue... Is there somewhere else as a non-SAP employee to report this?
I could open an OSS...
Stijn
Hi Stijn Mertens , thank you for reporting.
I successfully installed https://www.npmjs.com/package/@sap/cds-lsp and it works in my Neovim instance:
Language client log: /Users/******/.local/state/nvim/lsp.log
Detected filetype: cds
1 client(s) attached to this buffer:
Client: sapcds_lsp (id: 1, bufnr: [1])
filetypes: cds
autostart: true
root directory: /Users/******/SAPDevelop/issues/cds1122
cmd: /Users/******/apps/cds-lsp/node_modules/.bin/cds-lsp --stdio
Configured servers list: sapcds_lsp, tsserver, zls, rust_analyzer
Hi Joerg Mann , could you look into this? The links in the README don't seem to work.