This article isLearn Neovim full configuration and escape VSCodeThe second in a series

Please subscribe on Github

This chapter describes the basic configuration of Neovim

The configuration file

The Neovim configuration file is not.vimrc

Instead, it is saved in ~/.config/nvim/init.vim

Lua. To ensure compatibility with older versions, or if something is somehow configured in Lua, I still use init.vim.

But init.vim is only the entry point, and the real configuration is the other Lua configuration files that are loaded

Call lua in.vim

You can write lua code directly from init.vim, like this

Lua print(' lua')Copy the code

Multi-line call

Lua <<EOF print(' lua') print(' lua'Copy the code

Load other Lua files in.vim

Loading lua files in Neovim works like this

Lua require('basic') lua require('basic')Copy the code

My current configuration file structure looks something like this. These will be described in subsequent chapters

├─ Init. vim Import File, ├── basic.Lua ├── KeyBending. lua ├─ LSP ├── lua ├─ lua ├─ basic.Lua ├─ lua Bending. lua ├─ LSP │ ├── └─ Diagnostic_signs. Lua │ ├─ Language_servers. Lua │ ├─ nvim-cmp-config All the addons are configured in this folder. │ ├── Bass Exercises. Lua │ ├─ Nvim-Autopairs. Lua │ ├─ Nvim-colorizer Lua │ ├─ Heavy Exercises. Lua │ ├─ heavy Exercises. Lua │ ├─ telescope ├ ─ └─ plugins. Lua setup managementCopy the code

Init. vim configuration entry

Init. vim is the entry file that is responsible for loading various Lua files, corresponding to the above structure.

If you can’t find a way to set it in Lua, use vim script here.

"Lua require('basic')" Packer plugin management lua require('plugins') "shortcut mapping lua require('keybindings')" skin Settings" https://github.com/ellisonleao/gruvbox.nvim set background=dark " or light if you want light mode colorscheme gruvbox " Lua require('plugin-config/which-key') lua require('plugin-config/nvim-treesitter') lua require('plugin-config/telescope') lua require('plugin-config/nvim-autopairs') lua require('plugin-config/nvim-tree') lua require('plugin-config/bufferline') lua require('plugin-config/surround') lua require('plugin-config/comment') lua require('plugin-config/nvim-colorizer') lua require('plugin-config/rust-tools') " lsp lua require('lsp/nvim-cmp-config')  lua require('lsp/diagnostic_signs') lua require('lsp/language_servers')Copy the code

The first line in init.vim

"Lua require('basic')Copy the code

This line loads the corresponding lua/basic.lua

The configuration here looks a bit too much, much more complex than VSCode, mainly due to the historical default configuration that doesn’t make sense.

In fact, do not tangle too much, I also refer to a lot of god configuration are almost the same, the basic can close your eyes directly copy.

It can be fine-tuned as needed, and most are annotated

Basic Configuration description

-- UTf8 vim.g.encoding = "UTF-8" vim.O.filencoding = 'UTF-8' -- jk moves 8 lines above and below the cursor Vim.wo. Number = true Vim.wo. Relativenumber = true -- Highlight the row vim.wo. Cursorline = true -- display the left icon column Vim.wo. Signcolumn = "yes" -- reference line on the right, over means code is too long, Consider the newline vim.wo. Colorcolumn = "80" -- indent 2 Spaces equals a Tab vim.o.tabstop = 2 vim.bo.tabstop = 2 vim.o.ofttabStop = 2 Vim.o.shiftround = true -- >> << move length vim.o.shiftwidth = 2 vim.bo.shiftwidth = 2 -- new line aligned with current line, Void replace TAB vim.o.xpandTab = true vim.bo. expandTab = true vim.o.autoindent = true vim.bo.autoindent = true Vim. O.martindent = true -- search is case-insensitive, Unless you include uppercase VIm.o. GNOrecase = true vim.O. Smarcase = true -- do not highlight vim.O. Search = false -- search vim.o. search = true as you type The command line height is 2 to provide sufficient display space. The command line height is 2 to provide sufficient display space. Autoread = true -- Disallow line folding vim.o.rap = false vim.wo. Wrap = false -- End of line can skip to next line Vim. O.house = "a" -- prohibit creation of backup files vim.o.backup = false vim.o.writebackup = false vim.o.swapfile = false -- smaller updatetime vim.o.updatetime = 300 -- "> < mappings > < vim. O. Size = 100 -- Split window" > < "vim. O. size = true Vim.g.com pleteopt = "menu, menuone noselect, noinsert" -- style vim. Onychoteuthis ackground = "dark" vim. O.t ermguicolors = true Vim.opt. termguicolors = true -- display of invisible characters, Vim.o.list = true vim.o.list = "space:·" -- Complete enhancement vim.o.west menu = true -- Dont' pass messages to |ins-completin menu| vim.o.shortmess = vim.o.shortmess .. 'c' vim.o.pumheight = 10 -- always show tabline vim.o.showtabline = 2Copy the code
  • Init. vim complete file
  • Basic. lua complete file

After rebooting Neovim should look much better, next article will introduce my Neovim shortcut key configuration.

  • Next chapter:Neovim shortcut key configuration
  • Back to the home page:Learn Neovim full configuration, escape VSCode