Lua, Yes.

Neovim by lua

From init.vim to init.lua

Preface

The nvim supported lua script since Nvim 0.5. And lua is faster than vimscript. Even so, Neovim is not deprecating Vimscript.

Will Neovim deprecate Vimscript?

No. Lua is built-in, but Vimscript is supported with the most advanced Vimscript engine in the world (featuring an AST-producing parser)).

Why Lua?

Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

Get started with lua in 30 minutes

init.lua, Yes!

We need a lot of plugins when we use Neovim. So there is a plugin manager we need. Here I recommend ‘packer.nvim‘.

Installation

Unix, Linux Installation
1
2
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
Windows Powershell Installation
1
git clone https://github.com/wbthomason/packer.nvim "$env:LOCALAPPDATA\nvim-data\site\pack\packer\start\packer.nvim"

Configuration & Usage

This is directory tree of my configuration:

1
2
3
4
5
6
7
8
9
10
11
12
nvim
├── init.lua
├── lua
│   ├── conf
│   │   ├── plugin1_detaill-conf.lua
│   │   └── plugin2_detaill-conf.lua
│   ├── keymaps.lua
│   ├── localconf.lua
│   ├── lspconf.lua
│   └── plugins.lua
└── plugin
└── packer_compiled.lua

The entrance file changed from init.vim to init.lua.

Let’s look at the init.lua.

1
2
3
4
5
-- nvim/init.lua
require('plugins')
require('lspconf')
require('keymaps')
require('localconf')

The require function can invoke others .lua files.

Why require('lua/plugins') ?

Because the path ~/.config/nvim/lua is contained in the search path by Lua that Nvim built-in.

Let’s omit it.

The extremely important file is plugins.lua. Ok, actually you can use any name if you like. So, here we call it plugins.lua.

Take a look:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
-- nvim/lua/plugins.lua
vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- Lsp config
use {
'williamboman/nvim-lsp-installer',
config = function()
require('conf.nvim-lsp-installer-conf')
end
}
use 'neovim/nvim-lspconfig'
use 'hrsh7th/nvim-cmp'
use 'hrsh7th/cmp-nvim-lsp'
use 'saadparwaiz1/cmp_luasnip' -- Snippets source for nvim-cmp
use 'L3MON4D3/LuaSnip' -- Snippets plugin
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-nvim-lua'
-- Markdown Preview
use 'iamcco/markdown-preview.nvim'

-- lspsaga beautify the windows of lsp
use {
'tami5/lspsaga.nvim',
config = function()
-- require('conf.lspsaga-conf')
require('lspsaga').setup{}
end
}

-- Dashboard
use {
'goolord/alpha-nvim',
requires = { 'kyazdani42/nvim-web-devicons' },
config = function ()
require'alpha'.setup(require'alpha.themes.startify'.config)
end
}

-- Comment plugin
use {
'numToStr/Comment.nvim',
config = function()
require('Comment').setup{}
end
}

use 'xiyaowong/nvim-cursorword'

use({
"NTBBloodbath/galaxyline.nvim",
-- your statusline
config = function()
require("galaxyline.themes.eviline")
end,
-- some optional icons
requires = { "kyazdani42/nvim-web-devicons", opt = true }
})

use {'akinsho/bufferline.nvim',
tag = "v2.*",
requires = 'kyazdani42/nvim-web-devicons',
config = function()
require('bufferline').setup{}
end
}

-- Dirctory Tree
use {
'kyazdani42/nvim-tree.lua',
requires = {
'kyazdani42/nvim-web-devicons', -- optional, for file icon
},
tag = 'nightly', -- optional, updated every week. (see issue #1193)
config = function()
require('nvim-tree').setup{}
end
}

use({
'NTBBloodbath/doom-one.nvim',
config = function()
require('doom-one').setup({
cursor_coloring = false,
terminal_colors = false,
italic_comments = false,
enable_treesitter = true,
transparent_background = false,
pumblend = {
enable = true,
transparency_amount = 20,
},
plugins_integrations = {
neorg = true,
barbar = true,
bufferline = false,
gitgutter = false,
gitsigns = true,
telescope = false,
neogit = true,
nvim_tree = true,
dashboard = true,
startify = true,
whichkey = true,
indent_blankline = true,
vim_illuminate = true,
lspsaga = false,
},
})
end,
})

use {
'nvim-telescope/telescope.nvim',
requires = {
"nvim-lua/plenary.nvim", -- Lua development module
"BurntSushi/ripgrep", -- characters finding
"sharkdp/fd" -- file search
},
config = function()
require('telescope').setup{}
end
}
end)

Oh sh*t. It’s so loooooong. Let’s simplify it a bit and explian it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- nvim/lua/plugins.lua
vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- a plugin come from Github
use 'user/plugin1'
-- a plugin come from Github with some configuration
use {
'user/plugin2',
-- some dependences
requires = {...},
-- configuration by anonymous funciton
config = function()
-- --- code ----
...
end
}
end)

Now, you can download all plugins that you like. Awesome-Neovim has a lot of awesome plugins.

In the nvim/lua/localconf.lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-- nvim/lua/localconf.lua
vim.o.relativenumber = true
vim.o.number = true
vim.o.tabstop = 4
vim.o.shiftwidth = 4
vim.o.smartindent = true
vim.o.termguicolors = true
vim.o.cursorline = true
vim.o.mouse = 'a'
vim.o.scrolloff = 3
vim.o.expandtab = true
vim.o.wildmenu = true
vim.o.ignorecase = true
vim.o.swapfile = false

-- Markdown-Preview.nvim
vim.g.mkdp_filetypes = { 'markdown' }
vim.cmd('autocmd vimenter *.md exec ":MarkdownPreview"')

The global configuration of the editor has been changed in a new way.
If you have any unknown config items, you can use :help ... to query, such as :help vim.o.

Time to pause.


From init.vim to init.lua (1)
http://example.com/2022/06/25/lua.nvim/
Author
mistgc
Posted on
June 25, 2022
Licensed under