[feat] change nvim config from vimscript to lua

This commit is contained in:
jay
2023-08-28 02:22:29 +08:00
parent 009c896650
commit 4fd1b70a5c
19 changed files with 700 additions and 604 deletions
@@ -0,0 +1,48 @@
return {
"stevearc/aerial.nvim",
keys = {
{'<F8>', '<cmd>AerialToggle<CR>', desc = 'toggle aerial window', mode = 'n'},
},
opts = {
backends = {"lsp", "treesitter"},
-- optionally use on_attach to set keymaps when aerial has attached to a buffer
on_attach = function(bufnr)
-- Jump forwards/backwards with '{' and '}'
vim.keymap.set('n', '{', '<cmd>AerialPrev<CR>', {buffer = bufnr})
vim.keymap.set('n', '}', '<cmd>AerialNext<CR>', {buffer = bufnr})
end,
-- filter_kind = false,
filter_kind = {
"Class",
"Constructor",
"Enum",
"Function",
"Interface",
"Module",
"Method",
"Struct",
"Variable",
"Namespace",
"Package",
"Field",
"Constant",
},
--manage_folds = true,
link_tree_to_folds = false,
-- Show box drawing characters for the tree hierarchy
show_guides = true,
-- Customize the characters used when show_guides = true
guides = {
-- When the child item has a sibling below it
mid_item = "├─",
-- When the child item is the last in the list
last_item = "└─",
-- When there are nested child guides to the right
nested_top = "",
-- Raw indentation
whitespace = " ",
},
}
}
@@ -0,0 +1,26 @@
return {
"w0rp/ale",
lazy = false,
keys = {
{'<leader>=', '<Plug>(ale_fix)', mode = 'n'},
},
config = function ()
local g = vim.g
g.ale_linters = {
javascript = {'{{ if .nvim.js_linter }}{{ .nvim.js_linter }}{{ else }}eslint{{ end }}'},
typescript = {'{{ if .nvim.js_linter }}{{ .nvim.js_linter }}{{ else }}eslint{{ end }}'},
go = {'gopls'},
rust = {'analyzer'},
}
g.ale_fixers = {
javascript = {'{{ if .nvim.js_fixer }}{{ .nvim.js_fixer }}{{ else }}eslint{{ end }}'},
typescript = {'{{ if .nvim.js_fixer }}{{ .nvim.js_fixer }}{{ else }}eslint{{ end }}'},
}
g.ale_linters_explicit = 1
g.ale_lint_on_save = 1
g.ale_fix_on_save = 1
end
}
@@ -0,0 +1,10 @@
return {
"akinsho/bufferline.nvim",
version = "v4.*",
opts = {
options = {
mode = 'tabs',
diagnostics = 'nvim_lsp',
},
},
}
+42
View File
@@ -0,0 +1,42 @@
return {
"junegunn/fzf.vim",
dependencies = {
"junegunn/fzf",
},
config = function ()
local g = vim.g
local keymap = vim.keymap
g.fzf_action = {
['ctrl-t'] = 'tab split',
['ctrl-x'] = 'split',
['ctrl-v'] = 'vsplit',
}
g.fzf_colors = {
fg = {'fg', 'Normal'},
bg = {'bg', 'Normal'},
hl = {'fg', 'Comment'},
['fg+'] = {'fg', 'CursorLine', 'CursorColumn', 'Normal'},
['bg+'] = {'bg', 'CursorLine', 'CursorColumn'},
['hl+'] = {'fg', 'Statement'},
info = {'fg', 'PreProc'},
prompt = {'fg', 'Conditional'},
pointer = {'fg', 'Exception'},
marker = {'fg', 'Keyword'},
spinner = {'fg', 'Label'},
header = {'fg', 'Comment'},
}
g.fzf_history_dir = '~/.local/share/fzf-history'
keymap.set('n', '<leader>fl', ':Lines ')
keymap.set('n', '<leader>fb', ':BLines ')
keymap.set('n', '<leader>ff', ':Files ')
keymap.set('n', '<leader>fg', ':GFiles ')
keymap.set('n', '<leader>f?', ':GFiles? ')
keymap.set('n', '<leader>ft', ':Tags<cr>')
keymap.set('n', '<leader>fa', ':Ag ')
keymap.set('n', '<leader>fc', ':Commits ')
end
}
+26
View File
@@ -0,0 +1,26 @@
return {
"fatih/vim-go",
lazy = false,
keys = {},
config = function ()
vim.api.nvim_create_autocmd("FileType", {
pattern = 'go',
callback = function ()
vim.keymap.set('n', '<leader>err', '<Plug>(go-iferr)')
end
})
local g = vim.g
g.go_fmt_fail_silently = 1
g.go_fmt_command = "goimports"
g.go_def_mode = 'godef'
g.go_decls_includes = "func,type"
g.go_highlight_types = 1
g.go_highlight_fields = 1
g.go_highlight_functions = 1
g.go_highlight_function_calls = 1
g.go_highlight_operators = 1
g.go_highlight_extra_types = 1
end
}
+19
View File
@@ -0,0 +1,19 @@
return {
"phaazon/hop.nvim",
config = function ()
local hop = require('hop')
local keymap = vim.keymap
hop.setup()
-- keymap.set('', '<leader>f', function ()
-- hop.hint_char1()
-- end)
keymap.set('', '<leader>s', function ()
hop.hint_char2()
end)
keymap.set('', '<leader>w', function ()
hop.hint_words()
end)
end
}
@@ -0,0 +1,11 @@
return {
"lukas-reineke/indent-blankline.nvim",
opts = {
show_end_of_line = true,
show_current_context = true,
show_current_context_start = true,
},
config = function ()
vim.opt.list = true
end
}
+18
View File
@@ -0,0 +1,18 @@
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.list", {
defaults = {
lazy = false
},
})
+127
View File
@@ -0,0 +1,127 @@
return {
require('plugins.nvim_cmp'),
require('plugins.lsp'),
{
"ray-x/lsp_signature.nvim",
opts = {
hint_enable = true,
},
},
{
"scrooloose/nerdcommenter",
config = function ()
vim.g.NERDSpaceDelims=1
vim.g.NERDDefaultAlign='left'
end
},
"vim-scripts/DrawIt",
-- easymotion alternative
require('plugins.hop'),
require('plugins.ale'),
"mattn/emmet-vim",
require('plugins.go'),
{
"pangloss/vim-javascript",
config = function ()
vim.g.javascript_plugin_jsdoc = 1
end
},
"godlygeek/tabular",
"plasticboy/vim-markdown",
"ctrlpvim/ctrlp.vim",
-- fzf
require('plugins.fzf'),
"kyazdani42/nvim-web-devicons",
require('plugins.nvim_tree'),
"kien/tabman.vim",
-- for git
"tpope/vim-fugitive",
"christoomey/vim-conflicted",
-- for mark
"inkarkat/vim-ingo-library",
"inkarkat/vim-mark",
"rking/ag.vim",
{
"terryma/vim-multiple-cursors",
config = function ()
local g = vim.g
g.multi_cursor_use_default_mapping=0
-- Default mapping
g.multi_cursor_start_word_key = "<C-n>"
g.multi_cursor_select_all_word_key = '<A-n>'
g.multi_cursor_start_key = "g<C-n>"
g.multi_cursor_select_all_key = 'g<A-n>'
g.multi_cursor_next_key = "<C-n>"
g.multi_cursor_skip_key = '<C-x>'
g.multi_cursor_quit_key = '<Esc>'
end
},
require('plugins.lualine'),
require('plugins.bufferline'),
require('plugins.indent_blankline'),
"nvim-treesitter/nvim-treesitter",
{
"bluz71/vim-nightfly-colors",
config = function ()
vim.g.nightflyTransparent = true
vim.cmd[[ colorscheme nightfly ]]
end
},
{
"folke/tokyonight.nvim",
branch = "main",
},
"norcalli/nvim-colorizer.lua",
-- code outline
require('plugins.aerial'),
"tpope/vim-surround",
"buoto/gotests-vim",
"cespare/vim-toml",
{
"rust-lang/rust.vim",
config = function ()
local g = vim.g
g.rust_recommended_style = 0
g.rustfmt_autosave = 1
g.syntastic_rust_checkers = {'cargo'}
end
},
"vim-scripts/TaskList.vim",
"google/vim-jsonnet",
{
"github/copilot.vim",
keys = {
{'<c-j>', 'copilot#Accept("<CR>")', mode = 'i', silent = true, expr = true, noremap = true, replace_keycodes = false},
},
lazy = false,
init = function ()
vim.g.copilot_no_tab_map = true
end
},
-- temp plugins
"elkowar/yuck.vim",
-- themes
"tomasr/molokai",
}
+64
View File
@@ -0,0 +1,64 @@
return {
"neovim/nvim-lspconfig",
dependencies = {
{
"hrsh7th/cmp-nvim-lsp",
},
},
config = function ()
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local on_attach = function (client, bufnr)
local lspSig = require('lsp_signature')
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
lspSig.on_attach()
-- 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', '<leader>gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', '<leader>gt', '<cmd>tab split<CR><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', '<leader>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', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', '<leader>gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>ge', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
-- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
-- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
-- buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
-- buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
local nvlsp = require('lspconfig')
nvlsp['gopls'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
nvlsp['tsserver'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
nvlsp['rust_analyzer'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
nvlsp['bashls'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
end
}
@@ -0,0 +1,49 @@
return {
"nvim-lualine/lualine.nvim",
opts = {
options = {
icons_enabled = true,
theme = 'auto',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {
{
'filename',
file_status = true,
newfile_status = true,
path = 1,
},
},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
winbar = {},
inactive_winbar = {},
extensions = {}
}
}
@@ -0,0 +1,40 @@
return {
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
-- for vsnip users
"hrsh7th/cmp-vsnip",
"hrsh7th/vim-vsnip",
},
opts = function ()
local cmp = require('cmp')
return {
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({
-- behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
['<C-e>'] = cmp.mapping.abort(),
-- ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
}),
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
-- require'snippy'.expand_snippet(args.body) -- For `snippy` users.
end,
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{name = 'buffer'},
}),
}
end
}
@@ -0,0 +1,77 @@
return {
"kyazdani42/nvim-tree.lua",
keys = {
{"<leader>me", ':NvimTreeToggle<CR>', desc = 'open / close nvim tree', mode = 'n'},
{"<F3>", ':NvimTreeToggle<CR>', desc = 'open / close nvim tree', mode = 'n'}
},
opts = {
auto_reload_on_write = true,
disable_netrw = false,
hijack_cursor = false,
hijack_netrw = true,
hijack_unnamed_buffer_when_opening = false,
open_on_tab = false,
sort_by = "name",
update_cwd = false,
view = {
width = 40,
side = "left",
preserve_window_proportions = false,
number = false,
relativenumber = false,
signcolumn = "yes",
},
renderer = {
indent_markers = {
enable = false,
icons = {
corner = "",
edge = "",
none = " ",
},
},
},
hijack_directories = {
enable = true,
auto_open = true,
},
update_focused_file = {
enable = false,
update_cwd = false,
ignore_list = {},
},
system_open = {
cmd = nil,
args = {},
},
filters = {
dotfiles = false,
custom = {},
exclude = {},
},
git = {
enable = true,
ignore = true,
timeout = 400,
},
actions = {
use_system_clipboard = true,
change_dir = {
enable = true,
global = false,
},
open_file = {
quit_on_open = false,
resize_window = false,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
buftype = { "nofile", "terminal", "help" },
},
},
},
},
}
}