Hello everyone, my dear programmers, today we will step by step make from the standard vim, a full-fledged tool capable of replacing VSCode if desired.
I often hear this question from my friends. Why not use a ready-made config like LazyVim or NVChad? Well, firstly, I am the kind of person who likes to have control over all aspects of what I use. Secondly, when you say that you made your own config from scratch - it sounds cooler than just installing a couple of plugins (─‿‿─).
Can this replace VSCode? Maybe, as for me Vim is more convenient and faster to use than VSCode, but then again sometimes I also use VSCode, for some specific cases.
If you have any questions about the code, you can use my repository as a reference.
Configuration
First, you need to prepare your working environment (terminal) for correct work with vim. Preparation consists in the fact that you need to install fonts for displaying icons. Using Nerd Fonts download the fonts that you like best, but I recommend JetBrainsMono, I tried Hack, but it did not have all the icons, which is why I did not use it. Set the font in your terminal settings.
Next, install NeoVim itself on your device via the official website, or if you have homebrew, you can install it via the appropriate command brew install neovim, Linux users have their own package managers for installing packages, but I will not list them :)
And now we go to .config directory and create here the new nvim folder, this is where we will write all our code.
Basic setup
And finally we can start writing the configuration, create the init.lua file in the nvim folder. For convenience, we will split our config into different modules, but ultimately all modules will be imported into the init.lua file. For example, let's create a new file default.lua, in order for lua to recognize this file as a module we must create it in a folder called lua, otherwise it will not be visible to the main file when imported.
--init.luarequire("default")-- in the future I will not show that I import this or that file into init.lua, just know that if I write that a new file is created, then in most cases it will be imported into init.lua
Ok, let's go back to our init.lua, and install our first plugin, or rather the lazy.nvim plugin manager, through it we will install all our plugins in the future.
For further installation of plugins, we add a structure from the plugin manager and inside it we will add new plugins:
--init.luarequire("lazy").setup({})
For example, let's set a color scheme, I like TokyoNight, you can set any you like:
--init.luarequire("lazy").setup({---{"folke/tokyonight.nvim",lazy=false,priority=1000,opts={style="night",styles={comments={italic=true},},},},---})-- to apply the color scheme we write thisvim.cmd([[colorscheme tokyonight]])
Restart our nvim and all done! <( ̄︶ ̄)>
In neovim you can set your own keymap, create a new file keymap.lua, my standard layout looks like this:
The next step is to install and configure the Mason package manager, it allows you to easily manage external editor tooling such as LSP servers, DAP servers, linters, and formatters through a single interface.
mason.nvim is a Neovim plugin that allows you to easily manage external editor tooling such as LSP servers, DAP servers,
linters, and formatters through a single interface. It runs everywhere Neovim runs (across Linux, macOS, Windows, etc.),
with only a small set of external requirements needed.
Packages are installed in Neovim's data directory (:h standard-path) by default. Executables are
linked to a single bin/ directory, which mason.nvim will add to Neovim's PATH during setup, allowing seamless access
from Neovim builtins (shell, terminal, etc.) as well as other 3rd party plugins.
Restart our nvim and it should install normally. Now let's write the configuration of the package manager itself. Create a new file mason_config.lua and here we write this:
Okay, now let's set up our first language server, here you choose for which language you need to install a server, for example, I need servers for html, css, typescript, rust, tailwind and lua, in addition I will install emmet for faster work with html.
How do you find the configuration for your language? This package manager has a List with all supported language servers, look for the language you need there, in nvim through the command :Mason look for the package name as in the table, and install, then in the next column open the link to the language server, and take the configuration from there. Let's install the language server for all languages that i use as an example
For language servers sometimes you need to install additional plugins, for example, for rust you need to install rustaceanvim, or for TS - typescript-tools, and additionally a linter, so if you need to work with these languages, here are these plugins, for other languages look in the repository link to which is above
The first language server is ready, congratulations. Let's now add formatting to our code so that it looks more structured. To do this, install it via lazy.nvim and immediately write its config in a separate file formatter.lua
Now we write its configuration, for this we need to install the corresponding formatters via Mason, for example prettier for JS/TS or stylua for lua. Some language servers have ready-made formatters, for example rust_analyzer, so there is no need to configure code formatting for them. In our case, we need to install stylua for lua, which is what we are doing.