Skip to content

Commit

Permalink
Merge pull request #1 from ntk148v/lazy.nvim
Browse files Browse the repository at this point in the history
Migrate to Lazy.nvim as plugin manager
  • Loading branch information
ntk148v authored Feb 22, 2023
2 parents 606032a + 6200609 commit 210c7c2
Show file tree
Hide file tree
Showing 31 changed files with 1,035 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

nvim/plugin/
lazy-lock.json
76 changes: 53 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ Table of contents

- [1. Introduction](#1-introduction)
- [2. Installation](#2-installation)
- [3. Plugins \& LSP](#3-plugins--lsp)
- [3.1. Plugins](#31-plugins)
- [3.2. LSP](#32-lsp)
- [4. Keymaps](#4-keymaps)
- [5. Screenshots](#5-screenshots)
- [6. Contribution](#6-contribution)
- [7. Guide and resources](#7-guide-and-resources)
- [3. File structure](#3-file-structure)
- [4. Plugins \& LSP](#4-plugins--lsp)
- [4.1. Plugins](#41-plugins)
- [4.2. LSP](#42-lsp)
- [5. Keymaps](#5-keymaps)
- [6. Screenshots](#6-screenshots)
- [7. Contribution](#7-contribution)
- [8. Guide and resources](#8-guide-and-resources)

## 1. Introduction

Expand All @@ -48,16 +49,18 @@ Therefore, I decided to create this repository. There are several versions:

- [v0.1.0](https://github.com/ntk148v/neovim-config/tree/v0.1.0): written in VimL, a single file only.
- [v0.1.1](https://github.com/ntk148v/neovim-config/tree/v0.1.1): written in VimL, consist of mutliple files.
- [v0.2.0](https://github.com/ntk148v/neovim-config/tree/v0.2.0): started this version, switch from VimL to Lua. For the reason, you may to check [neovim's official wiki](https://github.com/neovim/neovim/wiki/FAQ#why-embed-lua-instead-of-x). Follow [KISS principle](https://en.wikipedia.org/wiki/KISS_principle), this version uses the least plugins as possible. It's more like a skeleton, users can add more plugins and LSP.
- [v0.2.0](https://github.com/ntk148v/neovim-config/tree/v0.2.0): started from this version, switch from VimL to Lua. For the reason, you may to check [neovim's official wiki](https://github.com/neovim/neovim/wiki/FAQ#why-embed-lua-instead-of-x). Follow [KISS principle](https://en.wikipedia.org/wiki/KISS_principle), this version uses the least plugins as possible. It's more like a skeleton, users can add more plugins and LSP.
- [v0.2.1](https://github.com/ntk148v/neovim-config/tree/v0.2.1): this version contains some minor changes.
- [v0.3.0](https://github.com/ntk148v/neovim-config/tree/v0.3.0): I decide to switch to [lazy.nvim](https://github.com/folke/lazy.nvim) as my plugin manager, instead of [packer](https://github.com/wbthomason/packer.nvim). The main reason is [lazy.nvim's support for plugin structure](https://github.com/folke/lazy.nvim#-structuring-your-plugins).

As I mentioned, this config is meant as a starting point, it is not a complete Neovim/Vim config distribution, if you're looking for a one, check out [here](https://github.com/rockerBOO/awesome-neovim#preconfigured-configuration).

## 2. Installation

- Requirements:
- Install [neovim >= 0.8.0](https://github.com/neovim/neovim/wiki/Installing-Neovim#install-from-package), or you can [build it](https://github.com/neovim/neovim/wiki/Building-Neovim#) yourself.
- git
- I recommend using a [nerdfonts](https://www.nerdfonts.com/font-downloads)
- git >= 2.19.0 (for partial clones suppot)
- I recommend using a [nerdfonts](https://www.nerdfonts.com/font-downloads) (optional)
- Backup your current neovim config, if necessary:

```shell
Expand All @@ -72,19 +75,44 @@ cd neovim-config.git/
cp -Rv nvim ~/.config/
```

- Start Neovim, Packer should be installed automatically, then run the following command to install plugins:
- Start Neovim, Lazy should be installed automatically, then it will install plugins.

```vim
:PackerSync
## 3. File structure

The files under config will be automatically loaded at the appropriate time, so you don't need to require those files manually.

```shell
tree ~/.config/nvim
├── init.lua
├── lazy-lock.json
└── lua
├── config
│   ├── autocmds.lua
│   ├── init.lua
│   ├── keymaps.lua
│   └── options.lua
└── plugins
├── autopairs.lua
├── colorizer.lua
├── colorscheme.lua
├── comment.lua
├── gitsigns.lua
├── lsp.lua
├── lualine.lua
├── neoterm.lua
├── null-ls.lua
├── telescope.lua
├── tree.lua
└── treesitter.lua
```

## 3. Plugins & LSP
## 4. Plugins & LSP

### 3.1. Plugins
### 4.1. Plugins

| Plugin | Description |
| --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [packer.nvim](https://github.com/wbthomason/packer.nvim) | A use-package inspired plugin manager for Neovim |
| [lazy.nvim](https://github.com/folke/lazy.nvim) | A modern plugin manager for Neovim |
| [mason.nvim](https://github.com/williamboman/mason.nvim) | Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters. |
| [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) | A collection of common configurations for Neovim's built-in language server client |
| [gitsigns](https://github.com/lewis6991/gitsigns.nvim) | Super fast git decorations implemented purely in lua/teal |
Expand All @@ -102,9 +130,11 @@ cp -Rv nvim ~/.config/
| [rosé-pine](https://github.com/rose-pine/neovim) | Soho vibes for Neovim |
| [folke/tokyonight.nvim](https://github.com/folke/tokyonight.nvim) | A clean, dark Neovim theme written in Lua, with support for lsp, treesitter and lots of plugins. Includes additional themes for Kitty, Alacritty, iTerm and Fish. |
| [projekt0n/github-nvim-theme](https://github.com/projekt0n/github-nvim-theme) | Github's Neovim themes |
| [null-ls](https://github.com/jose-elias-alvarez/null-ls.nvim) | Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua. |
| [null-ls](https://github.com/jose-elias-alvarez/null-ls.nvim) | Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua. |

**You can add your custom plugin specs under `lua/plugins`. All files will be automatically loaded by `lazy.nvim`.**

### 3.2. LSP
### 4.2. LSP

This configuration provides Python and Golang dev environment. The programming language server is current supported:

Expand Down Expand Up @@ -133,7 +163,7 @@ If your language is not supported, please follow this:
:TSInstall `<language_to_install>`
```

## 4. Keymaps
## 5. Keymaps

These are the default keymaps, in the following shortcuts, the `<leader>` key is set up to `` (space) character, check: [keymaps.lua](./nvim/lua/core/keymaps.lua).

Expand Down Expand Up @@ -166,19 +196,19 @@ There are many default keymaps, you can check it using `:map` command. There are

The above list is not complete. Typing `:help map` in Vim will give you more info.

## 5. Screenshots
## 6. Screenshots

| | |
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| <img src="screenshots/nvim1.png" alt="dark" style="border-radius:1%"/> | <img src="screenshots/nvim2.png" alt="dark" style="border-radius:1%"/> |
| <img src="screenshots/nvim3.png" alt="dark" style="border-radius:1%"/> | <img src="screenshots/nvim4.png" alt="dark" style="border-radius:1%"/> |
| <img src="screenshots/nvim5.png" alt="dark" style="border-radius:1%"/> | |
| <img src="screenshots/nvim5.png" alt="dark" style="border-radius:1%"/> | <img src="screenshots/nvim6.png" alt="dark" style="border-radius:1%"/> |

## 6. Contribution
## 7. Contribution

Feel free to file an issue or open a pull request. You're welcome!

## 7. Guide and resources
## 8. Guide and resources

- [nanotee/nvim-lua-guide](https://github.com/nanotee/nvim-lua-guide)
- [brainfucksec/neovim-lua](https://github.com/brainfucksec/neovim-lua)
Expand Down
34 changes: 17 additions & 17 deletions nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
--
-- ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗
-- ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║
-- ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║
-- ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║
-- ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║
-- ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝
--
-- File: init.lua
-- Description: main configuration file
-- Author: Kien Nguyen-Tuan <[email protected]>
if vim.fn.has('nvim-0.8') == 0 then
error('Need Neovim 0.8+ in order to use this config')
end

-- Import Lua modules --
local modules = {'loader', 'plugins', 'core'}
for _, cmd in ipairs({"git", "rg", {"fd", "fdfind"}}) do
local name = type(cmd) == "string" and cmd or vim.inspect(cmd)
local commands = type(cmd) == "string" and {cmd} or cmd
---@cast commands string[]
local found = false

for _, mod in ipairs(modules) do
local ok, err = pcall(require, mod)
if not ok then
error(('Error loading %s...\n\n%s'):format(mod, err))
for _, c in ipairs(commands) do
if vim.fn.executable(c) == 1 then
name = c
found = true
end
end

if not found then
error(("`%s` is not installed"):format(name))
end
end

-- Load main config
require("config")
40 changes: 20 additions & 20 deletions nvim/lua/core/autocmd.lua → nvim/lua/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║
-- ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝
--
-- File: core/autocmds.lua
-- File: config/autocmds.lua
-- Description: Autocommand functions
-- Author: Kien Nguyen-Tuan <[email protected]>
-- Define autocommands with Lua APIs
Expand All @@ -17,46 +17,46 @@ local autocmd = vim.api.nvim_create_autocmd -- Create autocommand
-- General settings

-- Highlight on yank
autocmd('TextYankPost', {
autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank({
higroup = 'IncSearch',
timeout = '1000'
higroup = "IncSearch",
timeout = "1000"
})
end
})

-- Remove whitespace on save
autocmd('BufWritePre', {
pattern = '',
autocmd("BufWritePre", {
pattern = "",
command = ":%s/\\s\\+$//e"
})

-- Auto format on save using the attached (optionally filtered) language servere clients
-- https://neovim.io/doc/user/lsp.html#vim.lsp.buf.format()
autocmd('BufWritePre', {
pattern = '',
command = ':silent lua vim.lsp.buf.format()'
autocmd("BufWritePre", {
pattern = "",
command = ":silent lua vim.lsp.buf.format()"
})

-- Don't auto commenting new lines
autocmd('BufEnter', {
pattern = '',
command = 'set fo-=c fo-=r fo-=o'
-- Don"t auto commenting new lines
autocmd("BufEnter", {
pattern = "",
command = "set fo-=c fo-=r fo-=o"
})

autocmd('Filetype', {
pattern = {'xml', 'html', 'xhtml', 'css', 'scss', 'javascript', 'typescript', 'yaml', 'lua'},
command = 'setlocal shiftwidth=2 tabstop=2'
autocmd("Filetype", {
pattern = {"xml", "html", "xhtml", "css", "scss", "javascript", "typescript", "yaml", "lua"},
command = "setlocal shiftwidth=2 tabstop=2"
})

-- Set colorcolumn
autocmd('Filetype', {
pattern = {'python', 'rst', 'c', 'cpp'},
command = 'set colorcolumn=80'
autocmd("Filetype", {
pattern = {"python", "rst", "c", "cpp"},
command = "set colorcolumn=80"
})

autocmd('Filetype', {
autocmd("Filetype", {
pattern = {"gitcommit", "markdown", "text"},
callback = function()
vim.opt_local.wrap = true
Expand Down
51 changes: 51 additions & 0 deletions nvim/lua/config/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--
-- ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗
-- ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║
-- ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║
-- ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║
-- ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║
-- ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝
--
-- File: config/init.lua
-- Description: Main configurations
-- Author: Kien Nguyen-Tuan <[email protected]>
-- Lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system(
{"git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", -- latest stable release
lazypath})
end
vim.opt.rtp:prepend(lazypath)

local modules = {"config.autocmds", "config.options", "config.keymaps"}

for _, mod in ipairs(modules) do
local ok, err = pcall(require, mod)
if not ok then
error(("Error loading %s...\n\n%s"):format(mod, err))
end
end

require("lazy").setup({
root = vim.fn.stdpath("data") .. "/lazy", -- directory where plugins will be installed
spec = {{
import = "plugins"
}},
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
defaults = {
lazy = false, -- should plugins be lazy-loaded?
version = nil
-- version = "*", -- enable this to try installing the latest stable versions of plugins
},
install = {
-- install missing plugins on startup
missing = true,
-- try to load one of these colorschemes when starting an installation during startup
colorscheme = {"rose-pine", "blue"}
},
checker = {
-- automatically check for plugin updates
enabled = true
}
})
38 changes: 19 additions & 19 deletions nvim/lua/core/keymaps.lua → nvim/lua/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@
-- ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║
-- ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝
--
-- File: core/keymaps.lua
-- File: config/keymaps.lua
-- Description: Key mapping configs
-- Author: Kien Nguyen-Tuan <[email protected]>
vim.g.mapleader = ' '
vim.g.mapleader = " "
-- Close all windows and exit from Neovim with <leader> and q
vim.keymap.set('n', '<leader>q', ':qa!<CR>', {})
vim.keymap.set("n", "<leader>q", ":qa!<CR>", {})
-- Fast saving with <leader> and s
vim.keymap.set('n', '<leader>s', ':w<CR>', {})
vim.keymap.set("n", "<leader>s", ":w<CR>", {})
-- Move around splits
vim.keymap.set('n', '<leader>wh', '<C-w>h', {})
vim.keymap.set('n', '<leader>wj', '<C-w>j', {})
vim.keymap.set('n', '<leader>wk', '<C-w>k', {})
vim.keymap.set('n', '<leader>wl', '<C-w>l', {})
vim.keymap.set("n", "<leader>wh", "<C-w>h", {})
vim.keymap.set("n", "<leader>wj", "<C-w>j", {})
vim.keymap.set("n", "<leader>wk", "<C-w>k", {})
vim.keymap.set("n", "<leader>wl", "<C-w>l", {})

-- Reload configuration without restart nvim
vim.keymap.set('n', '<leader>r', ':so %<CR>', {})
vim.keymap.set("n", "<leader>r", ":so %<CR>", {})

-- Telescope
-- <leader> is a space now
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set("n", "<leader>fh", builtin.help_tags, {})

-- NvimTree
vim.keymap.set('n', '<leader>n', ':NvimTreeToggle<CR>', {}) -- open/close
vim.keymap.set('n', '<leader>nr', ':NvimTreeRefresh<CR>', {}) -- refresh
vim.keymap.set('n', '<leader>nf', ':NvimTreeFindFile<CR>', {}) -- search file
vim.keymap.set("n", "<leader>n", ":NvimTreeToggle<CR>", {}) -- open/close
vim.keymap.set("n", "<leader>nr", ":NvimTreeRefresh<CR>", {}) -- refresh
vim.keymap.set("n", "<leader>nf", ":NvimTreeFindFile<CR>", {}) -- search file

-- Terminal
vim.keymap.set('n', '<leader>tt', ':NeotermToggle<CR>', {})
-- vim.keymap.set('n', '<leader>tx', ':NeotermExit<CR>', {})
vim.keymap.set("n", "<leader>tt", ":NeotermToggle<CR>", {})
-- vim.keymap.set("n", "<leader>tx", ":NeotermExit<CR>", {})
Loading

0 comments on commit 210c7c2

Please sign in to comment.