Made neovim config far simpler
This commit is contained in:
parent
3b994adf6d
commit
7ed897230b
16 changed files with 59 additions and 402 deletions
134
nvim/init.lua
134
nvim/init.lua
|
@ -1,16 +1,26 @@
|
|||
-- Install packer
|
||||
-- install packer if not already there
|
||||
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
|
||||
is_bootstrap = true
|
||||
vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }
|
||||
vim.fn.system{'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }
|
||||
vim.cmd [[packadd packer.nvim]]
|
||||
end
|
||||
|
||||
-- When we are bootstrapping a configuration, it doesn't
|
||||
-- make sense to execute the rest of the init.lua.
|
||||
--
|
||||
-- You'll need to restart nvim, and then it will work.
|
||||
-- Install Plugins
|
||||
require('packer').startup(function(use)
|
||||
use 'wbthomason/packer.nvim'
|
||||
use 'neovim/nvim-lspconfig'
|
||||
use 'nvim-treesitter/nvim-treesitter'
|
||||
use {
|
||||
'hrsh7th/nvim-cmp',
|
||||
requires = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua' }
|
||||
}
|
||||
if is_bootstrap then
|
||||
require('packer').sync()
|
||||
end
|
||||
end)
|
||||
|
||||
-- Don't run additional config if installing packer
|
||||
if is_bootstrap then
|
||||
print '=================================='
|
||||
print ' Plugins are being installed'
|
||||
|
@ -20,81 +30,53 @@ if is_bootstrap then
|
|||
return
|
||||
end
|
||||
|
||||
-- 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',
|
||||
})
|
||||
|
||||
-- [[ Setting options ]]
|
||||
-- See `:help vim.o`
|
||||
|
||||
-- Set highlight on search
|
||||
vim.o.hlsearch = false
|
||||
|
||||
-- Make line numbers default
|
||||
-- Some basic settings
|
||||
vim.wo.number = true
|
||||
vim.wo.relativenumber = true
|
||||
|
||||
-- Enable mouse mode
|
||||
vim.o.mouse = 'a'
|
||||
-- Additional keybinds if lsp running
|
||||
local on_attach = function(client, bufnr)
|
||||
local bufopts = { noremap=true, silent=true, buffer=bufnr }
|
||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
|
||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
|
||||
end
|
||||
|
||||
-- Enable break indent
|
||||
vim.o.breakindent = true
|
||||
local lsp_flags = {
|
||||
|
||||
-- Save undo history
|
||||
vim.o.undofile = true
|
||||
}
|
||||
|
||||
-- Case insensitive searching UNLESS /C or capital in search
|
||||
vim.o.ignorecase = true
|
||||
vim.o.smartcase = true
|
||||
-- lsp configs
|
||||
require('lspconfig')['tsserver'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags
|
||||
}
|
||||
|
||||
-- Decrease update time
|
||||
vim.o.updatetime = 250
|
||||
vim.wo.signcolumn = 'yes'
|
||||
require('lspconfig')['lua_ls'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags
|
||||
}
|
||||
|
||||
-- Set colorscheme
|
||||
vim.o.termguicolors = true
|
||||
vim.cmd [[colorscheme base16-tomorrow-night-eighties]]
|
||||
require('lspconfig')['gopls'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags
|
||||
}
|
||||
|
||||
-- Set completeopt to have a better completion experience
|
||||
vim.o.completeopt = 'menuone,noselect'
|
||||
-- TreeSitter Config
|
||||
require('nvim-treesitter.configs').setup{
|
||||
ensure_installed = {'go', 'vim', 'typescript', 'help', 'lua', 'javascript', 'python'},
|
||||
highlight = {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
|
||||
vim.g.loaded_netrw = 1
|
||||
|
||||
-- [[ 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)
|
||||
|
||||
local api = require("nvim-tree.api")
|
||||
vim.keymap.set('n', '<leader>ft', api.tree.toggle)
|
||||
|
||||
require('plugins')
|
||||
|
||||
-- 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)
|
||||
|
||||
-- disable some stock plugins
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
-- autocompletion
|
||||
local cmp = require 'cmp'
|
||||
cmp.setup {
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'buffer' },
|
||||
{ name = 'cmdline' },
|
||||
{ name = 'path' },
|
||||
{ name = 'nvim-lua' }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
require("autoclose").setup({})
|
|
@ -1,41 +0,0 @@
|
|||
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 +0,0 @@
|
|||
require('Comment').setup()
|
|
@ -1 +0,0 @@
|
|||
local db = require('dashboard')
|
|
@ -1 +0,0 @@
|
|||
require('fidget').setup()
|
|
@ -1,9 +0,0 @@
|
|||
require('gitsigns').setup {
|
||||
signs = {
|
||||
add = { text = '+' },
|
||||
change = { text = '~' },
|
||||
delete = { text = '_' },
|
||||
topdelete = { text = '‾' },
|
||||
changedelete = { text = '~' },
|
||||
},
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
require('indent_blankline').setup {
|
||||
char = '┊',
|
||||
show_trailing_blankline_indent = false,
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
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')
|
||||
require('plugins.nvim-tree')
|
||||
require('plugins.toggleterm')
|
||||
require('plugins.dashboard')
|
||||
require('plugins.autoclose')
|
||||
require('plugins.jabs')
|
|
@ -1 +0,0 @@
|
|||
require 'jabs'.setup {}
|
|
@ -1,8 +0,0 @@
|
|||
require('lualine').setup {
|
||||
options = {
|
||||
icons_enabled = false,
|
||||
theme = 'base16',
|
||||
component_separators = '|',
|
||||
section_separators = '',
|
||||
},
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
require('mason').setup()
|
||||
|
||||
-- LSP settings.
|
||||
-- This function gets run when an LSP connects to a particular buffer.
|
||||
--vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename)
|
||||
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>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||
|
||||
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
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
mason_lspconfig.setup_handlers {
|
||||
function(server_name)
|
||||
require('lspconfig')[server_name].setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
settings = servers[server_name],
|
||||
}
|
||||
end,
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
require("nvim-tree").setup({
|
||||
filters = {
|
||||
dotfiles = true,
|
||||
},
|
||||
})
|
|
@ -1,77 +0,0 @@
|
|||
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 'm4xshen/autoclose.nvim'
|
||||
|
||||
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 {
|
||||
'nvim-tree/nvim-tree.lua',
|
||||
requires = {
|
||||
'nvim-tree/nvim-web-devicons', -- optional, for file icons
|
||||
},
|
||||
}
|
||||
|
||||
use {
|
||||
'akinsho/toggleterm.nvim'
|
||||
}
|
||||
|
||||
use { -- rainbow brackets using treesitter
|
||||
'p00f/nvim-ts-rainbow',
|
||||
after = 'nvim-treesitter'
|
||||
}
|
||||
|
||||
use {
|
||||
'glepnir/dashboard-nvim'
|
||||
}
|
||||
|
||||
-- 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
|
||||
use 'matbme/JABS.nvim'
|
||||
|
||||
if is_bootstrap then
|
||||
require('packer').sync()
|
||||
end
|
||||
end)
|
|
@ -1,25 +0,0 @@
|
|||
require("toggleterm").setup({
|
||||
direction = 'horizontal'
|
||||
})
|
||||
|
||||
function _G.set_terminal_keymaps()
|
||||
local opts = {buffer = 0}
|
||||
vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
|
||||
vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
|
||||
vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
|
||||
vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
|
||||
vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
|
||||
vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
|
||||
end
|
||||
|
||||
vim.cmd "autocmd! TermOpen term://* lua set_terminal_keymaps()"
|
||||
local Terminal = require("toggleterm.terminal").Terminal
|
||||
local lazygit = Terminal:new { cmd = 'lazygit', hidden = true, direction = 'float' }
|
||||
|
||||
|
||||
function _LAZYGIT_TOGGLE()
|
||||
lazygit:toggle()
|
||||
end
|
||||
|
||||
vim.keymap.set('n', '<leader>tg', _LAZYGIT_TOGGLE)
|
||||
vim.keymap.set('n', '<leader>tt', '<Cmd>ToggleTerm<Cr>', {silent = true})
|
|
@ -1,65 +0,0 @@
|
|||
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,
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue