Lazyvim使用
Install Lazyvim
Lazyvim is a package manger for Neovim. The prerequisite of Lazyvim is installing Neovim. I suggest install neovim using homebrew, which can bring newer version than yum/apt.
First, install homebrew (the following command runs in all OSs):
1/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This command has a strange point: it checks the sudo permission for the current user, but also verify the current user is not root. So if you’re using a new user without a SUDO password, now you need to set one in advance:
1sudo passwd
Install neovim via homebrew:
1brew install neovim
Finally, install Lazyvim:
1git clone https://github.com/LazyVim/starter ~/.config/nvim
The next time you launch the neovim, it will install all default plugins and you will get a fancy IDE-like terminal, where you are even able to use mouse to select “windows”:
1nvim . # open current directory in neovim.
Recommended Keyboard Remapping
ECS is a very frequently used key in vim based editor, so remapping ecs to caps lock key is very useful.
- MacOS: remap the key using karabiner-elements. Install via homebrew
brew install --cask karabiner-elements
.
Lazyvim Language Support
Lazyvim provide plugin bundles to support coding in programing languages. To install language plugin bundles(called “language”), type :LazyExtras
to open extension management window. LazyExtras recommends extensions based on the current project opened, for example, if the current project contains .go file, it will recommend lang.go. The LazyExtras languages contain a set of plugin(LSP server plugin, formatter etc.). Move the cursor to certain language’s line and press x
to enable the plugin. After enabling, close and reload the neovim tmo install the plugins.
The core language features in LazyVim is powered by LSP. LSP(Language Server Portocol) is a portocol used between a tool(the client, usually a editor) and a language smartness provider(the server) to integrate features like auto complete, go to definition, find all references and alike into the tool. Lazyvim doesn’t directly install/manage the LSP plugin, but uses Mason to install them. So if some plugin audo installation fails, you can check the Mason logs to debug.
Useful Mason Command:
:MasonLog
check Mason’s log, to find the reason of installation failure etc.:MasonInstall pyright
use Mason to directly install some LSP plugin, like pyright here.:Mason
open Mason panel to view installed/all plugins and update plugins.
Useful Operations
Navigation, Buffers
The opened file tag is called buffer in Lazyvim. <leader>
is by default set to space key, when you press it, a little panel will appear in the right bottom cornor of the window, which prompt the next key to press and the action will be triggered.
Buffers:
<leader>bd
delete current buffer
Window Navigation:
ctrl
+ hjkl: change to focus among window areasshift
+ hjkl: change to focus among buffers<leader>|
split and show in right side window
File tree:
<leader>e
to open/close file tree panel- in the file tree, type
/
to filter the displayed files. use hjkl to navigate among directories and files. a
to create file/dir,d
to delete file,x
to cut,y
to copy,p
to paste.H
to show/hide hidden files.
Searching
<leader>/
search any text in all project files.<leader>space
search file name.
Language Related
<leader>gd
go to definition<leader>gI
go to implementations<leader>gr
go to references<leader>uf
toogle auto formatting on save<leader>cr
rename a symbol<leader>xq
show the quick fix action listjump back to last cursor position jump forward(opposite operation of jump back)
Terminal
<ctrl-/>
open/close terminal 1n<ctrl-/>
open/close terminal n- escape from terminal needs 2 press on ecs
Editor
<ctrl-s>
save file
Git
<leader>gb
git blame on current line