Baishun's Space

My Nvim Configuration - basic

By Baishun on May 14, 2024
nvim power

Summary

I used vscode to code before, but I found if there’s an update but you don’t want to do it, vscode will do wired things for you, like some functions not work properly, so I decide to change to vim, it’s not a decision by foot, some of my jobs is to configure some server environment, so I’m familiar with vim.

After some search, I found a youtube called typecraft, his video is pretty good for vim-beginners, so I learnt from him mostly of the configuration.

Basic

As mentioned above, I learnt from typecraft, he used neovim + lazyvim, so I also used these two. (believe me, I also tried other like vim + vim-plug, but I found lazyvim is real easy for laziers).

so, the first thing is to install neo vim, I use a mac, so I use brew to do this:

brew install neovim

then get the configuration from lazyvim github and clone into ~/.config/nvim:

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

rm -rf ~/.config/nvim/.git

if you open ~/.config/nvim, you will find it has a structure like this:

  • init.lua
  • lazyvim.json
  • lua
    • config
    • plugins

the init.lua is the index file of this configuration, neo vim will read this file to load it’s configs.

in config fold, there’re some default configurations from lazyvim.

mostly of our operations are in plugins fold.

Treesitter

Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited.

I use Nvim-treesitter to do this.

below is my configurations, the most important I think is auto_install = true, the file is also under plugins folder and called treesitter.lua.

return {
  "nvim-treesitter/nvim-treesitter",
  config = function()
    local treesitter_config = require("nvim-treesitter.configs")
    treesitter_config.setup({
      ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
      sync_install = false,
      auto_install = true,
      ignore_install = { "javascript" },

      highlight = {
        enable = true,

        disable = function(lang, buf)
          local max_filesize = 100 * 1024 -- 100 KB
          local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
          if ok and stats and stats.size > max_filesize then
            return true
          end
        end,

        additional_vim_regex_highlighting = false,
      },
    })
  end

}

I will continue in the next article

For business cooperation or you have any questions, please send email to : lecy.cc.app@gmail.com
© Copyright 2024 by Baishun Space. Built with ♥ by Lecy. Origin theme of this blog is from ixartz. Social Icons are copied from astro-social-share