Rewrite Nvim Config based on kickstart.nvim
This commit is contained in:
parent
8e7a295332
commit
adefa5ce2a
20 changed files with 320 additions and 124 deletions
123
nvim/init.lua
123
nvim/init.lua
|
@ -1,4 +1,4 @@
|
|||
-- Bootstrap
|
||||
-- Install packer
|
||||
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
|
||||
local is_bootstrap = false
|
||||
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
|
||||
|
@ -7,8 +7,6 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
|
|||
vim.cmd [[packadd packer.nvim]]
|
||||
end
|
||||
|
||||
require('plugins.packer')
|
||||
|
||||
-- When we are bootstrapping a configuration, it doesn't
|
||||
-- make sense to execute the rest of the init.lua.
|
||||
--
|
||||
|
@ -22,14 +20,115 @@ if is_bootstrap then
|
|||
return
|
||||
end
|
||||
|
||||
-- General Configuration
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.tabstop = 2
|
||||
vim.opt.shiftwidth = 2
|
||||
vim.opt.expandtab = true
|
||||
-- Automatically source and re-compile packer whenever you save this init.lua
|
||||
local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true })
|
||||
vim.api.nvim_create_autocmd('BufWritePost', {
|
||||
command = 'source <afile> | PackerCompile',
|
||||
group = packer_group,
|
||||
pattern = vim.fn.expand '$MYVIMRC',
|
||||
})
|
||||
|
||||
vim.cmd('colorscheme base16-tomorrow-night-eighties')
|
||||
-- [[ Setting options ]]
|
||||
-- See `:help vim.o`
|
||||
|
||||
require('keybindings')
|
||||
-- Set highlight on search
|
||||
vim.o.hlsearch = false
|
||||
|
||||
-- Make line numbers default
|
||||
vim.wo.number = 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
|
||||
|
||||
-- Decrease update time
|
||||
vim.o.updatetime = 250
|
||||
vim.wo.signcolumn = 'yes'
|
||||
|
||||
-- Set colorscheme
|
||||
vim.o.termguicolors = true
|
||||
vim.cmd [[colorscheme base16-tomorrow-night-eighties]]
|
||||
|
||||
-- Set completeopt to have a better completion experience
|
||||
vim.o.completeopt = 'menuone,noselect'
|
||||
|
||||
-- [[ Basic Keymaps ]]
|
||||
-- Set <space> as the leader key
|
||||
-- See `:help mapleader`
|
||||
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
|
||||
vim.g.mapleader = ' '
|
||||
vim.g.maplocalleader = ' '
|
||||
|
||||
-- Keymaps for better default experience
|
||||
-- See `:help vim.keymap.set()`
|
||||
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
|
||||
|
||||
-- Remap for dealing with word wrap
|
||||
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
||||
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
||||
|
||||
-- Diagnostic keymaps
|
||||
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
|
||||
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
|
||||
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
|
||||
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
|
||||
|
||||
require('plugins')
|
||||
|
||||
-- LSP settings.
|
||||
-- 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', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
||||
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
|
||||
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||
|
||||
-- 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
|
||||
|
||||
-- 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)
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
vim.g.mapleader = ' '
|
||||
|
||||
vim.keymap.set('', '<Leader>ft', ':NvimTreeToggle<CR>')
|
||||
vim.keymap.set('', '<Leader>ff', ':NvimTreeFocus<CR>')
|
||||
|
||||
vim.keymap.set('n', '<Leader>bl', ':buffers<CR>')
|
41
nvim/lua/plugins/cmp.lua
Normal file
41
nvim/lua/plugins/cmp.lua
Normal file
|
@ -0,0 +1,41 @@
|
|||
local cmp = require 'cmp'
|
||||
local luasnip = require 'luasnip'
|
||||
|
||||
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(),
|
||||
['<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_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.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
},
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
||||
|
||||
require('cmp').setup({
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
}
|
||||
})
|
1
nvim/lua/plugins/comment.lua
Normal file
1
nvim/lua/plugins/comment.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require('Comment').setup()
|
|
@ -1 +0,0 @@
|
|||
local db = require('dashboard')
|
9
nvim/lua/plugins/gitsigns.lua
Normal file
9
nvim/lua/plugins/gitsigns.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
require('gitsigns').setup {
|
||||
signs = {
|
||||
add = { text = '+' },
|
||||
change = { text = '~' },
|
||||
delete = { text = '_' },
|
||||
topdelete = { text = '‾' },
|
||||
changedelete = { text = '~' },
|
||||
},
|
||||
}
|
4
nvim/lua/plugins/indent_blankline.lua
Normal file
4
nvim/lua/plugins/indent_blankline.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
require('indent_blankline').setup {
|
||||
char = '┊',
|
||||
show_trailing_blankline_indent = false,
|
||||
}
|
9
nvim/lua/plugins/init.lua
Normal file
9
nvim/lua/plugins/init.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
require('plugins.packer')
|
||||
require('plugins.lualine')
|
||||
require('plugins.comment')
|
||||
require('plugins.indent_blankline')
|
||||
require('plugins.gitsigns')
|
||||
require('plugins.treesitter')
|
||||
require('plugins.mason')
|
||||
require('plugins.fidget')
|
||||
require('plugins.cmp')
|
8
nvim/lua/plugins/lualine.lua
Normal file
8
nvim/lua/plugins/lualine.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
require('lualine').setup {
|
||||
options = {
|
||||
icons_enabled = false,
|
||||
theme = 'base16',
|
||||
component_separators = '|',
|
||||
section_separators = '',
|
||||
},
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
require('lualine').setup({
|
||||
options = {
|
||||
theme = 'base16',
|
||||
section_separators = { left = '', right = '' }
|
||||
},
|
||||
extensions = {'nvim-tree'}
|
||||
})
|
|
@ -1,12 +1,19 @@
|
|||
local mason_lspconfig = require 'mason-lspconfig'
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
||||
require('mason').setup()
|
||||
|
||||
local servers = {
|
||||
tsserver = {},
|
||||
|
||||
sumneko_lua = {
|
||||
Lua = {
|
||||
workspace = { checkThirdParty = false },
|
||||
telemetry = { enable = false },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Ensure the servers above are installed
|
||||
local mason_lspconfig = require 'mason-lspconfig'
|
||||
|
||||
mason_lspconfig.setup {
|
||||
ensure_installed = vim.tbl_keys(servers),
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
require("mason").setup()
|
|
@ -1,8 +0,0 @@
|
|||
require("nvim-tree").setup({
|
||||
open_on_setup = false,
|
||||
actions = {
|
||||
open_file = {
|
||||
quit_on_open = true,
|
||||
}
|
||||
}
|
||||
})
|
61
nvim/lua/plugins/packer.lua
Normal file
61
nvim/lua/plugins/packer.lua
Normal file
|
@ -0,0 +1,61 @@
|
|||
require('packer').startup(function(use)
|
||||
-- Package manager
|
||||
use 'wbthomason/packer.nvim'
|
||||
|
||||
use { -- LSP Configuration & Plugins
|
||||
'neovim/nvim-lspconfig',
|
||||
requires = {
|
||||
-- Automatically install LSPs to stdpath for neovim
|
||||
'williamboman/mason.nvim',
|
||||
'williamboman/mason-lspconfig.nvim',
|
||||
|
||||
-- Useful status updates for LSP
|
||||
'j-hui/fidget.nvim',
|
||||
|
||||
-- Additional lua configuration, makes nvim stuff amazing
|
||||
'folke/neodev.nvim',
|
||||
},
|
||||
}
|
||||
|
||||
use 'RRethy/nvim-base16'
|
||||
|
||||
use 'xiyaowong/nvim-transparent'
|
||||
|
||||
|
||||
|
||||
use { -- Autocompletion
|
||||
'hrsh7th/nvim-cmp',
|
||||
requires = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' },
|
||||
}
|
||||
|
||||
use { -- Highlight, edit, and navigate code
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
run = function()
|
||||
pcall(require('nvim-treesitter.install').update { with_sync = true })
|
||||
end,
|
||||
}
|
||||
|
||||
use { -- Additional text objects via treesitter
|
||||
'nvim-treesitter/nvim-treesitter-textobjects',
|
||||
after = 'nvim-treesitter',
|
||||
}
|
||||
|
||||
use { -- rainbow brackets using treesitter
|
||||
'p00f/nvim-ts-rainbow',
|
||||
after = 'nvim-treesitter'
|
||||
}
|
||||
|
||||
-- Git related plugins
|
||||
use 'tpope/vim-fugitive'
|
||||
use 'tpope/vim-rhubarb'
|
||||
use 'lewis6991/gitsigns.nvim'
|
||||
|
||||
use 'nvim-lualine/lualine.nvim' -- Fancier statusline
|
||||
use 'lukas-reineke/indent-blankline.nvim' -- Add indentation guides even on blank lines
|
||||
use 'numToStr/Comment.nvim' -- "gc" to comment visual regions/lines
|
||||
use 'tpope/vim-sleuth' -- Detect tabstop and shiftwidth automatically
|
||||
|
||||
if is_bootstrap then
|
||||
require('packer').sync()
|
||||
end
|
||||
end)
|
|
@ -1,62 +0,0 @@
|
|||
return require('packer').startup(function(use)
|
||||
use 'wbthomason/packer.nvim'
|
||||
use {
|
||||
'glepnir/dashboard-nvim',
|
||||
config = [[require('plugins.dashboard')]]
|
||||
}
|
||||
use {
|
||||
'nvim-lualine/lualine.nvim',
|
||||
requires = {
|
||||
'kyazdani42/nvim-web-devicons',
|
||||
'RRethy/nvim-base16'
|
||||
},
|
||||
config = [[require('plugins.lualine')]]
|
||||
}
|
||||
use {
|
||||
'xiyaowong/nvim-transparent',
|
||||
config = [[require('plugins.transparent')]]
|
||||
}
|
||||
use {
|
||||
'nvim-tree/nvim-tree.lua',
|
||||
requires = {
|
||||
'nvim-tree/nvim-web-devicons',
|
||||
},
|
||||
config = [[require('plugins.nvim-tree')]]
|
||||
}
|
||||
use {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
run = function()
|
||||
local ts_update = require('nvim-treesitter.install').update({ with_sync = true })
|
||||
ts_update()
|
||||
end,
|
||||
config = [[require('plugins.treesitter')]]
|
||||
}
|
||||
use 'p00f/nvim-ts-rainbow'
|
||||
use 'jiangmiao/auto-pairs'
|
||||
use {
|
||||
'williamboman/mason.nvim',
|
||||
requires = {
|
||||
'neovim/nvim-lspconfig',
|
||||
{
|
||||
'williamboman/mason-lspconfig.nvim',
|
||||
config = [[require('plugins.mason.lspconfig')]]
|
||||
},
|
||||
{
|
||||
'j-hui/fidget.nvim',
|
||||
config = [[require('plugins.fidget')]]
|
||||
}
|
||||
},
|
||||
config = [[require('plugins.mason')]]
|
||||
}
|
||||
use {
|
||||
'hrsh7th/nvim-cmp',
|
||||
requires = {
|
||||
'hrsh7th/cmp-nvim-lsp'
|
||||
},
|
||||
config = [[require('plugins.cmp')]]
|
||||
}
|
||||
|
||||
if is_bootstrap then
|
||||
require('packer').sync()
|
||||
end
|
||||
end)
|
|
@ -1,3 +0,0 @@
|
|||
require("transparent").setup({
|
||||
enable = true,
|
||||
})
|
65
nvim/lua/plugins/treesitter.lua
Normal file
65
nvim/lua/plugins/treesitter.lua
Normal file
|
@ -0,0 +1,65 @@
|
|||
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', 'typescript', 'help', 'javascript' },
|
||||
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true, disable = { 'python' } },
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
init_selection = '<c-space>',
|
||||
node_incremental = '<c-space>',
|
||||
scope_incremental = '<c-s>',
|
||||
node_decremental = '<c-backspace>',
|
||||
},
|
||||
},
|
||||
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',
|
||||
},
|
||||
},
|
||||
},
|
||||
rainbow = {
|
||||
enable = true,
|
||||
extended_mode = true,
|
||||
max_file_lines = nil,
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
require'nvim-treesitter.configs'.setup {
|
||||
ensure_installed = { "vim", "c", "lua", "kotlin", "javascript", "typescript" },
|
||||
highlight = {
|
||||
enable = true,
|
||||
additional_vim_regex_highlighting = false,
|
||||
},
|
||||
rainbow = {
|
||||
enable = true,
|
||||
extended_mode = true,
|
||||
max_file_lines = nil,
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue