aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-09-08 17:57:37 +0800
committercrupest <crupest@outlook.com>2023-09-09 09:22:26 +0800
commit3c500ccfa20273a5f1670e07acd5f73ac49d05f3 (patch)
tree428b1905085e48dace6b834a688a76f4ae1c8bdb
parent2dfb1a054c77552e23205ddcce7520b5e10adad4 (diff)
downloadcrupest-3c500ccfa20273a5f1670e07acd5f73ac49d05f3.tar.gz
crupest-3c500ccfa20273a5f1670e07acd5f73ac49d05f3.tar.bz2
crupest-3c500ccfa20273a5f1670e07acd5f73ac49d05f3.zip
Update nvim config.
-rw-r--r--configs/nvim/init.lua83
-rw-r--r--configs/nvim/lazy-lock.json4
-rw-r--r--configs/nvim/lua/open_project.lua17
-rw-r--r--configs/nvim/lua/plugins/plenary-nvim.lua3
-rw-r--r--configs/nvim/lua/plugins/trouble-nvim.lua3
-rw-r--r--configs/nvim/lua/plugins/which-key-nvim.lua8
6 files changed, 113 insertions, 5 deletions
diff --git a/configs/nvim/init.lua b/configs/nvim/init.lua
index f70919d..8781791 100644
--- a/configs/nvim/init.lua
+++ b/configs/nvim/init.lua
@@ -2,8 +2,6 @@
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-
-vim.cmd.cd("~");
vim.opt.shell = "pwsh";
vim.opt.termguicolors = true;
@@ -12,6 +10,7 @@ vim.opt.softtabstop = 4;
vim.opt.shiftwidth = 4;
vim.opt.expandtab = true;
vim.opt.wrap = false;
+vim.opt.number = true;
if vim.g.neovide then
vim.opt.guifont = "FiraCodeNerdFont";
@@ -44,7 +43,7 @@ require("nvim-tree").setup()
require('lualine').setup()
-- setup bufferline
-require("bufferline").setup{
+require("bufferline").setup {
options = {
offsets = {
{
@@ -90,10 +89,47 @@ cmp.setup({
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig")
+-- setup lsp clangd
lspconfig.clangd.setup {
- capabilities = capabilites
+ capabilities = capabilities
+}
+
+-- setup lsp lua
+require 'lspconfig'.lua_ls.setup {
+ on_init = function(client)
+ local path = client.workspace_folders[1].name
+ if not vim.loop.fs_stat(path .. '/.luarc.json') and not vim.loop.fs_stat(path .. '/.luarc.jsonc') then
+ client.config.settings = vim.tbl_deep_extend('force', client.config.settings, {
+ Lua = {
+ runtime = {
+ -- Tell the language server which version of Lua you're using
+ -- (most likely LuaJIT in the case of Neovim)
+ version = 'LuaJIT'
+ },
+ -- Make the server aware of Neovim runtime files
+ workspace = {
+ checkThirdParty = false,
+ library = {
+ vim.env.VIMRUNTIME
+ -- "${3rd}/luv/library"
+ -- "${3rd}/busted/library",
+ }
+ -- or pull in all of 'runtimepath'. NOTE: this is a lot slower
+ -- library = vim.api.nvim_get_runtime_file("", true)
+ }
+ }
+ })
+
+ client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
+ end
+ return true
+ end
}
+-- setup trouble
+require("trouble").setup()
+require("trouble.providers.telescope")
+
-- setup keymap for telescope
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
@@ -101,3 +137,42 @@ vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
+-- setup keymap for lsp
+
+-- Global mappings.
+-- See `:help vim.diagnostic.*` for documentation on any of the below functions
+vim.keymap.set('n', '<space>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', '<space>q', vim.diagnostic.setloclist)
+
+-- Use LspAttach autocommand to only map the following keys
+-- after the language server attaches to the current buffer
+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', 'K', vim.lsp.buf.hover, opts)
+ vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
+ vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
+ vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
+ vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
+ vim.keymap.set('n', '<space>wl', function()
+ print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+ end, opts)
+ vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
+ vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
+ vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
+ vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
+ vim.keymap.set('n', '<space>f', function()
+ vim.lsp.buf.format { async = true }
+ end, opts)
+ end,
+})
diff --git a/configs/nvim/lazy-lock.json b/configs/nvim/lazy-lock.json
index 2d69639..28efe5b 100644
--- a/configs/nvim/lazy-lock.json
+++ b/configs/nvim/lazy-lock.json
@@ -16,5 +16,7 @@
"nvim-web-devicons": { "branch": "master", "commit": "bc11ee2498de2310de5776477dd9dce65d03b464" },
"plenary.nvim": { "branch": "master", "commit": "a56bf0071bf63d35274fdc4738bb1e8821cfd2ea" },
"telescope.nvim": { "branch": "master", "commit": "18f10f28007cb8b4d50324217349c3f568684be2" },
- "tokyonight.nvim": { "branch": "main", "commit": "9a01eada39558dc3243278e6805d90e8dff45dc0" }
+ "tokyonight.nvim": { "branch": "main", "commit": "9a01eada39558dc3243278e6805d90e8dff45dc0" },
+ "trouble.nvim": { "branch": "main", "commit": "3f85d8ed30e97ceeddbbcf80224245d347053711" },
+ "which-key.nvim": { "branch": "main", "commit": "7ccf476ebe0445a741b64e36c78a682c1c6118b7" }
} \ No newline at end of file
diff --git a/configs/nvim/lua/open_project.lua b/configs/nvim/lua/open_project.lua
new file mode 100644
index 0000000..5228143
--- /dev/null
+++ b/configs/nvim/lua/open_project.lua
@@ -0,0 +1,17 @@
+local a = require'plenary.async'
+:with
+local context_manager = require "plenary.context_manager"
+local with = context_manager.with
+local open = context_manager.open
+
+local err, stat = a.fs_stat("./.project");
+assert(not error, ".project file does not exist, you should run this script at project root.")
+
+-- open nvim tree
+local nvim_tree_api = require("nvim-tree.api")
+nvim_tree_api.open()
+
+-- open terminal
+vim.cmd("split")
+vim.cmd
+
diff --git a/configs/nvim/lua/plugins/plenary-nvim.lua b/configs/nvim/lua/plugins/plenary-nvim.lua
new file mode 100644
index 0000000..d2c1874
--- /dev/null
+++ b/configs/nvim/lua/plugins/plenary-nvim.lua
@@ -0,0 +1,3 @@
+return {
+ "nvim-lua/plenary.nvim"
+}
diff --git a/configs/nvim/lua/plugins/trouble-nvim.lua b/configs/nvim/lua/plugins/trouble-nvim.lua
new file mode 100644
index 0000000..3ed7ee3
--- /dev/null
+++ b/configs/nvim/lua/plugins/trouble-nvim.lua
@@ -0,0 +1,3 @@
+return {
+ "folke/trouble.nvim",
+}
diff --git a/configs/nvim/lua/plugins/which-key-nvim.lua b/configs/nvim/lua/plugins/which-key-nvim.lua
new file mode 100644
index 0000000..11be1bd
--- /dev/null
+++ b/configs/nvim/lua/plugins/which-key-nvim.lua
@@ -0,0 +1,8 @@
+return {
+ "folke/which-key.nvim",
+ event = "VeryLazy",
+ init = function()
+ vim.o.timeout = true
+ vim.o.timeoutlen = 300
+ end,
+}