Initial nvim config, derived from kickstart.nvim.
This commit is contained in:
parent
09be919865
commit
39536754b3
38 changed files with 479 additions and 338 deletions
|
@ -1,4 +1,15 @@
|
|||
require("core")
|
||||
require("plugins")
|
||||
require("lsp")
|
||||
require("mappings")
|
||||
-- Remap leader key to <Space>
|
||||
vim.g.mapleader = ' '
|
||||
vim.g.maplocalleader = ' '
|
||||
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
|
||||
|
||||
-- Load modules
|
||||
require("utils.lazy").lazy_init()
|
||||
require("lazy").setup("plugins", {
|
||||
change_detection = {
|
||||
enabled = false,
|
||||
notify = false,
|
||||
},
|
||||
})
|
||||
|
||||
require("config")
|
||||
|
|
|
@ -1,25 +1,4 @@
|
|||
-- Line numbers
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
|
||||
-- Indentation
|
||||
vim.opt.expandtab = true
|
||||
vim.opt.autoindent = true
|
||||
vim.opt.smarttab = true
|
||||
vim.opt.shiftwidth = 4
|
||||
vim.opt.tabstop = 4
|
||||
vim.opt.softtabstop = 4
|
||||
|
||||
-- Enable syntax highlighting
|
||||
vim.opt.termguicolors = true
|
||||
vim.opt.syntax = on
|
||||
|
||||
-- Enable undo after closing vim
|
||||
vim.opt.undofile = true
|
||||
|
||||
-- vim.g.lightline = { colorscheme = "one" }
|
||||
|
||||
-- Autostart nvim-tree
|
||||
-- Open NvimTree on startup
|
||||
local function open_nvim_tree(data)
|
||||
local real_file = vim.fn.filereadable(data.file) == 1
|
||||
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
|
||||
|
@ -35,3 +14,10 @@ local function open_nvim_tree(data)
|
|||
end
|
||||
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
||||
|
||||
-- Resotre cursor on exit
|
||||
vim.api.nvim_create_autocmd("VimLeave", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
vim.o.guicursor = "n:ver20-blinkwait700-blinkoff400-blinkon250"
|
||||
end,
|
||||
})
|
5
.config/nvim/lua/config/init.lua
Normal file
5
.config/nvim/lua/config/init.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
require("config.options")
|
||||
require("config.plugins")
|
||||
require("config.mappings")
|
||||
require("config.autocmd")
|
||||
require("config.lsp")
|
111
.config/nvim/lua/config/lsp/init.lua
Normal file
111
.config/nvim/lua/config/lsp/init.lua
Normal file
|
@ -0,0 +1,111 @@
|
|||
-- This function gets run when an LSP connects to a particular buffer.
|
||||
local on_attach = function(_, bufnr)
|
||||
-- NOTE: Remember that lua is a real programming language, and as such it is possible
|
||||
-- to define small helper and utility functions so you don't have to repeat yourself
|
||||
-- many times.
|
||||
--
|
||||
-- In this case, we create a function that lets us more easily define mappings specific
|
||||
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||
local nmap = function(keys, func, desc)
|
||||
if desc then
|
||||
desc = 'LSP: ' .. desc
|
||||
end
|
||||
|
||||
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||
|
||||
nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
|
||||
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
|
||||
nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
|
||||
nmap('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
|
||||
|
||||
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
||||
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
||||
|
||||
-- See `:help K` for why this keymap
|
||||
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
||||
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||
|
||||
-- Lesser used LSP functionality
|
||||
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||
nmap('<leader>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, '[W]orkspace [L]ist Folders')
|
||||
|
||||
-- Create a command `:Format` local to the LSP buffer
|
||||
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||
vim.lsp.buf.format()
|
||||
end, { desc = 'Format current buffer with LSP' })
|
||||
end
|
||||
|
||||
-- document existing key chains
|
||||
-- require('which-key').register {
|
||||
-- ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
|
||||
-- ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
|
||||
-- ['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
|
||||
-- ['<leader>h'] = { name = 'More git', _ = 'which_key_ignore' },
|
||||
-- ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
|
||||
-- ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
|
||||
-- ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
|
||||
-- }
|
||||
|
||||
-- mason-lspconfig requires that these setup functions are called in this order
|
||||
-- before setting up the servers.
|
||||
require('mason').setup()
|
||||
require('mason-lspconfig').setup()
|
||||
|
||||
-- Enable the following language servers
|
||||
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
||||
--
|
||||
-- Add any additional override configuration in the following tables. They will be passed to
|
||||
-- the `settings` field of the server config. You must look up that documentation yourself.
|
||||
--
|
||||
-- If you want to override the default filetypes that your language server will attach to you can
|
||||
-- define the property 'filetypes' to the map in question.
|
||||
local servers = {
|
||||
clangd = {},
|
||||
-- gopls = {},
|
||||
-- pyright = {},
|
||||
-- rust_analyzer = {},
|
||||
-- tsserver = {},
|
||||
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
||||
|
||||
lua_ls = {
|
||||
Lua = {
|
||||
workspace = { checkThirdParty = false },
|
||||
telemetry = { enable = false },
|
||||
-- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings
|
||||
-- diagnostics = { disable = { 'missing-fields' } },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Setup neovim lua configuration
|
||||
require('neodev').setup()
|
||||
|
||||
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
||||
|
||||
-- Ensure the servers above are installed
|
||||
local mason_lspconfig = require 'mason-lspconfig'
|
||||
|
||||
mason_lspconfig.setup {
|
||||
ensure_installed = vim.tbl_keys(servers),
|
||||
}
|
||||
|
||||
mason_lspconfig.setup_handlers {
|
||||
function(server_name)
|
||||
require('lspconfig')[server_name].setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
settings = servers[server_name],
|
||||
filetypes = (servers[server_name] or {}).filetypes,
|
||||
}
|
||||
end,
|
||||
}
|
35
.config/nvim/lua/config/mappings.lua
Normal file
35
.config/nvim/lua/config/mappings.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
local map = vim.keymap.set
|
||||
|
||||
-- Movements between splits
|
||||
map('n', '<C-h>', '<C-w>h')
|
||||
map('n', '<C-j>', '<C-w>j')
|
||||
map('n', '<C-k>', '<C-w>k')
|
||||
map('n', '<C-l>', '<C-w>l')
|
||||
|
||||
-- Movement between buffers
|
||||
map({'n', 'v', 'i'}, '<A-h>', ':bp<CR>')
|
||||
map({'n', 'v', 'i'}, '<A-l>', ':bn<CR>')
|
||||
|
||||
-- Remap for dealing with word wrap
|
||||
map('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
||||
map('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
||||
|
||||
-- Exit buffers/nvim with <leader>
|
||||
map("n", "<leader>q", function() require('utils.close_buffer').close_buffer() end)
|
||||
map("n", "<leader>Q", ":%bd | quit<CR>")
|
||||
map("n", "<leader><C-Q>", ":%bd! | quit!<CR>")
|
||||
map("n", "<leader>w", ":write<CR>")
|
||||
|
||||
-- Copy and paste from clipboard
|
||||
map("n", "<leader>y", '"+yy')
|
||||
map("v", "<leader>y", '"+y')
|
||||
map({ "n", "v" }, "<leader>p", '"+p')
|
||||
|
||||
-- Remap comments
|
||||
map("n", "<C-_>", require("Comment.api").toggle.linewise.current)
|
||||
map("i", "<C-_>", require("Comment.api").toggle.linewise.current)
|
||||
map("x", "<C-_>", function()
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<ESC>', true, false, true), 'nx', false)
|
||||
require("Comment.api").toggle.linewise(vim.fn.visualmode())
|
||||
end
|
||||
)
|
31
.config/nvim/lua/config/options.lua
Normal file
31
.config/nvim/lua/config/options.lua
Normal file
|
@ -0,0 +1,31 @@
|
|||
vim.o.hlsearch = true
|
||||
|
||||
-- Enable line numbers
|
||||
vim.wo.number = true
|
||||
vim.wo.relativenumber = true
|
||||
|
||||
-- Enable mouse mode
|
||||
vim.o.mouse = 'a'
|
||||
|
||||
-- Enable break indent
|
||||
vim.o.breakindent = true
|
||||
|
||||
-- Save undo history
|
||||
vim.o.undofile = true
|
||||
|
||||
-- Case-insensitive searching UNLESS \C or capital in search
|
||||
vim.o.ignorecase = true
|
||||
vim.o.smartcase = true
|
||||
|
||||
-- Keep signcolumn on by default
|
||||
vim.wo.signcolumn = 'yes'
|
||||
|
||||
-- Decrease update time
|
||||
vim.o.updatetime = 250
|
||||
vim.o.timeoutlen = 300
|
||||
|
||||
-- Set completeopt to have a better completion experience
|
||||
vim.o.completeopt = 'menuone,noselect'
|
||||
|
||||
-- NOTE: You should make sure your terminal supports this
|
||||
vim.o.termguicolors = true
|
5
.config/nvim/lua/config/plugins/init.lua
Normal file
5
.config/nvim/lua/config/plugins/init.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
require("config.plugins.treesitter")
|
||||
require("config.plugins.telescope")
|
||||
require("config.plugins.nvim-cmp")
|
||||
require("config.plugins.nvim-tree")
|
||||
require("config.plugins.lualine")
|
1
.config/nvim/lua/config/plugins/lualine.lua
Normal file
1
.config/nvim/lua/config/plugins/lualine.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require('lualine').setup()
|
49
.config/nvim/lua/config/plugins/nvim-cmp.lua
Normal file
49
.config/nvim/lua/config/plugins/nvim-cmp.lua
Normal file
|
@ -0,0 +1,49 @@
|
|||
local cmp = require 'cmp'
|
||||
local luasnip = require 'luasnip'
|
||||
require('luasnip.loaders.from_vscode').lazy_load()
|
||||
luasnip.config.setup {}
|
||||
|
||||
cmp.setup {
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
completion = {
|
||||
completeopt = 'menu,menuone,noinsert'
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert {
|
||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete {},
|
||||
['<CR>'] = cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
},
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
},
|
||||
}
|
||||
|
3
.config/nvim/lua/config/plugins/nvim-tree.lua
Normal file
3
.config/nvim/lua/config/plugins/nvim-tree.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
vim.g.loaded_netrw = 1
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
require("nvim-tree").setup()
|
32
.config/nvim/lua/config/plugins/telescope.lua
Normal file
32
.config/nvim/lua/config/plugins/telescope.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
require('telescope').setup {
|
||||
defaults = {
|
||||
mappings = {
|
||||
i = {
|
||||
['<C-u>'] = false,
|
||||
['<C-d>'] = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Enable telescope fzf native, if installed
|
||||
pcall(require('telescope').load_extension, 'fzf')
|
||||
|
||||
-- See `:help telescope.builtin`
|
||||
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
|
||||
-- vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
|
||||
vim.keymap.set('n', '<leader>/', function()
|
||||
-- You can pass additional configuration to telescope to change theme, layout, etc.
|
||||
require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
|
||||
winblend = 10,
|
||||
previewer = false,
|
||||
})
|
||||
end, { desc = '[/] Fuzzily search in current buffer' })
|
||||
|
||||
vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' })
|
||||
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
|
||||
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
|
||||
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
|
||||
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
|
||||
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
|
||||
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
|
65
.config/nvim/lua/config/plugins/treesitter.lua
Normal file
65
.config/nvim/lua/config/plugins/treesitter.lua
Normal file
|
@ -0,0 +1,65 @@
|
|||
vim.defer_fn(function()
|
||||
require('nvim-treesitter.configs').setup {
|
||||
-- Add languages to be installed here that you want installed for treesitter
|
||||
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' },
|
||||
|
||||
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
|
||||
auto_install = false,
|
||||
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
init_selection = '<c-space>',
|
||||
node_incremental = '<c-space>',
|
||||
scope_incremental = '<c-s>',
|
||||
node_decremental = '<M-space>',
|
||||
},
|
||||
},
|
||||
textobjects = {
|
||||
select = {
|
||||
enable = true,
|
||||
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
|
||||
keymaps = {
|
||||
-- You can use the capture groups defined in textobjects.scm
|
||||
['aa'] = '@parameter.outer',
|
||||
['ia'] = '@parameter.inner',
|
||||
['af'] = '@function.outer',
|
||||
['if'] = '@function.inner',
|
||||
['ac'] = '@class.outer',
|
||||
['ic'] = '@class.inner',
|
||||
},
|
||||
},
|
||||
move = {
|
||||
enable = true,
|
||||
set_jumps = true, -- whether to set jumps in the jumplist
|
||||
goto_next_start = {
|
||||
[']m'] = '@function.outer',
|
||||
[']]'] = '@class.outer',
|
||||
},
|
||||
goto_next_end = {
|
||||
[']M'] = '@function.outer',
|
||||
[']['] = '@class.outer',
|
||||
},
|
||||
goto_previous_start = {
|
||||
['[m'] = '@function.outer',
|
||||
['[['] = '@class.outer',
|
||||
},
|
||||
goto_previous_end = {
|
||||
['[M'] = '@function.outer',
|
||||
['[]'] = '@class.outer',
|
||||
},
|
||||
},
|
||||
swap = {
|
||||
enable = true,
|
||||
swap_next = {
|
||||
['<leader>a'] = '@parameter.inner',
|
||||
},
|
||||
swap_previous = {
|
||||
['<leader>A'] = '@parameter.inner',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
end, 0)
|
|
@ -1,4 +0,0 @@
|
|||
return {
|
||||
"bashls",
|
||||
settings = { },
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
return {
|
||||
"clangd",
|
||||
settings = {}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
return {
|
||||
"pylsp",
|
||||
settings = {
|
||||
["pylsp"] = {
|
||||
plugins = {
|
||||
pylint = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
return {
|
||||
"akinsho/bufferline.nvim",
|
||||
config = {
|
||||
options = {
|
||||
buffer_close_icon = "✕",
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
return {
|
||||
'numToStr/Comment.nvim',
|
||||
opts = { },
|
||||
lazy = false,
|
||||
config = function()
|
||||
require('Comment').setup()
|
||||
end,
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
return { "nvim-tree/nvim-web-devicons" }
|
|
@ -1,5 +0,0 @@
|
|||
return {
|
||||
"ethanholz/nvim-lastplace",
|
||||
config = {}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
return {
|
||||
"itchyny/lightline.vim",
|
||||
config = function()
|
||||
vim.g.lightline = {
|
||||
colorscheme = "one",
|
||||
enable = {
|
||||
tabline = 0
|
||||
}
|
||||
}
|
||||
end
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
return { "neovim/nvim-lspconfig" }
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
return {
|
||||
"nvim-tree/nvim-tree.lua",
|
||||
config = function()
|
||||
vim.g.loaded_netrw = 1
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
require("nvim-tree").setup()
|
||||
end,
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
return {
|
||||
"joshdick/onedark.vim",
|
||||
lazy = false,
|
||||
config = function()
|
||||
vim.cmd([[colorscheme onedark]])
|
||||
end,
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
return {
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
build = ":TSUpdate",
|
||||
config = function ()
|
||||
local configs = require("nvim-treesitter.configs")
|
||||
|
||||
configs.setup({
|
||||
ensure_installed = { "c", "cpp", "lua", "vim", "vimdoc", "query", "python", "javascript", "html" },
|
||||
sync_install = false,
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
})
|
||||
end
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
local lspconfig = require("lspconfig")
|
||||
|
||||
local custom_attach = function(client, bufnr)
|
||||
-- Mappings.
|
||||
local map = function(mode, l, r, opts)
|
||||
opts = opts or {}
|
||||
opts.silent = true
|
||||
opts.buffer = bufnr
|
||||
keymap.set(mode, l, r, opts)
|
||||
end
|
||||
|
||||
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
|
||||
map("n", "<C-]>", vim.lsp.buf.definition)
|
||||
map("n", "K", vim.lsp.buf.hover)
|
||||
map("n", "<C-k>", vim.lsp.buf.signature_help)
|
||||
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
|
||||
map("n", "gr", vim.lsp.buf.references, { desc = "show references" })
|
||||
map("n", "[d", diagnostic.goto_prev, { desc = "previous diagnostic" })
|
||||
map("n", "]d", diagnostic.goto_next, { desc = "next diagnostic" })
|
||||
-- this puts diagnostics from opened files to quickfix
|
||||
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
|
||||
-- this puts diagnostics from current buffer to quickfix
|
||||
map("n", "<space>qb", function() set_qflist(bufnr) end, { desc = "put buffer diagnostics to qf" })
|
||||
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
|
||||
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
|
||||
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
|
||||
map("n", "<space>wl", function()
|
||||
inspect(vim.lsp.buf.list_workspace_folders())
|
||||
end, { desc = "list workspace folder" })
|
||||
|
||||
-- Set some key bindings conditional on server capabilities
|
||||
if client.server_capabilities.documentFormattingProvider then
|
||||
map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" })
|
||||
end
|
||||
|
||||
api.nvim_create_autocmd("CursorHold", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
local float_opts = {
|
||||
focusable = false,
|
||||
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
|
||||
border = "rounded",
|
||||
source = "always", -- show source in diagnostic popup window
|
||||
prefix = " ",
|
||||
}
|
||||
|
||||
if not vim.b.diagnostics_pos then
|
||||
vim.b.diagnostics_pos = { nil, nil }
|
||||
end
|
||||
|
||||
local cursor_pos = api.nvim_win_get_cursor(0)
|
||||
if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2])
|
||||
and #diagnostic.get() > 0
|
||||
then
|
||||
diagnostic.open_float(nil, float_opts)
|
||||
end
|
||||
|
||||
vim.b.diagnostics_pos = cursor_pos
|
||||
end,
|
||||
})
|
||||
|
||||
-- The blow command will highlight the current variable and its usages in the buffer.
|
||||
if client.server_capabilities.documentHighlightProvider then
|
||||
vim.cmd([[
|
||||
hi! link LspReferenceRead Visual
|
||||
hi! link LspReferenceText Visual
|
||||
hi! link LspReferenceWrite Visual
|
||||
]])
|
||||
|
||||
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||
api.nvim_create_autocmd("CursorHold" , {
|
||||
group = gid,
|
||||
buffer = bufnr,
|
||||
callback = function ()
|
||||
lsp.buf.document_highlight()
|
||||
end
|
||||
})
|
||||
|
||||
api.nvim_create_autocmd("CursorMoved" , {
|
||||
group = gid,
|
||||
buffer = bufnr,
|
||||
callback = function ()
|
||||
lsp.buf.clear_references()
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
if vim.g.logging_level == "debug" then
|
||||
local msg = string.format("Language server %s started!", client.name)
|
||||
vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
lspconfig.clangd.setup {
|
||||
on_attach = custom_attach,
|
||||
filetypes = { "c", "cpp", "cc" },
|
||||
flags = {
|
||||
debounce_text_changes = 500,
|
||||
},
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
local map = vim.keymap.set
|
||||
|
||||
-- Remap leader
|
||||
vim.g.mapleader = " "
|
||||
map('n', '<Space>', '<Nop>')
|
||||
|
||||
-- Buffer movements
|
||||
map("n", "<A-h>", ":bp<CR>")
|
||||
map("n", "<A-l>", ":bn<CR>")
|
||||
|
||||
-- Make use of Shift+hjkl
|
||||
map("n", "H", "^")
|
||||
map("n", "L", "$")
|
||||
map("n", "<A-j>", "}")
|
||||
map("n", "<A-k>", "{")
|
||||
|
||||
-- Leader remap
|
||||
map("n", "<Leader>w", ":write<CR>")
|
||||
map("n", "<Leader>e", ":NvimTreeFocus<CR>")
|
||||
|
||||
-- Split movements
|
||||
map("n", "<Leader>h", "<C-w>h")
|
||||
map("n", "<Leader>j", "<C-w>j")
|
||||
map("n", "<Leader>k", "<C-w>k")
|
||||
map("n", "<Leader>l", "<C-w>l")
|
||||
|
||||
-- Remap comments
|
||||
map("n", "<C-_>", require("Comment.api").toggle.linewise.current)
|
||||
map("i", "<C-_>", require("Comment.api").toggle.linewise.current)
|
||||
map("x", "<C-_>", function() -- some evil trickery with comment plugin
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<ESC>', true, false, true), 'nx', false)
|
||||
require("Comment.api").toggle.linewise(vim.fn.visualmode())
|
||||
end
|
||||
)
|
||||
|
||||
-- Close buffer and nvim
|
||||
local close_buffer_and_nvimtree = function()
|
||||
local try_quit = function(command)
|
||||
local success, errorMsg = pcall(vim.api.nvim_command, command)
|
||||
if not success then
|
||||
print("Failed to quit: " .. errorMsg)
|
||||
end
|
||||
end
|
||||
|
||||
local tree = require("nvim-tree.api").tree
|
||||
local buffer_count = #vim.fn.filter(vim.fn.range(1, vim.fn.bufnr '$'), 'buflisted(v:val)')
|
||||
|
||||
if buffer_count == 0 then
|
||||
try_quit("quit")
|
||||
-- elseif buffer_count == 1 then
|
||||
-- vim.cmd("e .")
|
||||
-- try_quit("bd")
|
||||
-- vim.cmd("NvimTreeClose")
|
||||
else
|
||||
tree.toggle({ focus = false })
|
||||
try_quit("bd")
|
||||
tree.toggle({ focus = false })
|
||||
end
|
||||
-- if buffer_count == 1 and #vim.api.nvim_list_wins() == 1 then
|
||||
-- try_quit("quit")
|
||||
-- end
|
||||
end
|
||||
|
||||
-- Leader remapping
|
||||
map("n", "<Leader>q", function() close_buffer_and_nvimtree() end)
|
||||
map("n", "<Leader>Q", ":%bd | quit<CR>")
|
||||
map("n", "<Leader><C-Q>", ":%bd! | quit!<CR>")
|
||||
map("n", "<Leader><C-Q>", ":%bd! | quit!<CR>")
|
||||
|
||||
map("v", "<Leader>y", '"+y')
|
||||
map("n", "<Leader>y", '"+yy')
|
||||
|
||||
map({ "n", "v" }, "<Leader>p", '"+p')
|
||||
map({ "n", "v" }, "<Leader>P", '"+P')
|
||||
|
||||
-- Toggle tree
|
||||
map("n", "<C-b>", function() require("nvim-tree.api").tree.toggle({ focus=false }) end)
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
require("utils").init_lazy()
|
||||
|
||||
require("lazy").setup{
|
||||
require("configs.plugins.bufferline"),
|
||||
require("configs.plugins.comment"),
|
||||
require("configs.plugins.devicons"),
|
||||
require("configs.plugins.lastplace"),
|
||||
require("configs.plugins.lightline"),
|
||||
require("configs.plugins.lspconfig"),
|
||||
require("configs.plugins.nvim-tree"),
|
||||
require("configs.plugins.onedark"),
|
||||
require("configs.plugins.treesitter"),
|
||||
}
|
8
.config/nvim/lua/plugins/indent-blankline.lua
Normal file
8
.config/nvim/lua/plugins/indent-blankline.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
return {
|
||||
-- Add indentation guides even on blank lines
|
||||
'lukas-reineke/indent-blankline.nvim',
|
||||
-- Enable `lukas-reineke/indent-blankline.nvim`
|
||||
-- See `:help ibl`
|
||||
main = 'ibl',
|
||||
opts = {},
|
||||
}
|
11
.config/nvim/lua/plugins/init.lua
Normal file
11
.config/nvim/lua/plugins/init.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
return {
|
||||
'tpope/vim-fugitive',
|
||||
'tpope/vim-rhubarb',
|
||||
'tpope/vim-sleuth',
|
||||
'nvim-tree/nvim-web-devicons',
|
||||
"nvim-tree/nvim-tree.lua",
|
||||
'nvim-lualine/lualine.nvim',
|
||||
{ 'numToStr/Comment.nvim', opts = {} },
|
||||
{ 'ethanholz/nvim-lastplace', config = {} },
|
||||
{ "akinsho/bufferline.nvim", config = {} },
|
||||
}
|
14
.config/nvim/lua/plugins/nvim-cmp.lua
Normal file
14
.config/nvim/lua/plugins/nvim-cmp.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
return {
|
||||
'hrsh7th/nvim-cmp',
|
||||
dependencies = {
|
||||
-- Snippet Engine & its associated nvim-cmp source
|
||||
'L3MON4D3/LuaSnip',
|
||||
'saadparwaiz1/cmp_luasnip',
|
||||
|
||||
-- Adds LSP completion capabilities
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
|
||||
-- Adds a number of user-friendly snippets
|
||||
'rafamadriz/friendly-snippets',
|
||||
},
|
||||
}
|
16
.config/nvim/lua/plugins/nvim-lspconfig.lua
Normal file
16
.config/nvim/lua/plugins/nvim-lspconfig.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
return {
|
||||
-- LSP Configuration & Plugins
|
||||
'neovim/nvim-lspconfig',
|
||||
dependencies = {
|
||||
-- Automatically install LSPs to stdpath for neovim
|
||||
'williamboman/mason.nvim',
|
||||
'williamboman/mason-lspconfig.nvim',
|
||||
|
||||
-- Useful status updates for LSP
|
||||
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
|
||||
{ 'j-hui/fidget.nvim', opts = {} },
|
||||
|
||||
-- Additional lua configuration, makes nvim stuff amazing!
|
||||
'folke/neodev.nvim',
|
||||
},
|
||||
}
|
8
.config/nvim/lua/plugins/nvim-tresitter.lua
Normal file
8
.config/nvim/lua/plugins/nvim-tresitter.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
return {
|
||||
-- Highlight, edit, and navigate code
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
dependencies = {
|
||||
'nvim-treesitter/nvim-treesitter-textobjects',
|
||||
},
|
||||
build = ':TSUpdate',
|
||||
}
|
6
.config/nvim/lua/plugins/onedark.lua
Normal file
6
.config/nvim/lua/plugins/onedark.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
return {
|
||||
'navarasu/onedark.nvim',
|
||||
config = function()
|
||||
vim.cmd.colorscheme 'onedark'
|
||||
end,
|
||||
}
|
11
.config/nvim/lua/plugins/telescope.lua
Normal file
11
.config/nvim/lua/plugins/telescope.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
return {
|
||||
'nvim-telescope/telescope.nvim',
|
||||
branch = '0.1.x',
|
||||
dependencies = {
|
||||
'nvim-lua/plenary.nvim',
|
||||
{
|
||||
'nvim-telescope/telescope-fzf-native.nvim',
|
||||
build = 'make',
|
||||
},
|
||||
},
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
local M = {}
|
||||
|
||||
function M.init_lazy()
|
||||
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",
|
||||
lazypath,
|
||||
})
|
||||
end
|
||||
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
end
|
||||
|
||||
function load_server(lspconfig, server)
|
||||
server_name = server[1]
|
||||
table.remove(server, 1)
|
||||
lspconfig[server_name].setup(server)
|
||||
end
|
||||
|
||||
function M.load_servers(servers)
|
||||
lspconfig = require("lspconfig")
|
||||
for _, server in ipairs(servers) do
|
||||
load_server(lspconfig, server)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
23
.config/nvim/lua/utils/close_buffer.lua
Normal file
23
.config/nvim/lua/utils/close_buffer.lua
Normal file
|
@ -0,0 +1,23 @@
|
|||
local M = { }
|
||||
|
||||
function M.close_buffer()
|
||||
local try_quit = function(command)
|
||||
local success, errorMsg = pcall(vim.api.nvim_command, command)
|
||||
if not success then
|
||||
print("Failed to quit: " .. errorMsg)
|
||||
end
|
||||
end
|
||||
|
||||
local tree = require("nvim-tree.api").tree
|
||||
local buffer_count = #vim.fn.filter(vim.fn.range(1, vim.fn.bufnr '$'), 'buflisted(v:val)')
|
||||
|
||||
if buffer_count ~= 1 then
|
||||
tree.toggle({ focus = false })
|
||||
try_quit("bd")
|
||||
tree.toggle({ focus = false })
|
||||
else
|
||||
try_quit("qa")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
4
.config/nvim/lua/utils/init.lua
Normal file
4
.config/nvim/lua/utils/init.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
return {
|
||||
require("utils.lazy"),
|
||||
require("utils.close_buffer"),
|
||||
}
|
18
.config/nvim/lua/utils/lazy.lua
Normal file
18
.config/nvim/lua/utils/lazy.lua
Normal file
|
@ -0,0 +1,18 @@
|
|||
local M = { }
|
||||
|
||||
function M.lazy_init()
|
||||
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)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue