I started to toss NeoVim again, can this time replace VSC

Original link: https://innei.in/posts/Z-Turn/nvim-lua-config-init

The rendering is generated by marked, and there may be typography problems. For the best experience, please go to: https://innei.in/posts/Z-Turn/nvim-lua-config-init

0724222044.png

What can I get by using NeoVim? What are the advantages over traditional editors

Many people probably won’t read the following content, so I decided to write this part first. After reading it, decide whether to configure it, because this is a very long but enjoyable process, and you need to get used to hjkl’s horizontal movement and a large number of shortcut keys.

The biggest advantage of using Vim is that you can abandon the mouse. When writing code, there will be no pause time due to the need to use the mouse to locate. Without pause time, you can focus more on coding.

The second is that it is very fast, the startup time is within 100ms, the memory usage is very small, and the response speed is very fast, unlike some IDE 96G, the memory is not enough.

With the blessing of the plug-in, you can quickly solve the following frequently encountered problems.

  1. constituency

Selecting a block-level scope code in VSC and moving it from one place to another may require dragging with the mouse to complete the selection of the block-level scope. In NeoVim, you only need to press Enter a few times to use the increase selection of Treesitter.

In addition, NeoVim + Treesitter provides a lot of textobjects, which can be very convenient for selecting and deleting text objects.

  1. Add/modify/delete parenthesis pairings

In VSC, I don’t know how to do it in general. My words are to use the mouse to select the area with the keyboard to cut and paste, then add brackets and then paste. It takes a lot of time here. And use mini-surround in NeoVim.

  1. Fast-moving

If you see a keyword in the current view in VSC, you may need to use the mouse if you want to move the cursor to that place and enter it. But if you use the ability of flash.nvim in NeoVim. For example I want to move to console.log and delete this line.

  1. Context moves quickly

  1. fuzzy match

It is also impossible for VSC to fuzzy match content based on path and file content.


Summary

It has been 3 years since I first started contacting NeoVim (hereinafter referred to as nvim). I remember that it was nvim 0.4.x at that time. After more than half a year, it was still stuck in the dev version of 0.5 and could not wait for the arrival of 0.5 stable.

At that time, I was still writing Vue 2, and there was no telescope.nvim and nvim-lsp on nvim. Although it was no longer the era of YouCompleteMe, nvim still did not have an lsp with excellent performance. At that time, we were all using coc.nvim , which is an lsp driven by NodeJS. Because the runtime of NodeJS adopts the same interface as VSC, it is very convenient to transplant VSC plug-ins to coc. However, due to the worrying performance of coc, coupled with the rapid change of coc ecology. In the end I chose to give up using nvim as my main editor.

In the past two years, nvim has entered the era of lua. During this time, I sometimes pay attention to the nvim circle and toss and toss interesting plug-ins, but because the original configuration is basically VimScript, it is difficult to migrate to lua. Although the two can be mixed, I have long forgotten the worrying startup speed and various shortcut keys.

0724214653.png

This time I saw the video of theniceboy again, and the experience of migrating nvim configuration to lua made me feel itchy. I started to configure nvim again, and this time I completely pushed back the original configuration of more than a thousand lines.

start

Use kitty as a terminal emulator hosting nvim. Because kitty supports wavy lines, the performance is fast enough, and the rendering of characters is better than iTerm2. Its configuration is simpler than Alacritty. And its icon is very cute.

The nvim community has always been very active, and the plugin ecosystem is also huge. Currently in the community, there are the following out-of-the-box configurations:

https://github.com/NvChad/NvChad

https://github.com/AstroNvim/AstroNvim

https://github.com/LazyVim/LazyVim

From the perspective of the number of stars, AstroNvim has a lot of preset plug-in configurations maintained by the community, and the main configuration and user configuration are separated, which will be easier to maintain later, and it will not be too mentally burdensome. It is recommended for novices to use this directly, and then get familiar with the preset keys.

Note that the preset keys for each of the above are different, so once you get used to one, it is difficult to switch to another. Here you need to choose the most suitable for you.

I’m using LazyNvim .

 git clone https://github.com/LazyVim/starter ~/.config/nvim rm -rf ~/.config/nvim/.git

After installation, it can be used. The basic functions are available, and the lsp telescope treesitter is all configured. Then you can watch this video to get familiar with the basic operation:

https://www.youtube.com/watch?v=N93cTbtLCIM&themeRefresh=1

I won’t talk about it here. Those who don’t want to bother will naturally not see it here. Those who want to bother have already read the official documents. It’s useless for me to talk so much, after all, it’s not a tutorial post.

key move

As a vim party and qwerty keyboard layout, the movement of hjkl is indispensable. Use the Hammerspoon map system key to map the up, down, left, and right to <Caps-hjkl> . By the way, I am now changing the key in the settings. CapsLock is also the Control key. Control is also Control, and CapsLock is completely abandoned.

0724223606.png

The mapping hjkl is configured as follows:

https://gist.github.com/Innei/695460015ba94e8d163d3665d707c6b4

Migrating Common Configurations

As I said earlier, I had more than a thousand lines of configuration before. Although I started from scratch this time, some configurations still need to be configured.

Currently I have configured the following options, and others use the default values ​​of LazyNvim.

 local opt = vim.opt opt.clipboard = "unnamedplus" opt.wrap = true opt.clipboard = "" opt.spelllang = "en,cjk" -- vim.opt.spell = true opt.spelloptions = "camel" opt.scrolloff = 5 opt.indentexpr = "" opt.foldmethod = "indent" opt.foldlevel = 99 opt.foldenable = true opt.foldlevelstart = 99

The code folding is turned on, the system clipboard synchronization is disabled, the code is turned on beyond the line break, and the cursor is kept 5 lines from the bottom. nothing else.

Then some regular keymaps, the ; to : is still handy. From y to +"y , only y will be copied to the system clipboard. To <Cg>u is very special, it can solve nvim’s undo range is too large in the input mode. In this case, a space will be used as a memory point. The same can be done with =.

https://github.com/Innei/nvim-config-lua/blob/main/lua/config/keymaps.lua

There are also some keymaps prepared for kitty above. When using kitty, you can do some character mapping specifically for nvim. For example, I configured in kitty to send the character sequence of ⌥ P when pressing the ⌘ P combination in nvim, and then make the keymap of <Mp> in nvim to :Telescope fd to do the same as ⌘ P of VSC.

Others I did ⌘, S, ⌘, D, ⌘ C, ⌘, X and so on.

https://github.com/Innei/dotfiles/blob/master/tag-base/config/kitty/keymap.py

(This is inspired by sxyazi )

plug-in sharing

Plug-ins are the primary productivity of nvim as the main editor. I don’t recommend the one that comes with LazyNvim, everyone uses it, and the default is fine.

better-escape.nvim

The character wait after jk can be eliminated. Available, but not necessary.

https://github.com/max397574/better-escape.nvim

fedepujol/move.nvim

You can do some block-level movement of the selection.

https://github.com/fedepujol/move.nvim

LunarVim/bigfile.nvim

It can speed up large files. But I still recommend using VSC to open large files. At present, only VSC has the best support for large files, and the opening speed is the fastest and smoothest.

https://github.com/LunarVim/bigfile.nvim

dstein64/nvim-scrollview

A scroll bar indicator can be added to the right side of nvim.

https://github.com/dstein64/nvim-scrollview

Andrew Radev/switch.vim

It is very convenient to switch directly between false and true .

https://github.com/AndrewRadev/switch.vim

Wansmer/treesj

Merge multi-line scopes into one line, or vice versa, according to ast. Still very convenient.

https://github.com/Wansmer/treesj

mbbill/undotree

I haven’t used it a few times, but it is very useful in critical times. Backtrack the undo history.

https://github.com/mbbill/undotree

gbprod/yanky.nvim

Clipboard records.

https://github.com/gbprod/yanky.nvim

Eandrju/cellular-automaton.nvim

Useless things, just for fun.

Code rain.

https://github.com/Eandrju/cellular-automaton.nvim

Bekaboo/dropbar.nvim

Breadcrumb navigation similar to VSC, requires nvim > 0.10.

https://github.com/Bekaboo/dropbar.nvim

finish watching? say something

This article is transferred from: https://innei.in/posts/Z-Turn/nvim-lua-config-init
This site is only for collection, and the copyright belongs to the original author.