initial commit

This commit is contained in:
Guanran Wang 2023-12-12 20:16:58 +08:00
commit 655e863d25
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8
10 changed files with 318 additions and 0 deletions

2
.stylua.toml Normal file
View file

@ -0,0 +1,2 @@
indent_type = "Spaces"
indent_width = 2

2
init.lua Executable file
View file

@ -0,0 +1,2 @@
require("options")
require("plugins")

26
lazy-lock.json Executable file
View file

@ -0,0 +1,26 @@
{
"LuaSnip": { "branch": "master", "commit": "954c81b53989097faaff0fabc11c29575288c3e1" },
"barbar.nvim": { "branch": "master", "commit": "dd852401ee902745b67fc09a83d113b3fe82a96f" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" },
"gitsigns.nvim": { "branch": "main", "commit": "6e05045fb1a4845fe44f5c54aafe024444c422ba" },
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
"lspsaga.nvim": { "branch": "main", "commit": "335805d4f591f5bb71cabb6aa4dc58ccef8e8617" },
"lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "9453e3d6cd2ca45d96e20f343e8f1b927364b630" },
"mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" },
"nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" },
"nvim-cmp": { "branch": "main", "commit": "41d7633e4146dce1072de32cea31ee31b056a131" },
"nvim-lspconfig": { "branch": "master", "commit": "bd405e45c5fb122c16af8f87fa2dd7ab1981b243" },
"nvim-tree.lua": { "branch": "master", "commit": "141c0f97c35f274031294267808ada59bb5fb08e" },
"nvim-treesitter": { "branch": "master", "commit": "a6c655629cad421e432aa84af32cbfe35375113a" },
"nvim-web-devicons": { "branch": "master", "commit": "8b2e5ef9eb8a717221bd96cb8422686d65a09ed5" },
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
"telescope.nvim": { "branch": "master", "commit": "6213322ab56eb27356fdc09a5078e41e3ea7f3bc" },
"tokyonight.nvim": { "branch": "main", "commit": "f247ee700b569ed43f39320413a13ba9b0aef0db" },
"which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }
}

31
lua/options.lua Executable file
View file

@ -0,0 +1,31 @@
vim.opt.autowrite = true
vim.opt.cursorline = true
vim.opt.autoread = true
vim.opt.tabstop = 2
vim.opt.shiftround = true
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.wo.number = true
vim.wo.signcolumn = "yes"
vim.o.undofile = true
vim.o.clipboard = "unnamedplus"
vim.cmd([[ set noswapfile ]])
-- Neovide
-- Put anything you want to happen only in Neovide here
if vim.g.neovide then
vim.o.guifont = "monospace:h12"
vim.g.neovide_padding_top = 12
vim.g.neovide_padding_bottom = 12
vim.g.neovide_padding_right = 12
vim.g.neovide_padding_left = 12
-- Terminal-emulator-like copy/pasting
local opts = { noremap = true, silent = true }
local keymap = vim.api.nvim_set_keymap
keymap("n", "<C-C>", '"*y :let @+=@*<CR>', opts)
keymap("n", "<C-V>", '"+p', opts)
end

63
lua/plugins/completions.lua Executable file
View file

@ -0,0 +1,63 @@
local cmp = require("cmp")
local luasnip = require("luasnip")
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
require("mason").setup()
require("luasnip.loaders.from_vscode").lazy_load()
require("cmp").setup({
-- keybinds
mapping = cmp.mapping.preset.insert({
-- unsure
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-o>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
-- return to confirm
["<CR>"] = cmp.mapping.confirm({ select = false }),
-- tab to select prev/next option
-- see: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- that way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
-- snippet engine
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
-- snippet source
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "buffer" },
}),
})

136
lua/plugins/init.lua Executable file
View file

@ -0,0 +1,136 @@
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)
require("lazy").setup({
-- completions.lua
{
"hrsh7th/nvim-cmp", -- Auto completion
dependencies = {
"neovim/nvim-lspconfig",
-- Snippet Engine & its associated nvim-cmp source
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
-- Adds LSP completion capabilities
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
-- Adds a number of user-friendly snippets
"rafamadriz/friendly-snippets",
},
},
-- lspconfig.lua
{
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
},
},
-- nvim-tree.lua
"nvim-tree/nvim-tree.lua",
-- telescope.lua
{ "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
-- treesitter.lua
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
},
-- misc
{
"folke/tokyonight.nvim", -- theme
lazy = false,
priority = 1000,
opts = {},
init = function()
vim.cmd([[ colorscheme tokyonight-night ]])
end,
},
{
"nvim-lualine/lualine.nvim", -- status line
dependencies = {
"kyazdani42/nvim-web-devicons", -- for filetype icons
},
opts = {
options = {
-- disable separators
section_separators = "",
component_separators = "",
-- color scheme
theme = "tokyonight",
},
},
},
{
"windwp/nvim-autopairs",
event = "InsertEnter",
opts = {}, -- this is equalent to setup({}) function
},
{
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeoutlen = 300
end,
opts = {},
},
{
"glepnir/lspsaga.nvim",
dependencies = {
"nvim-treesitter/nvim-treesitter", -- optional
"nvim-tree/nvim-web-devicons", -- optional
},
opts = {
lightbulb = {
-- enable = false,
},
},
},
{
"romgrk/barbar.nvim",
dependencies = {
"lewis6991/gitsigns.nvim", -- OPTIONAL: for git status
"nvim-tree/nvim-web-devicons", -- OPTIONAL: for file icons
},
init = function()
vim.g.barbar_auto_setup = false
end,
opts = {},
},
{ "lewis6991/gitsigns.nvim", opts = {} },
})
-- LSP related
require("plugins.lspconfig") -- utilizes lsp
require("plugins.completions") -- adds completions
require("plugins.treesitter") -- better highlights
-- QoL
require("plugins.nvim-tree") -- file explorer
require("plugins.telescope") -- file search

24
lua/plugins/lspconfig.lua Executable file
View file

@ -0,0 +1,24 @@
local capabilities = require("cmp_nvim_lsp").default_capabilities() -- needed for nvim-cmp
require("mason").setup()
require("mason-lspconfig").setup()
-- lspconfig
require("lspconfig").lua_ls.setup({
capabilities = capabilities,
})
require("lspconfig").nil_ls.setup({
capabilities = capabilities,
settings = {
["nil"] = {
formatting = {
command = { "alejandra" },
},
nix = {
flake = {
autoArchive = true,
},
},
},
},
})

9
lua/plugins/nvim-tree.lua Executable file
View file

@ -0,0 +1,9 @@
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.keymap.set("n", "<c-n>", ":NvimTreeFindFileToggle<CR>")
require("nvim-tree").setup({
view = {
adaptive_size = true,
},
})

7
lua/plugins/telescope.lua Executable file
View file

@ -0,0 +1,7 @@
require("telescope").setup()
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<c-p>", builtin.find_files, {})
vim.keymap.set("n", "<Space><Space>", builtin.oldfiles, {})
vim.keymap.set("n", "<Space>fg", builtin.live_grep, {})
vim.keymap.set("n", "<Space>fh", builtin.help_tags, {})

18
lua/plugins/treesitter.lua Executable file
View file

@ -0,0 +1,18 @@
require("nvim-treesitter.configs").setup({
-- A list of parser names, or "all"
ensure_installed = {
"nix",
"lua",
"vim",
},
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
auto_install = true,
highlight = {
enable = true,
},
indent = {
enable = true,
},
})