init commit

This commit is contained in:
YuhangQ 2022-11-23 13:16:46 +08:00
parent e54dce08ba
commit 38cf7c82fc
12 changed files with 460 additions and 0 deletions

7
.luarc.json Normal file
View File

@ -0,0 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.diagnostics.globals": [
"vim",
"use"
]
}

11
init.vim Normal file
View File

@ -0,0 +1,11 @@
lua require('basic')
lua require('keybindings')
lua require('plugins')
" 插件配置
lua require('plugin-config/nvim-tree')
lua require('plugin-config/nvim-treesitter')
lua require('lsp/setup')
set background=dark
colorscheme nord

80
lua/basic.lua Normal file
View File

@ -0,0 +1,80 @@
-- utf8
vim.g.encoding = "UTF-8"
vim.o.fileencoding = 'utf-8'
-- jk移动时光标下上方保留8行
vim.o.scrolloff = 8
vim.o.sidescrolloff = 8
-- 使用相对行号
vim.wo.number = true
vim.wo.relativenumber = true
-- 高亮所在行
vim.wo.cursorline = true
-- 显示左侧图标指示列
vim.wo.signcolumn = "yes"
-- 右侧参考线,超过表示代码太长了,考虑换行
vim.wo.colorcolumn = "80"
-- 缩进2个空格等于一个Tab
vim.o.tabstop = 2
vim.bo.tabstop = 2
vim.o.softtabstop = 2
vim.o.shiftround = true
-- >> << 时移动长度
vim.o.shiftwidth = 2
vim.bo.shiftwidth = 2
-- 新行对齐当前行空格替代tab
vim.o.expandtab = true
vim.bo.expandtab = true
vim.o.autoindent = true
vim.bo.autoindent = true
vim.o.smartindent = true
-- 搜索大小写不敏感,除非包含大写
vim.o.ignorecase = true
vim.o.smartcase = true
-- 搜索不要高亮
vim.o.hlsearch = false
-- 边输入边搜索
vim.o.incsearch = true
-- 使用增强状态栏后不再需要 vim 的模式提示
vim.o.showmode = false
-- 命令行高为2提供足够的显示空间
vim.o.cmdheight = 2
-- 当文件被外部程序修改时,自动加载
vim.o.autoread = true
vim.bo.autoread = true
-- 禁止折行
vim.o.wrap = false
vim.wo.wrap = false
-- 行结尾可以跳到下一行
vim.o.whichwrap = 'b,s,<,>,[,],h,l'
-- 允许隐藏被修改过的buffer
vim.o.hidden = true
-- 鼠标支持
vim.o.mouse = "a"
-- 禁止创建备份文件
vim.o.backup = false
vim.o.writebackup = false
vim.o.swapfile = false
-- smaller updatetime
vim.o.updatetime = 300
-- 设置 timeoutlen 为等待键盘快捷键连击时间200毫秒可根据需要设置
-- 遇到问题详见https://github.com/nshen/learn-neovim-lua/issues/1
vim.o.timeoutlen = 200
-- split window 从下边和右边出现
vim.o.splitbelow = true
vim.o.splitright = true
-- 自动补全不自动选中
vim.g.completeopt = "menu,menuone,noselect,noinsert"
-- 样式
vim.o.background = "dark"
vim.o.termguicolors = true
vim.opt.termguicolors = true
-- 不可见字符的显示,这里只把空格显示为一个点
vim.o.list = true
vim.o.listchars = "space:·"
-- 补全增强
vim.o.wildmenu = true
-- Dont' pass messages to |ins-completin menu|
vim.o.shortmess = vim.o.shortmess .. 'c'
vim.o.pumheight = 10
-- always show tabline
vim.o.showtabline = 2

57
lua/keybindings.lua Normal file
View File

@ -0,0 +1,57 @@
vim.g.mapleader = " "
vim.g.maplocalleader = " "
local map = vim.api.nvim_set_keymap
local opt = {noremap = true, silent = true }
map("n", "<C-u>", "9k", opt)
map("n", "<C-d>", "9j", opt)
-- map('v', '<', '<gv', opt)
-- map('v', '>', '>gv', opt)
map("n", "sv", ":vsp<CR>", opt)
map("n", "sh", ":sp<CR>", opt)
map("n", "sc", "<C-w>c", opt)
map("n", "so", "<C-w>o", opt) -- close others
map("n", "<A-h>", "<C-w>h", opt)
map("n", "<A-j>", "<C-w>j", opt)
map("n", "<A-k>", "<C-w>k", opt)
map("n", "<A-l>", "<C-w>l", opt)
-- nvimTree
map('n', 'ct', ':NvimTreeToggle<CR>', opt)
local pluginKeys = {}
-- lsp 回调函数快捷键设置
pluginKeys.maplsp = function(mapbuf)
-- rename
mapbuf('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opt)
-- code action
mapbuf('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opt)
-- go xx
mapbuf('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opt)
mapbuf('n', 'gh', '<cmd>lua vim.lsp.buf.hover()<CR>', opt)
mapbuf('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opt)
mapbuf('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opt)
mapbuf('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opt)
-- diagnostic
mapbuf('n', 'go', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
mapbuf('n', 'gp', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opt)
mapbuf('n', 'gn', '<cmd>lua vim.diagnostic.goto_next()<CR>', opt)
-- mapbuf('n', '<leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
-- leader + =
mapbuf('n', '<leader>=', '<cmd>lua vim.lsp.buf.formatting()<CR>', opt)
-- mapbuf('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opt)
-- mapbuf('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opt)
-- mapbuf('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opt)
-- mapbuf('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opt)
-- mapbuf('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opt)
end
return pluginKeys

1
lua/lsp/clangd.lua Normal file
View File

@ -0,0 +1 @@

0
lua/lsp/lua.lua Normal file
View File

38
lua/lsp/setup.lua Normal file
View File

@ -0,0 +1,38 @@
local lsp_installer = require "nvim-lsp-installer"
-- 安装列表
-- https://github.com/williamboman/nvim-lsp-installer#available-lsps
-- { key: 语言 value: 配置文件 }
local servers = {
sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua
clangd = require "lsp.lua" -- /lua/lsp/clangd.lua
}
-- 自动安装 LanguageServers
for name, _ in pairs(servers) do
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found then
if not server:is_installed() then
print("Installing " .. name)
server:install()
end
end
end
lsp_installer.on_server_ready(function(server)
local opts = servers[server.name]
if opts then
opts.on_attach = function(_, 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
-- 绑定快捷键
require('keybindings').maplsp(buf_set_keymap)
end
opts.flags = {
debounce_text_changes = 150,
}
server:setup(opts)
end
end)

View File

@ -0,0 +1,7 @@
require'nvim-tree'.setup {
-- 不显示 git 状态图标
git = {
enable = false
}
}

View File

@ -0,0 +1,30 @@
require'nvim-treesitter.configs'.setup {
-- 安装 language parser
-- :TSInstallInfo 命令查看支持的语言
ensure_installed = {"html", "css", "lua", "javascript", "typescript", "tsx", "cpp", "c"},
-- 启用代码高亮功能
highlight = {
enable = true,
additional_vim_regex_highlighting = false
},
-- 启用增量选择
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<CR>',
node_incremental = '<CR>',
node_decremental = '<BS>',
scope_incremental = '<TAB>',
}
},
-- 启用基于Treesitter的代码格式化(=) . NOTE: This is an experimental feature.
indent = {
enable = true
}
}
-- 开启 Folding
vim.wo.foldmethod = 'expr'
vim.wo.foldexpr = 'nvim_treesitter#foldexpr()'
-- 默认不要折叠
-- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file
vim.wo.foldlevel = 99

32
lua/plugins.lua Normal file
View File

@ -0,0 +1,32 @@
return require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- gruvbox theme
use {
"ellisonleao/gruvbox.nvim",
requires = {"rktjmp/lush.nvim"}
}
use 'shaunsingh/nord.nvim'
use 'glepnir/zephyr-nvim'
-- nvim-tree (新增)
use {
'kyazdani42/nvim-tree.lua',
requires = 'kyazdani42/nvim-web-devicons'
}
-- treesitter
use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
-- lspconfig
use {'neovim/nvim-lspconfig', 'williamboman/nvim-lsp-installer'}
-- nvim-cmp
use 'hrsh7th/cmp-nvim-lsp' -- { name = nvim_lsp }
use 'hrsh7th/cmp-buffer' -- { name = 'buffer' },
use 'hrsh7th/cmp-path' -- { name = 'path' }
use 'hrsh7th/cmp-cmdline' -- { name = 'cmdline' }
use 'hrsh7th/nvim-cmp'
-- vsnip
use 'hrsh7th/cmp-vsnip' -- { name = 'vsnip' }
use 'hrsh7th/vim-vsnip'
use 'rafamadriz/friendly-snippets'
-- lspkind
use 'onsails/lspkind-nvim'
end)

189
plugin/packer_compiled.lua Normal file
View File

@ -0,0 +1,189 @@
-- Automatically generated packer.nvim plugin loader code
if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then
vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"')
return
end
vim.api.nvim_command('packadd packer.nvim')
local no_errors, error_msg = pcall(function()
_G._packer = _G._packer or {}
_G._packer.inside_compile = true
local time
local profile_info
local should_profile = false
if should_profile then
local hrtime = vim.loop.hrtime
profile_info = {}
time = function(chunk, start)
if start then
profile_info[chunk] = hrtime()
else
profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6
end
end
else
time = function(chunk, start) end
end
local function save_profiles(threshold)
local sorted_times = {}
for chunk_name, time_taken in pairs(profile_info) do
sorted_times[#sorted_times + 1] = {chunk_name, time_taken}
end
table.sort(sorted_times, function(a, b) return a[2] > b[2] end)
local results = {}
for i, elem in ipairs(sorted_times) do
if not threshold or threshold and elem[2] > threshold then
results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms'
end
end
if threshold then
table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)')
end
_G._packer.profile_output = results
end
time([[Luarocks path setup]], true)
local package_path_str = "/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua"
local install_cpath_pattern = "/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so"
if not string.find(package.path, package_path_str, 1, true) then
package.path = package.path .. ';' .. package_path_str
end
if not string.find(package.cpath, install_cpath_pattern, 1, true) then
package.cpath = package.cpath .. ';' .. install_cpath_pattern
end
time([[Luarocks path setup]], false)
time([[try_loadstring definition]], true)
local function try_loadstring(s, component, name)
local success, result = pcall(loadstring(s), name, _G.packer_plugins[name])
if not success then
vim.schedule(function()
vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {})
end)
end
return result
end
time([[try_loadstring definition]], false)
time([[Defining packer_plugins]], true)
_G.packer_plugins = {
["cmp-buffer"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-buffer",
url = "https://github.com/hrsh7th/cmp-buffer"
},
["cmp-cmdline"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-cmdline",
url = "https://github.com/hrsh7th/cmp-cmdline"
},
["cmp-nvim-lsp"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
url = "https://github.com/hrsh7th/cmp-nvim-lsp"
},
["cmp-path"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-path",
url = "https://github.com/hrsh7th/cmp-path"
},
["cmp-vsnip"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-vsnip",
url = "https://github.com/hrsh7th/cmp-vsnip"
},
["friendly-snippets"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/friendly-snippets",
url = "https://github.com/rafamadriz/friendly-snippets"
},
["gruvbox.nvim"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/gruvbox.nvim",
url = "https://github.com/ellisonleao/gruvbox.nvim"
},
["lspkind-nvim"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/lspkind-nvim",
url = "https://github.com/onsails/lspkind-nvim"
},
["lush.nvim"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/lush.nvim",
url = "https://github.com/rktjmp/lush.nvim"
},
["nord.nvim"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nord.nvim",
url = "https://github.com/shaunsingh/nord.nvim"
},
["nvim-cmp"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-cmp",
url = "https://github.com/hrsh7th/nvim-cmp"
},
["nvim-lsp-installer"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer",
url = "https://github.com/williamboman/nvim-lsp-installer"
},
["nvim-lspconfig"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
url = "https://github.com/neovim/nvim-lspconfig"
},
["nvim-tree.lua"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-tree.lua",
url = "https://github.com/kyazdani42/nvim-tree.lua"
},
["nvim-treesitter"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
url = "https://github.com/nvim-treesitter/nvim-treesitter"
},
["nvim-web-devicons"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-web-devicons",
url = "https://github.com/kyazdani42/nvim-web-devicons"
},
["packer.nvim"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/packer.nvim",
url = "https://github.com/wbthomason/packer.nvim"
},
["vim-vsnip"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/vim-vsnip",
url = "https://github.com/hrsh7th/vim-vsnip"
},
["zephyr-nvim"] = {
loaded = true,
path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/zephyr-nvim",
url = "https://github.com/glepnir/zephyr-nvim"
}
}
time([[Defining packer_plugins]], false)
_G._packer.inside_compile = false
if _G._packer.needs_bufread == true then
vim.cmd("doautocmd BufRead")
end
_G._packer.needs_bufread = false
if should_profile then save_profiles() end
end)
if not no_errors then
error_msg = error_msg:gsub('"', '\\"')
vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None')
end

8
test.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
printf("Hello World!");
for(int i=0; i<=10; i++) {
:
}
}