Introduction#
GitHub this note shows basic setting for nvim and lua
- project structure
- basic lau to configure nvim
- how to install plugins with packer and configure in after
- telescope and telescope filer browser
- nerd-font
- lsp and langugae server
- tmux to fix the true color issue
- fish shell and configuration
Prerequisite#
- Install Node
- Install nvim at least 0.9.0
- Install Packer package management
First, let download Node from offical site
wget https://nodejs.org/dist/v18.16.1/node-v18.16.1-linux-x64.tar.xz
Then extract and update the PATH
tar -xvzf node-v18.16.1-linux-x64.tar.xz
Update the PATH
echo 'PATH=/home/ec2-user/node-v18.16.1-linux-x64/bin:$PATH' >> ~/.bashrc
Second, let download nvim at least 0.9.0 from official site
wget https://github.com/neovim/neovim/releases/download/v0.9.0/nvim-linux64.tar.gz
Extract and upload the PATH
tar -xvzf nvim-linux64.tar.gz
Upload the PATH
echo 'PATH=/home/ec2-user/nvim/nvim-linux64/bin:$PATH' >> ~/.bashrc
Third, install the Packer package manager for nvim by following offical docs
git clone --depth 1 https://github.com/wbthomason/packer.nvim\~/.local/share/nvim/site/pack/packer/start/packer.nvim
Project Structure#
Let create a config director for nvim in ~/.config as
mdkir ~/.config/nvim
Then setup the project structure as below
- init.lua- after/plugin|--prettier.rc.lua|--telescope.rc.lua|--web-devicons.rc.lua- plugin|--packer-compiled.lua|--null-ls.rc.lua|--lspconfig.lua|--lspsaga.lua- lua|--entest|--base.lua|--maps.lua|--highlight.lua|--macos.lua|--plugins.lua
according to the nvim documentation, all dirs in the runtimepath will be searcherd for for the plugin here.
Lua Configuration#
vim.cmd("autocmd!")vim.scriptencoding = 'utf-8'vim.opt.encoding = 'utf-8'vim.opt.fileencoding = 'utf-8'-- Leader keyvim.g.mapleader = ','vim.wo.number = truevim.opt.title = truevim.opt.autoindent = truevim.opt.smartindent = truevim.opt.hlsearch = truevim.opt.backup = falsevim.opt.showcmd = truevim.opt.cmdheight = 1vim.opt.laststatus = 2vim.opt.expandtab = truevim.opt.scrolloff = 10vim.opt.shell = 'fish'vim.opt.backupskip = { '/tmp/*', '/private/tmp/*' }vim.opt.inccommand = 'split'vim.opt.ignorecase = true -- Case insensitive searching UNLESS /C or capital in searchvim.opt.smarttab = truevim.opt.breakindent = truevim.opt.shiftwidth = 2vim.opt.tabstop = 2vim.opt.wrap = false -- No Wrap linesvim.opt.backspace = { 'start', 'eol', 'indent' }vim.opt.path:append { '**' } -- Finding files - Search down into subfoldersvim.opt.wildignore:append { '*/node_modules/*' }
Package Managment#
install packer for Lunix here
git clone --depth 1 https://github.com/wbthomason/packer.nvim\~/.local/share/nvim/site/pack/packer/start/packer.nvim
basic example, install prettier plugin, require in the below file
lua/entest/plugins.lau
with content so packer will install prettier
local status, packer = pcall(require, "packer")if (not status) thenprint("Packer is not installed")returnendvim.cmd [[packadd packer.nvim]]packer.startup(function(use)use 'wbthomason/packer.nvim'use { "MunifTanjim/prettier.nvim" }end)
basic commands
:PackerSync - pay attention before removing things:PackerComplie:PackerClean:PackerUpdate
configure prettier after loaded the package
after/plugin/prettier.rc.lua
with content
local status, prettier = pcall(require, "prettier")if (not status) then return endprettier.setup {print_width = 80,bin = 'prettier',filetypes = {"python","css","javascript","javascriptreact","typescript","typescriptreact","json","scss","less"}}
Language Server Protocol#
install lsp client
use 'neovim/nvim-lspconfig' -- LSP
then need to install cmp (auto completion), syntax highlight, auto tag, etc. Put below in the file
lua/entest/plugins.lua
content
use 'hrsh7th/cmp-buffer' -- nvim-cmp source for buffer wordsuse 'hrsh7th/cmp-nvim-lsp' -- nvim-cmp source for neovim's built-in LSPuse 'hrsh7th/nvim-cmp' -- Completionuse 'neovim/nvim-lspconfig' -- LSPuse 'williamboman/mason.nvim'use 'williamboman/mason-lspconfig.nvim'
also update after/plugin/
plugin/lspconfig.luaafter/plugin/cmp.rc.luaafter/plugin/autopairs.rc.lua
install lsp server for python
npm i -g pyright
install lsp server for typescript
npm i typescript-language-server
Telescope File Browser#
install telescope in lua/entest/plugins.lua
use 'nvim-telescope/telescope.nvim'use 'nvim-telescope/telescope-file-browser.nvim'
configure telescope in after/plugins/telescope.rc.lua
local status, telescope = pcall(require, "telescope")if (not status) then return endlocal actions = require('telescope.actions')local builtin = require("telescope.builtin")local function telescope_buffer_dir()return vim.fn.expand('%:p:h')endlocal fb_actions = require "telescope".extensions.file_browser.actionstelescope.setup {defaults = {mappings = {n = {["q"] = actions.close},},},extensions = {file_browser = {theme = "dropdown",-- disables netrwhijack_netrw = true,mappings = {-- your custom insert mode mappings["i"] = {["<C-w>"] = function() vim.cmd('normal vbd') end,},["n"] = {-- your custom normal mode mappings["N"] = fb_actions.create,["h"] = fb_actions.goto_parent_dir,["/"] = function()vim.cmd('startinsert')end},},},},}telescope.load_extension("file_browser")-- find filesvim.keymap.set('n', ';f', function()builtin.find_files({no_ignore = false,hidden = true})end)-- file explorevim.keymap.set("n", "sf", function()telescope.extensions.file_browser.file_browser({path = "%:p:h",cwd = telescope_buffer_dir(),respect_gitignore = false,hidden = true,grouped = true,previewer = false,initial_mode = "normal",layout_config = { height = 40 }})end)
dependencies, might need to brew install for macos
- sharkd/fd for greph filder
- nvim-treesister
basic setup and mappings here
telescope file browser
- seletection by tab
- rename, move, copy here
- need to disable loading netrw by default
Nerd Font#
- for macos brew install or manually install and then terminal (Iterm) setting to select hack nerd font. the font help display icons such as git
- for linux -- download nerdfont for Linux here -- install nerdfont for Linux here
download the nerdfontunzip to ~/.local/share/fonts/sudo fc-cache -fv
Tmux#
tmux can be used to fix the non-true-color terminal issue
Fish Shell#
- run fish_config to select a font
- the fish backgroud color does not work
- customize fish_variables and fish_prompt.fish function
# VERSION: 3.0SETUVAR __fish_initialized:3400SETUVAR fish_color_autosuggestion:666SETUVAR fish_color_cancel:\x2d\x2dreverseSETUVAR fish_color_command:normalSETUVAR fish_color_comment:888\x1e\x2d\x2ditalicsSETUVAR fish_color_cwd:whiteSETUVAR fish_color_cwd_root:A00SETUVAR fish_color_end:009900SETUVAR fish_color_error:F22SETUVAR fish_color_escape:0AASETUVAR fish_color_history_current:0AASETUVAR fish_color_host:normalSETUVAR fish_color_host_remote:\x1dSETUVAR fish_color_keyword:\x1dSETUVAR fish_color_match:0AASETUVAR fish_color_normal:B2B2B2SETUVAR fish_color_operator:0AASETUVAR fish_color_option:\x1dSETUVAR fish_color_param:ccccffSETUVAR fish_color_quote:9ce781SETUVAR fish_color_redirection:FFFSETUVAR fish_color_search_match:\x2d\x2dbackground\x3d533SETUVAR fish_color_selection:\x2d\x2dbackground\x3dB218B2SETUVAR fish_color_status:redSETUVAR fish_color_user:brgreenSETUVAR fish_color_valid_path:\x2d\x2dSETUVAR fish_key_bindings:fish_default_key_bindingsSETUVAR fish_pager_color_background:\x1dSETUVAR fish_pager_color_completion:BBBSETUVAR fish_pager_color_description:666SETUVAR fish_pager_color_prefix:0AA\x1e\x2d\x2dSETUVAR fish_pager_color_progress:0AASETUVAR fish_pager_color_secondary_background:\x1dSETUVAR fish_pager_color_secondary_completion:\x1dSETUVAR fish_pager_color_secondary_description:\x1dSETUVAR fish_pager_color_secondary_prefix:\x1dSETUVAR fish_pager_color_selected_background:\x2d\x2dbackground\x3d333SETUVAR fish_pager_color_selected_completion:\x1dSETUVAR fish_pager_color_selected_description:\x1dSETUVAR fish_pager_color_selected_prefix:\x1d
Vscode Setting#
show function documentation or show hover
Cmd K Cmd I
Troubleshooting#
- clipboard
- if live_grep does not work, please install ripgrep for Linux
- nvim docs here
- lua docs here
- remove treesister and nvim-tree with neovim 8.0
- replace sumneko_lua by lua_ls with neovim 8.0
- LspInstall tailwinss or other langugae servers or npm install
- checkheath to see which install has error
- PackerStatus to see status of plugins
- LSPInfor error edit ~/.local/share/.../packer/.../lspinfo.lua
- comment nvim_set_option_value to fix LSPInfor error
- disable icons in telescope and vim.opt.laststatus = 0