2021-12-02
Setup VS Code as NIM IDE
Learn how to set up VSCode as a Nim IDE from scratch. Includes instructions for downloading VSCode, installing the Nim extension, configuring settings, and debugging Nim code.
Introduction
Nim is a statically-typed, imperative programming language that is designed to be efficient, expressive, and easy to learn. It is often compared to other programming languages like Python, C, and Go. One of the great things about Nim is that it can be used to create efficient command-line tools, web servers, and desktop applications.
In this tutorial, we will go over how to set up Visual Studio Code (VS Code) as a Nim IDE (Integrated Development Environment) from scratch. This includes downloading VS Code, installing the Nim extension, and configuring the necessary settings for debugging and code completion.
Installation steps
1. Download and Install VSCode
The first step is to download and install VS Code. You can do this by visiting the VS Code website (https://code.visualstudio.com/) and selecting the appropriate download for your operating system. Once the download is complete, simply follow the instructions to install VSCode on your computer.
2 Install the Nim Extension
Once VS Code is installed, open it and press Ctrl+Shift+X (Cmd+Shift+X on macOS) to open the Extensions pane. Search for "Nim"
and select the "Nim" extension by "Konstantin Zaitsev" and click on the install button. This extension provides syntax highlighting, code completion, and other features for Nim development.
3. Configure the Settings
Now that the Nim extension is installed, you can configure the settings to make your Nim development experience even better. In VSCode, go to File > Preferences > Settings
(Code > Settings > Settings
on macOS) and search for "Nim". From here, you can configure settings such as the path to the Nim compiler, the formatting of the code, and the behavior of the code completion.
4. Download Nim
You will also have to download the Nim compiler, which you can do from the official website (https://nim-lang.org/install.html). Once downloaded, you can add the bin path of the Nim compiler to your environment variable. On macOS, you can brew install nim
.
Check if Nim is installed with:
nim --version
you should see something like this:
Nim Compiler Version 1.6.10 [MacOSX: amd64]
Compiled at 2022-11-21
Copyright (c) 2006-2021 by Andreas Rumpf
active boot switches: -d:release -d:nimUseLinenoise
Now write and compile first program. Create text file hello.nim
with content:
echo "Hello world!"
Then compile:
nim c hello.nim
output
Hint: used config file '/usr/local/Cellar/nim/1.6.10/nim/config/nim.cfg' [Conf]
Hint: used config file '/usr/local/Cellar/nim/1.6.10/nim/config/config.nims' [Conf]
.........................................................
CC: ../../usr/local/Cellar/nim/1.6.10/nim/lib/std/private/digitsutils.nim
CC: ../../usr/local/Cellar/nim/1.6.10/nim/lib/system/dollars.nim
CC: ../../usr/local/Cellar/nim/1.6.10/nim/lib/system/io.nim
CC: ../../usr/local/Cellar/nim/1.6.10/nim/lib/system.nim
CC: hello.nim
Hint: [Link]
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
26644 lines; 0.776s; 31.555MiB peakmem; proj: /Users/krystian.safjan/hello.nim; out: /Users/krystian.safjan/hello [SuccessX]
Time to run it:
./hello
output:
Hello world!
5. Create a new Nim file
Now that everything is set up in the system, you can create a new Nim file in VS Code by going to File > New File
and then saving the file with a .nim
file extension. You can now start writing Nim code, and use the features provided by the extension such as syntax highlighting, code completion, and debugging.
For example, create file hello2.nim
with content:
echo "Hello world!!!"
and hit the Run button (triangle), and in the output window you should see:
[Running] nim compile --verbosity:0 --hints:off --run "/Users/krystian.safjan/hello2.nim"
Hello world!!!
[Done] exited with code=0 in 0.959 seconds
6. Debugging
For the information on debugging in VS Code, you can refer to the official documentation Debugging in Visual Studio Code and guide specific for the Nim language: A walkthrough for setting up debugging of Nim code in VSCode
Conclusion
Setting up VSCode as a Nim IDE is relatively easy, and provides a great development experience. The Nim extension provides a wide range of features that make Nim development much more efficient and enjoyable.
References
- Editor Support · nim-lang/Nim Wiki · GitHub
- A walkthrough for setting up debugging of Nim code in VSCode
Any comments or suggestions? Let me know.
Credits:
To cite this article:
@article{Saf2021Setup, author = {Krystian Safjan}, title = {Setup VS Code as NIM IDE}, journal = {Krystian's Safjan Blog}, year = {2021}, }