switch to lazy.nvim, refactor plugins, to pure lua

This commit is contained in:
leafee98 2023-05-21 22:02:07 +08:00
parent b12c7ea937
commit 3516e2ed0e
14 changed files with 270 additions and 256 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/lazy-lock.json

40
init.lua Normal file
View file

@ -0,0 +1,40 @@
vim.o.tabstop = 4
vim.o.shiftwidth = 0
vim.o.softtabstop = -1
vim.o.shiftround = true
vim.o.list = true
vim.o.relativenumber = true
vim.o.number = true
vim.o.expandtab = true
vim.o.autoindent = true
vim.o.smartindent = true
vim.keymap.set("n", "<C-q>", "<cmd>wincmd q<CR>", { silent = true })
vim.keymap.set("n", "<C-h>", "<cmd>wincmd h<CR>", { silent = true })
vim.keymap.set("n", "<C-j>", "<cmd>wincmd j<CR>", { silent = true })
vim.keymap.set("n", "<C-k>", "<cmd>wincmd k<CR>", { silent = true })
vim.keymap.set("n", "<C-l>", "<cmd>wincmd l<CR>", { silent = true })
vim.keymap.set("n", "<F1>", "<cmd>bprevious<CR>", { silent = true })
vim.keymap.set("n", "<F2>", "<cmd>bnext<CR>", { silent = true })
vim.keymap.set("n", "<F3>", "<cmd>bdelete<CR>", { silent = true })
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Use lazy.nvim as plugin manager, and load plugin's config
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("plugins")

102
init.vim
View file

@ -1,102 +0,0 @@
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" my custom settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" tabstop: length of an actual \t character:
" shiftwidth: length to use when shifting text (eg. <<, >> and == commands), (0 for tabstop):
" softtabstop: length to use when editing text (eg. TAB and BS keys), (0 for tabstop, -1 for shiftwidth):
" shiftround: round indentation to multiples of 'shiftwidth' when shifting text (so that it behaves like Ctrl-D / Ctrl-T):
set tabstop=4
set shiftwidth=0
set softtabstop=-1
set shiftround
set list
set relativenumber
set number
set expandtab
set autoindent
set smartindent
let mapleader="\<Space>"
let maplocalleader="\<Space>"
" plugin 'toogleterm' need this or it will initialze a new terminal each time foucus on terminal
set hidden
nmap <C-q> <C-w>q
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
lua << EOF
vim.g.markdown_fenced_languages = {
"ts=typescript"
}
EOF
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" config of vim-plug
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let s:plugs = []
function! s:add_plug(name, setup = v:true)
call add(s:plugs, { 'setup': a:setup, 'name': a:name })
endfunction
function! s:plug_name(dict)
return get(a:dict, 'name')
endfunction
function! s:plug_setup(dict)
return get(a:dict, 'setup')
endfunction
" call add_plug('bling/vim-bufferline', v:false)
call s:add_plug('neovim/nvim-lspconfig')
call s:add_plug('kyazdani42/nvim-tree.lua')
call s:add_plug('kyazdani42/nvim-web-devicons', v:false)
call s:add_plug('akinsho/toggleterm.nvim')
call s:add_plug('lukas-reineke/indent-blankline.nvim')
call s:add_plug('jupyter-vim/jupyter-vim')
"call s:add_plug('nvim-lualine/lualine.nvim')
"call s:add_plug('ap/vim-buftabline')
"call s:add_plug('projekt0n/github-nvim-theme')
call s:add_plug('morhetz/gruvbox', v:false)
call s:add_plug('vim-airline/vim-airline', v:false)
call s:add_plug('vim-airline/vim-airline-themes', v:false)
call s:add_plug('bling/vim-bufferline', v:false)
let g:airline_theme='violet'
set background=dark
function! s:setup_file(plug_name)
let l:pos_dot = strridx(a:plug_name, '.')
let l:pos_slash = strridx(a:plug_name, '/')
let l:pos_dot = l:pos_dot > 0 ? l:pos_dot - 1 : -1
let l:pos_slash = l:pos_slash > 0 ? l:pos_slash + 1 : 0
return a:plug_name[l:pos_slash : l:pos_dot] .. '.vim'
endfunction
call plug#begin(has('nvim') ? stdpath('data') .. '/plugged' : '~/.vim/plugged')
for p in s:plugs
Plug get(p, 'name')
endfor
call plug#end()
for p in s:plugs
if s:plug_setup(p)
execute 'source' stdpath('config') .. '/plugins.d/' .. s:setup_file(s:plug_name(p))
endif
endfor

80
lua/plugins/10-editor.lua Normal file
View file

@ -0,0 +1,80 @@
return {
{
"sainnhe/gruvbox-material",
config = function(_, _)
vim.o.termguicolors = true
vim.g.background = "dark"
vim.cmd("colorscheme gruvbox-material")
end
},
{
"karb94/neoscroll.nvim",
main = "neoscroll",
config = true,
opts = { },
},
{
"lukas-reineke/indent-blankline.nvim",
main = "indent_blankline",
config = true,
opts = {
show_current_context = true,
show_current_context_start = true,
},
},
{
"lewis6991/gitsigns.nvim",
main = "gitsigns",
opts = { },
},
{
"akinsho/bufferline.nvim",
main = "bufferline",
opts = {
options = {
numbers = "both",
diagnostics = "nvim_lsp",
separator_style = "slant",
offsets = {
{
filetype = "NvimTree",
text = "File Explorer",
text_align = "center",
separator = true,
},
},
hover = {
delay = 200,
reveal = { "close" },
},
}
},
},
{
"nvim-lualine/lualine.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons"
},
main = "lualine",
opts = { },
init = function(_)
vim.o.mousemoveevent = true
end,
},
{
"nvim-tree/nvim-tree.lua",
dependencies = {
"nvim-tree/nvim-web-devicons"
},
main = "nvim-tree",
opts = { },
lazy = false,
keys = {
{ "<leader>t", "<cmd>NvimTreeFocus<CR>", mode = "n" },
},
init = function(_)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
end,
}
}

100
lua/plugins/50-lsp.lua Normal file
View file

@ -0,0 +1,100 @@
function setup_keymap_lsp()
-- -- Global mappings.
-- -- See `:help vim.diagnostic.*` for documentation on any of the below functions
-- vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float)
-- vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
-- vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
-- vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist)
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<leader>f", function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
end
return {
{
"neovim/nvim-lspconfig",
dependencies = {
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"L3MON4D3/LuaSnip",
},
lazy = false,
config = function (_, opts)
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local servers = { "clangd", "rust_analyzer", "pyright", "gopls", "denols" }
for _, lsp in ipairs(servers) do
require("lspconfig")[lsp].setup{
capabilities = capabilities,
}
end
local luasnip = require("luasnip")
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<tab>"] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "luasnip" },
}),
})
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" }
}, {
{ name = "cmdline" }
})
})
setup_keymap_lsp()
end,
keys = {
{ "<leader>e", vim.diagnostic.open_float, mode = "n" },
{ "[d", vim.diagnostic.goto_prev, mode = "n" },
{ "]d", vim.diagnostic.goto_next, mode = "n" },
{ "<leader>q", vim.diagnostic.setloclist, mode = "n" }
},
},
}

View file

@ -0,0 +1,49 @@
return {
"nvim-treesitter/nvim-treesitter",
main = "nvim-treesitter.configs",
config = true,
build = ":TSUpdate",
opts = {
indent = { enable = true },
highlight = { enable = true },
ensure_installed = {
"bash",
"c",
"cmake",
"cpp",
"css",
"diff",
"dockerfile",
"git_config",
"git_rebase",
"gitattributes",
"gitcommit",
"gitignore",
"go",
"gomod",
"gosum",
"html",
"java",
"javascript",
"json",
"json5",
"jsonc",
"lua",
"luadoc",
"luau",
"make",
"markdown",
"markdown_inline",
"python",
"rust",
"scss",
"sql",
"toml",
"vim",
"vimdoc",
"yaml"
},
auto_install = true,
sync_install = false,
},
}

View file

@ -1,3 +0,0 @@
lua << EOF
require('github-theme').setup()
EOF

View file

@ -1,9 +0,0 @@
lua << EOF
require("indent_blankline").setup {
-- for example, context is off by default, use this to turn it on
-- show_current_context = true,
-- show_current_context_start = true,
filetype = {}
}
EOF

View file

@ -1,37 +0,0 @@
if has('nvim')
"let g:python3_host_prog = '~/miniconda3/envs/torch/bin/python3'
let g:python3_host_prog = '/usr/bin/python3'
else
set pyxversion=3
endif
" Always use the same virtualenv for vim, regardless of what Python
" environment is loaded in the shell from which vim is launched
"
" let g:vim_virtualenv_path = '~/miniconda3/envs/torch'
" if exists('g:vim_virtualenv_path')
" pythonx import os; import vim
" pythonx activate_this = os.path.join(vim.eval('g:vim_virtualenv_path'), 'bin/activate_this.py')
" pythonx with open(activate_this) as f: exec(f.read(), {'__file__': activate_this})
" endif
"""""""""""""""""""""""""
" Key mapping
"""""""""""""""""""""""""
" Run current file
nnoremap <buffer> <silent> <localleader>R :JupyterRunFile<CR>
nnoremap <buffer> <silent> <localleader>I :PythonImportThisFile<CR>
" Change to directory of current file
nnoremap <buffer> <silent> <localleader>d :JupyterCd %:p:h<CR>
" Send a selection of lines
nnoremap <buffer> <silent> <localleader>X :JupyterSendCell<CR>
nnoremap <buffer> <silent> <localleader>E :JupyterSendRange<CR>
nmap <buffer> <silent> <localleader>e <Plug>JupyterRunTextObj
vmap <buffer> <silent> <localleader>e <Plug>JupyterRunVisual
" Debugging maps
nnoremap <buffer> <silent> <localleader>b :PythonSetBreak<CR>

View file

@ -1,3 +0,0 @@
lua << END
require('lualine').setup()
END

View file

@ -1,59 +0,0 @@
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" config of LSP
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
lua << EOF
local nvim_lsp = require('lspconfig')
-- local util = require('lsputil')
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright', 'html', 'gopls' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
},
root_dir = nvim_lsp.util.find_git_ancestor
}
end
require'lspconfig'.quick_lint_js.setup{}
require'lspconfig'.denols.setup{}
EOF

View file

@ -1,27 +0,0 @@
lua << EOF
-- following options are the default
-- each of these are documented in `:help nvim-tree.OPTION_NAME`
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
adaptive_size = true,
mappings = {
list = {
{ key = "u", action = "dir_up" },
},
},
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
})
EOF
nnoremap <localleader>t :NvimTreeFocus<CR>

View file

@ -1,13 +0,0 @@
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" config of toggleterm
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
lua << EOF
require("toggleterm").setup{
}
EOF
nnoremap <C-\> <Cmd>ToggleTerm<CR>
" tnoremap <C-\> <Cmd>ToggleTerm<CR>
tnoremap <C-\> <Cmd>wincmd p<CR>
tnoremap <leader><Esc> <C-\><c-n>

View file

@ -1,3 +0,0 @@
let g:buftabline_numbers = 1
let g:buftabline_indicators = 1
let g:buftabline_separators = 1