Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
htammen
Active Contributor

Do you, like me, like to develop your CAP projects with VIM?
I have created a git repository that creates a Docker image with which you can run Lazyvim in a container and use the language server protocol (lsp) for CAP, Typescript, json, ... .

This allows you to get a similar programming experience as in VSCode. However, the fingers stay on the keyboard and do not always switch back and forth between keyboard and mouse.

Lazyvim

What is Lazyvim? It is the newest kid in the block of VIM variants. To be exact it's not a new implementation. It is based on Neovim, a very popular vim fork. On top of this it adds a bunch of plugins and configures them as well as Neovim itself. 
In the end you get a nice editor, no it's more an IDE, in the terminal

Docker Image

The Docker image you can create with the git repository does the following

  • It`s based on alpine linux, a very lightweight linux variant that is used in many Docker images
  • It installs some linux packages that are required by lazyvim. Among them is lazygit, my prefered git client in terminal that is leveraged by lazyvim.
  • It installs lazyvim.
    Technically it's not an installation, but cloning of a git repository that replaces the default Neovim configuration files by the lazyvim ones.
  • It alters the default lazyvim configuration a bit.
    The two things worth to mention here is
    • the mason-nvim.lua file which installs some language servers and
    • the introduction of cds.lua which start the cds-lsp.

The Result

A picture is worth a thousand words. So some screenshots follow.

When you first run your Docker container you have to be a bit patient (~30 seconds) cause it does all the installation work. At the end you see something like this (have a look at the README.md to see how I handle my containers).
At this point you can press the 'q' key to close the popup and start editing your files.

lv-docker-00.png

Btw. the next time you start your container you'll see this welcome screen.

lv-docker-0.png

If you are not familiar with VIM the next step would be to press the <space> key:

lv-docker-1.png

Here you see the most important shortcuts you can use to get your work done. The pink entries immediately start an action, the violet ones show you the next level of shortcuts.
In the next screenshot you see the result of 's' at the first level.

lv-docker-2.png

To start editing a file press <space><space>. A popup opens from which you can select a file or just enter some characters to reduce the amount shown files and then select one.

lv-docker-3.png

Let's come to the cds-lsp (cds language server protocol) plugin.
I opened a cds file and added a new property 'internalnotes' to the entity Books. When I define the type and begin typing I get suggestions (code completion). See the next two screenshots.

lv-docker-4.png

 

lv-docker-5.png

 If I have an error in my cds file this is immediately shown.

lv-docker-6.png

You can navigate to the type under cursor by pressing 'gd' (goto definition)

lv-docker-7-1.png

or show all references of a type by pressing 'gr' (goto references).

lv-docker-7-2.png

If you press <shift>-k you get the documentation of the artifact.

lv-docker-7-3.png

If you want to format a single file just press 'cf' and if you want to format all your cds files use the 'format-cds' script that comes with the cds-lsp package by pressing ':!format-cds<enter>'. Here you see the results of this call

Bildschirmfoto vom 2024-03-28 10-25-30.png

The last screenshot is not from cds-lsp but shows my beloved lazygit which is also integrated into this Docker image and can be displayed by pressing '<space>gg'.

lv-docker-11.png

Conclusion

In this blog post I told you about Lazyvim, introduced my Docker image to easily use Lazyvim without manual configuration and showed you how you can easily edit cds files by leveraging the cds-lsp package.

For all those of you who like working in a terminal there is no longer a need to use VSCode.

There is much more you can do with Lazyvim and Docker but that's beyond the scope of this blog post.

Labels in this area