Original link: https://blog.kelu.org/tech/2023/06/06/vim-ide.html
Document the process of configuring neovim. I am already a veteran of vim, so the related content of vim is omitted.
install neovim
apt install neovim
view version
nvim --version
The version is too old, uninstall it.
sudo apt remove neovim sudo apt remove neovim-runtime
Update to latest version . Currently the latest version is 0.9. Download the installation package :
wget https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz tar zxvf nvim-linux64.tar.gz ./nvim-linux64/bin/nvim
Below is the default configuration.
I adjusted the installation location, and made a soft link to the system path:
mv nvim-linux64 /var/local ln -s /var/local/nvim-linux64/bin/nvim /usr/local/bin/nvim
Install NvChad
Nerd Font font (can be skipped first)
Note: This part can be skipped first, and then deal with it after it is fully installed
After installation, if no fonts are installed, there will be a question, why is there a “? box” in front of the file name? Just no fonts.
Nerd Font : https://github.com/ryanoasis/nerd-fonts/releases/latest
Nerd Fonts is a font tinkering project for developers with a high number of glyphs. The project patch includes more than 50 patched fonts from Hack, Source Code Pro, and Termius custom fonts from three Nerd Fonts including Fira Code, JetBrains Mono, and Meslo.
Font installation is only related to your local device. On which platform we display content (using a terminal), we install fonts on that platform.
under linux
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/SourceCodePro.zip unzip SourceCodePro.zip -d /usr/share/fonts/SourceCodePro
Make sure the font is placed:
under Mac
Search for “font”:
Drag the following font file into it:
Then configure and use this font in item2:
And you’re done:
under iOS
Refer to this answer from reddit: https://www.reddit.com/r/ish/comments/nuzvir/how_to_install_nerd_fonts/ ,
-
Download Fontcase
-
download fonts
https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/SourceCodePro.zip
Throw it down a path.
-
Fonts import & install
-
Download fonts after install
-
It needs to be installed in the system, and installed in the path General > VPN & Device Management:
-
The imported fonts can be used in specific apps. For example, I can set this font in iSH:
ripgrep
ripgrep is a line-based search tool that recursively searches the current directory for a match to a regular expression pattern. It is required to use the telescope.
By default, ripgrep respects gitignore rules and automatically skips hidden files/directories and binaries. It supports Windows, macOS, and Linux, and offers binary downloads. This tool is similar to other popular search tools such as The Silver Searcher, ack, and grep. It can replace many other search tools because it includes most of their functionality and is often faster.
How to use it can refer to https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#basics
I download the deb package and install it under Debian:
curl -LO https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep_13.0.0_amd64.deb sudo dpkg -i ripgrep_13.0.0_amd64.deb
sharkdp/fd
fd is a program for finding entries in the file system, a simple, fast and user-friendly replacement for find. It is required to use the telescope.
I download the deb package and install it under Debian:
curl -LO https://github.com/sharkdp/fd/releases/download/v8.7.0/fd_8.7.0_amd64.deb sudo dpkg -i fd_8.7.0_amd64.deb
Install NvChad
I don’t want to use the default neovim configuration, just make a backup of the configuration file and install NvChad
cd ~/.config mv nvim nvim_bak git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1 && nvim
Check plugin dependencies
Type nvim
in the terminal to open neovim. Direct keyboard input :checkhealth
, and then press Enter to execute to check whether the dependencies are complete:
Ps: This automatic prompt is really easy to use
There are still many problems found.
Follow the prompts to fix related issues.
Neovim directory structure
NvChad shortcuts/keymaps
https://nvchad.com/docs/config/mappings
-
Default mappings are defined in
core.mappings
.vi /root/.config/nvim/lua/core/mappings.lua
-
In nvim you can use
NvCheatsheet
orTelescope keymaps
to list all mappings.
I don’t know what the reason is, no matter how I modify it, the shortcut key just doesn’t work.
I checked tmux.conf, vimrc, bashrc, zshrc and other related files, but I still can’t solve it.
You can only use Neovim’s default shortcut key combination Ctrl+w, plus other keys. Although it is not convenient to use it like this first, I will study it later:
- +hijk is the activation of the left, bottom and right windows
- +w return to the previous window
- +n/s is desktop horizontal split
- +v is the vertical split of the desktop
- +o closes all other windows
- +r switch left and right windows
In addition, there are (I’m not sure whose shortcuts these are, but they work in neovim)
- Ctrl+O/T, open the history file in the buff backward in the current window.
- Ctrl+I, forward the history file in the buff in the current window.
Common command commands
Commands in command mode
- help help
- NvimTreeToggle, open/close file tree
- checkHealth
- Lazy View the plugins and plugin loading status managed by Lazy
- Telescope find_files query file name
Telescope live_grep query content - The homepage of nvdash Neovim, you can change the theme, open files and other operations
Manage plugins
lazy plugin management
NvChad uses lazy.nvim for plugin management. When a plugin is loaded, the plugins it depends on will also be loaded automatically.
Enter Lazy
in the command mode of the nvim interface to enter the management interface, display the loading status of the plug-in, install and update the plug-in, analyze the loading time of the plug-in, etc.
Telescope fuzzy search
telescope.nvim is implemented by Lua, supports extensions, and has very powerful functions. It supports almost everything that can be listed in the list, for example:
- File content fuzzy search
- Tag symbol search
- LSP Definition/Reference Search
- Diagnostic information preview
- Treesitter Symbol Search
- Git commit history search
- Git file change preview
You can check if it is installed:
Later I completed the installation of fd.
In addition, because my shortcut key is really not debugged successfully, I use the command to enter for the time being:
:Telescope find_files
The interface is as follows, the search speed is the same as flying
According to the official github , there are several commands:
" Find files using Telescope command-line sugar. nnoremap <leader>ff <cmd>Telescope find_files<cr> nnoremap <leader>fg <cmd>Telescope live_grep<cr> nnoremap <leader>fb <cmd>Telescope buffers<cr> nnoremap <leader>fh <cmd>Telescope help_tags<cr>
At the same time Telescope also manages several other plugins:
- plenary.nvim:
- plenary.nvim is a general-purpose Neovim Lua tool library that provides a set of functions and utility functions to help simplify the development process of plugins.
- It contains many commonly used functions, such as asynchronous task management, time processing, table operations, file system operations, etc. Plugin developers can use these features to build more advanced and complex plugins.
- plenary.nvim is a dependency library for many Neovim plugins, including telescope.nvim.
- extensions:
- extensions is a telescope.nvim plugin extension mechanism for adding additional functionality and integration to telescope.nvim.
- extensions can provide telescope.nvim with integration with other plugins and tools, extending its search scope and functionality. For example, there are specialized extensions for integration with Git, LSP, file preview, etc.
- The extensions use the tools and functionality provided by plenty.nvim for seamless integration with telescope.nvim.
NvimTreeToggle File Tree
Used to toggle showing and hiding the File Explorer window in Neovim. Works in conjunction with two other plugins to get the job done.
- nvim-tree.lua:
- nvim-tree.lua is a file browser plugin written in Lua language that can display and manage file and directory structures in Neovim.
- This plug-in provides a wealth of functions, such as opening, creating, deleting, copying, renaming and other operations of files and directories, and supports iconized file display.
- nvim-web-devicons:
- nvim-web-devicons is a Neovim plugin and utility library for adding icon displays to files and directories.
- This tool library provides a series of icons for displaying corresponding icons in the file browser based on file type, extension, etc.
nvim-treesitter syntax highlighting, code navigation
nvim-treesitter provides powerful syntax parsing and code analysis functions, enabling you to write and understand code more efficiently. It uses the Tree-sitter engine, an efficient and extensible parser capable of fast and accurate parsing of various programming languages.
Features of nvim-treesitter include:
- Syntax Highlighting: Provides more accurate and richer syntax highlighting with accurate syntax tree-based analysis.
- Automatic indentation: According to the structure of the syntax tree, the indentation of the code is automatically adjusted to make the code more clear and readable.
- Smart abbreviation: According to the understanding of the syntax tree, intelligently expand and complete the abbreviation of the code.
- Intelligent selection and operation: According to the knowledge of the syntax tree, provide more intelligent selection and operation functions, such as selection of functions, classes, conditional statements, etc.
- Code navigation: According to the structure of the syntax tree, functions such as jumping to definitions, finding references, and code browsing are provided to facilitate code navigation and understanding.
- Code refactoring: Based on the syntax tree information, provide code refactoring functions, such as renaming variables, extracting functions, etc.
- Error and warning prompts: According to the analysis of the syntax tree, more accurate error and warning prompts are provided to help you find and fix problems in the code.
When I checked, I reported two warnings:
nvim-cmp framework
nvim-cmp is a code completion framework for Neovim designed to provide flexible, highly configurable and extensible code completion functionality. It is designed to meet the needs of different users and integrates with other plugins and completion sources.
Here are some key features and functions of the nvim-cmp framework:
- Multi-source support: nvim-cmp supports many different completion sources, such as buffer completion, LSP completion, path completion, etc. These sources can be selected and customized according to the user’s configuration and needs.
- Powerful configuration options: nvim-cmp provides a wealth of configuration options that can be customized through Lua code. Users can configure the behavior, appearance and interaction mode of completion according to their own preferences and needs, so as to realize a personalized completion experience.
- Asynchronous processing: nvim-cmp uses asynchronous processing to improve the response speed and efficiency of completion. It can acquire and process the data of the completion source in the background to avoid blocking the user’s editing operations.
- Plug-in integration: nvim-cmp can be integrated with other plug-ins, such as syntax checking plug-ins, code snippet plug-ins, etc. This allows completion to work better in conjunction with other features and tools, providing a more comprehensive and powerful development environment.
- Event-based trigger: nvim-cmp provides a flexible trigger mechanism, which can trigger the completion function according to user-defined rules and conditions. This allows completion to be triggered automatically when the user wants it, providing a more seamless development experience.
- Smart sorting and filtering: nvim-cmp provides a smart sorting and filtering mechanism that sorts and filters completion candidates based on context and user input, ensuring that the most relevant and useful options are displayed first.
In NvChad it integrates the following plugins:
-
luaSnip:
- Plugin function: luaSnip is a code snippet plugin for Neovim, which allows you to define and use code snippets to improve the efficiency of code writing. In addition, using luaSnip can also help avoid the possibility of errors when writing code by hand.
friendly-snippets:
- Plug-in function: friendly-snippets is a collection of friendly code snippets that contain a large number of common programming languages. It is compatible with luaSnip plug-ins, and can be used as luaSnip’s snippet library, providing rich code snippets to choose from.
-
cmp-buffer:
- Plug-in function: cmp-buffer is a source plug-in of nvim-cmp, which is used to provide buffer completion candidates. It can perform completion in the currently open buffer, providing corresponding candidates for selection.
-
cmp-nvim-lsp:
- Plugin function: cmp-nvim-lsp is a source plugin of nvim-cmp for integration with Neovim’s built-in LSP client. It can obtain the completion information provided by LSP, including functions, variables, types, etc., and provide related completion candidates.
-
cmp-nvim-lua:
- Plug-in function: cmp-nvim-lua is a source plug-in of nvim-cmp, which is used to provide the completion support of Lua language. It can identify information such as functions and variables in Lua code, and provide relevant completion options.
-
cmp-path:
- Plug-in function: cmp-path is a source plug-in of nvim-cmp, which is used to provide the completion function of file path. It can automatically complete the path of files and folders according to the current path, which is convenient for quick access to the content in the file system.
-
cmp_luasnip:
- Plug-in function: cmp_luasnip is a plug-in of nvim-cmp, which is used to integrate with luaSnip plug-in. It can take luaSnip’s code snippets as completion options, and provide completion functions together with other completion sources.
-
nvim-autopairs:
- Plug-in function: nvim-autopairs is a plug-in that automatically completes characters such as brackets and quotation marks. It can automatically insert and match these characters according to the cursor position, improving the efficiency of writing code. It works with nvim-cmp to automatically handle parenthesis closing during completion.
other plugins
- gitsigns.nvim:
- gitsigns.nvim is a Git status prompt plug-in, which is used to display the modified part of the Git repository in Neovim, and provide related operations and functions, such as jumping to the modified location, submitting code, etc.
- indent-blankline.nvim:
- indent-blankline.nvim is an indentation line plugin, which is used to display indentation visualization in Neovim, helping users to see the indentation level of the code more clearly.
- nvim-colorizer.lua:
- nvim-colorizer.lua is a color preview plug-in, which can display the color values in the code in real colors in Neovim, helping users understand and adjust colors more intuitively.
- nvim-lspconfig:
- nvim-lspconfig is a plugin for configuring Neovim’s built-in LSP client. It provides a set of predefined configuration options that allow users to easily configure and enable different language servers.
- ui:
- ui involves Neovim’s user interface beautification and customization. This may include plugins and configurations for color schemes, status bars, tab bars, etc. to improve the look and feel of the user interface.
- which-key.nvim:
- which-key.nvim is a key prompt and shortcut key help plug-in, which is used to display the operation prompt of the current key in Neovim to help users better understand and use shortcut keys.
- Comment.nvim:
- Comment.nvim is a comment plugin that provides quick comment and uncomment functions, simplifying the operation of commenting code.
- mason.nvim:
- mason.nvim is a quick insert plugin for HTML and CSS, which can help users insert commonly used HTML and CSS code snippets more quickly and conveniently.
- nvterm:
- nvterm is a Neovim terminal emulator, which embeds the terminal function into Neovim, so that users can directly execute commands and operate the terminal in Neovim.
what is lsp
plug-ins not in use
It may be used in the future, so put it here first.
Startup page: alpha-nvim .
Rename: renamer.nvim .
Terminal: toggleterm.nvim .
Provides formatting, diagnostics: null-ls.nvim .
Manage tabs and buffers: bufferline.nvim .
Error resolution
-
Encountered an error
Error executing vim.schedule lua callback: /root/.config/nvim/lua/core/utils.lua:80: attempt to index a nil value
discussed with gpt,
Changed line 80 of source code
vi .config/nvim/lua/core/utils.lu
and inserted this sentence:mappings [ section ] = mappings [ section ] or {}
It ends up as follows:
Enough.
Autocomplete
k
References
- How to install and use Neovim
- Finally made vim look like vscode
- nvim-basic-ide 1.6k stars
- VapourNvim 486 stars
- NvChad 17.5k stars
- Make your neovim as powerful as an IDE
- Introduction and practice of configuring neovim in iterm of Mac computer
- https://github.com/glepnir/nvim-lua-guide-zh
- Neovim experience
This article is transferred from: https://blog.kelu.org/tech/2023/06/06/vim-ide.html
This site is only for collection, and the copyright belongs to the original author.