mirror of
https://github.com/turtlebasket/env.git
synced 2026-03-04 19:44:26 -08:00
more nvim overhaul
This commit is contained in:
@@ -2,65 +2,54 @@
|
|||||||
-- git clone --filter=blob:none https://github.com/folke/lazy.nvim.git --branch=stable \
|
-- git clone --filter=blob:none https://github.com/folke/lazy.nvim.git --branch=stable \
|
||||||
-- ~/.local/share/nvim/lazy/lazy.nvim
|
-- ~/.local/share/nvim/lazy/lazy.nvim
|
||||||
|
|
||||||
-- NOTE: if vscode-neovim is active, exit early for stock behavior.
|
|
||||||
if vim.g.vscode then
|
if vim.g.vscode then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- aliases
|
|
||||||
local o = vim.o
|
|
||||||
local c = vim.cmd
|
|
||||||
local map = vim.api.nvim_set_keymap
|
|
||||||
|
|
||||||
-- leader keys
|
|
||||||
vim.g.mapleader = ' '
|
vim.g.mapleader = ' '
|
||||||
vim.g.maplocalleader = ' '
|
vim.g.maplocalleader = ' '
|
||||||
|
|
||||||
-- options
|
local opt = vim.opt
|
||||||
o.termguicolors = true
|
opt.termguicolors = true
|
||||||
o.mouse = 'a'
|
opt.mouse = 'a'
|
||||||
o.smartindent = true
|
opt.smartindent = true
|
||||||
o.wrap = false
|
opt.wrap = false
|
||||||
o.relativenumber = true
|
opt.relativenumber = true
|
||||||
o.tabstop = 4
|
opt.tabstop = 4
|
||||||
o.shiftwidth = 4
|
opt.shiftwidth = 4
|
||||||
o.expandtab = true
|
opt.expandtab = true
|
||||||
|
|
||||||
-- Prefer LSP semantic tokens over treesitter captures when both exist.
|
|
||||||
vim.hl.priorities.semantic_tokens = 140
|
vim.hl.priorities.semantic_tokens = 140
|
||||||
vim.hl.priorities.treesitter = 100
|
vim.hl.priorities.treesitter = 100
|
||||||
|
|
||||||
-- ensure .svelte files are detected correctly
|
vim.filetype.add({ extension = { svelte = 'svelte' } })
|
||||||
vim.filetype.add({
|
vim.api.nvim_create_autocmd('FileType', { pattern = 'markdown', command = 'setlocal wrap' })
|
||||||
extension = {
|
|
||||||
svelte = 'svelte',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
-- set wrap if markdown file
|
local function map(mode, lhs, rhs)
|
||||||
vim.cmd('autocmd FileType markdown setlocal wrap')
|
vim.keymap.set(mode, lhs, rhs, { silent = true })
|
||||||
|
end
|
||||||
|
|
||||||
-- keybinds
|
for _, m in ipairs({
|
||||||
map('n', '<c-b>', ':NvimTreeToggle<cr>', { silent = true })
|
{ 'n', '<c-b>', '<cmd>NvimTreeToggle<cr>' },
|
||||||
|
{ 'n', '<c-`>', '<cmd>ToggleTerm direction="float"<cr>' },
|
||||||
|
{ 't', '<c-`>', '<cmd>ToggleTerm<cr>' },
|
||||||
|
{ 'n', '<leader>gs', '<cmd>Telescope git_status<cr>' },
|
||||||
|
{ 'n', '<leader>gc', '<cmd>Telescope git_commits<cr>' },
|
||||||
|
{ 'n', '<leader>:', '<cmd>Telescope commands<cr>' },
|
||||||
|
{ 'n', '<leader><leader>', '<cmd>Telescope find_files<cr>' },
|
||||||
|
{ 'n', '<leader>f', '<cmd>Telescope grep_string<cr>' },
|
||||||
|
{ 'n', '<leader>b', '<cmd>Telescope buffers<cr>' },
|
||||||
|
{ 'n', 'B', '<cmd>Telescope buffers<cr>' },
|
||||||
|
{ 'n', '<leader>e', vim.diagnostic.open_float },
|
||||||
|
{ 'n', '\\', vim.lsp.buf.hover },
|
||||||
|
{ 'n', '<a-k>', '<cmd>GitGutterPrevHunk<cr>' },
|
||||||
|
{ 'n', '<a-j>', '<cmd>GitGutterNextHunk<cr>' },
|
||||||
|
{ 'n', '<c-h>', '<cmd>bp<cr>' },
|
||||||
|
{ 'n', '<c-l>', '<cmd>bn<cr>' },
|
||||||
|
}) do
|
||||||
|
map(m[1], m[2], m[3])
|
||||||
|
end
|
||||||
|
|
||||||
map('n', '<c-`>', ':ToggleTerm direction="float"<cr>', { silent = true })
|
|
||||||
map('t', '<c-`>', '<Cmd>:ToggleTerm<cr>', { silent = true })
|
|
||||||
|
|
||||||
map('n', '<leader>gs', ':Telescope git_status<cr>', { silent = true })
|
|
||||||
map('n', '<leader>gc', ':Telescope git_commits<cr>', { silent = true })
|
|
||||||
map('n', '<leader>:', ':Telescope commands<cr>', { silent = true })
|
|
||||||
map('n', '<leader><leader>', ':Telescope find_files<cr>', { silent = true })
|
|
||||||
map('n', '<leader>f', ':Telescope grep_string<cr>', { silent = true })
|
|
||||||
map('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<cr>', { silent = true })
|
|
||||||
|
|
||||||
map('n', '<a-k>', ':GitGutterPrevHunk<cr>', { silent = true })
|
|
||||||
map('n', '<a-j>', ':GitGutterNextHunk<cr>', { silent = true })
|
|
||||||
|
|
||||||
-- buffer management
|
|
||||||
map('n', '<c-h>', ':bp<cr>', { silent = true })
|
|
||||||
map('n', '<c-l>', ':bn<cr>', { silent = true })
|
|
||||||
|
|
||||||
-- lazy.nvim bootstrap
|
|
||||||
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
|
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
|
||||||
if not vim.loop.fs_stat(lazypath) then
|
if not vim.loop.fs_stat(lazypath) then
|
||||||
vim.fn.system({
|
vim.fn.system({
|
||||||
@@ -80,64 +69,61 @@ require('lazy').setup({
|
|||||||
name = 'vscode',
|
name = 'vscode',
|
||||||
priority = 1000,
|
priority = 1000,
|
||||||
lazy = false,
|
lazy = false,
|
||||||
config = function()
|
config = function() require('vscode').setup({ transparent = true }) end,
|
||||||
require('vscode').setup({
|
|
||||||
transparent = true,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
{ 'airblade/vim-gitgutter' },
|
{ 'airblade/vim-gitgutter' },
|
||||||
{
|
{
|
||||||
'nvim-lualine/lualine.nvim',
|
'nvim-lualine/lualine.nvim',
|
||||||
dependencies = { 'nvim-tree/nvim-web-devicons' },
|
dependencies = { 'nvim-tree/nvim-web-devicons' },
|
||||||
config = function()
|
config = function() require('lualine').setup({ options = { theme = 'vscode', globalstatus = true } }) end,
|
||||||
require('lualine').setup({
|
|
||||||
options = {
|
|
||||||
theme = 'vscode',
|
|
||||||
globalstatus = true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'nvim-treesitter/nvim-treesitter',
|
'nvim-treesitter/nvim-treesitter',
|
||||||
build = ':TSUpdate',
|
build = ':TSUpdate',
|
||||||
config = function()
|
config = function()
|
||||||
local treesitter = require('nvim-treesitter')
|
|
||||||
local wanted = { 'svelte', 'javascript', 'typescript', 'html', 'css' }
|
local wanted = { 'svelte', 'javascript', 'typescript', 'html', 'css' }
|
||||||
treesitter.setup({})
|
local ts_runtime = vim.fn.stdpath('data') .. '/lazy/nvim-treesitter/runtime'
|
||||||
|
if vim.loop.fs_stat(ts_runtime) then
|
||||||
|
vim.opt.rtp:append(ts_runtime)
|
||||||
|
end
|
||||||
|
require('nvim-treesitter').setup({ install_dir = vim.fn.stdpath('data') .. '/site' })
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd('FileType', {
|
vim.api.nvim_create_autocmd('FileType', {
|
||||||
pattern = wanted,
|
pattern = wanted,
|
||||||
callback = function()
|
callback = function() pcall(vim.treesitter.start) end,
|
||||||
pcall(vim.treesitter.start)
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
config = function()
|
config = function()
|
||||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
local capabilities = vim.tbl_deep_extend(
|
||||||
|
'force',
|
||||||
|
vim.lsp.protocol.make_client_capabilities(),
|
||||||
|
require('cmp_nvim_lsp').default_capabilities()
|
||||||
|
)
|
||||||
|
|
||||||
vim.lsp.config('pyright', { capabilities = capabilities })
|
local function on_attach(client, bufnr)
|
||||||
vim.lsp.config('ts_ls', { capabilities = capabilities })
|
if client.server_capabilities.semanticTokensProvider then
|
||||||
vim.lsp.config('svelte', { capabilities = capabilities })
|
vim.lsp.semantic_tokens.start(bufnr, client.id)
|
||||||
vim.lsp.config('rust_analyzer', { capabilities = capabilities })
|
end
|
||||||
|
end
|
||||||
vim.lsp.enable('pyright')
|
|
||||||
vim.lsp.enable('ts_ls')
|
local defaults = {
|
||||||
vim.lsp.enable('svelte')
|
capabilities = capabilities,
|
||||||
vim.lsp.enable('rust_analyzer')
|
on_attach = on_attach,
|
||||||
|
}
|
||||||
vim.api.nvim_create_autocmd('LspAttach', {
|
local servers = {
|
||||||
callback = function(args)
|
basedpyright = {},
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
ts_ls = {},
|
||||||
if client and client.server_capabilities.semanticTokensProvider then
|
svelte = {},
|
||||||
vim.lsp.semantic_tokens.start(args.buf, client.id)
|
rust_analyzer = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
for server, opts in pairs(servers) do
|
||||||
|
vim.lsp.config(server, vim.tbl_deep_extend('force', defaults, opts))
|
||||||
|
vim.lsp.enable(server)
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{ 'hrsh7th/cmp-nvim-lsp' },
|
{ 'hrsh7th/cmp-nvim-lsp' },
|
||||||
@@ -147,35 +133,69 @@ require('lazy').setup({
|
|||||||
config = function()
|
config = function()
|
||||||
local cmp = require('cmp')
|
local cmp = require('cmp')
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
sources = {
|
mapping = {
|
||||||
{ name = 'nvim_lsp' },
|
['<C-n>'] = cmp.mapping(function()
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
|
||||||
|
else
|
||||||
|
cmp.complete()
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
['<C-p>'] = cmp.mapping(function()
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
['<CR>'] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.confirm({ select = true })
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
},
|
},
|
||||||
|
sources = { { name = 'nvim_lsp' } },
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'nvim-tree/nvim-tree.lua',
|
'nvim-tree/nvim-tree.lua',
|
||||||
dependencies = { 'nvim-tree/nvim-web-devicons' },
|
dependencies = { 'nvim-tree/nvim-web-devicons' },
|
||||||
config = function()
|
config = function() require('nvim-tree').setup({ view = { width = 42 } }) end,
|
||||||
require('nvim-tree').setup({ view = { width = 42 } })
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'nvim-telescope/telescope.nvim',
|
'nvim-telescope/telescope.nvim',
|
||||||
dependencies = { 'nvim-lua/plenary.nvim' },
|
dependencies = { 'nvim-lua/plenary.nvim', 'nvim-telescope/telescope-fzf-native.nvim' },
|
||||||
|
config = function()
|
||||||
|
local actions = require('telescope.actions')
|
||||||
|
require('telescope').setup({
|
||||||
|
defaults = {
|
||||||
|
mappings = {
|
||||||
|
i = {
|
||||||
|
['<Esc>'] = actions.close,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extensions = {
|
||||||
|
fzf = {
|
||||||
|
fuzzy = true,
|
||||||
|
override_generic_sorter = true,
|
||||||
|
override_file_sorter = true,
|
||||||
|
case_mode = 'smart_case',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require('telescope').load_extension('fzf')
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{ 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' },
|
||||||
{
|
{
|
||||||
'akinsho/toggleterm.nvim',
|
'akinsho/toggleterm.nvim',
|
||||||
version = '*',
|
version = '*',
|
||||||
config = function()
|
config = function() require('toggleterm').setup() end,
|
||||||
require('toggleterm').setup()
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- NOTE: pcall prevents plugin system errors on first load
|
if not pcall(vim.cmd.colorscheme, 'vscode') then
|
||||||
if not pcall(function()
|
|
||||||
c.colorscheme('vscode')
|
|
||||||
end) then
|
|
||||||
print('Failed to load colorscheme - probably has not been installed')
|
print('Failed to load colorscheme - probably has not been installed')
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"nvim-treesitter": { "branch": "main", "commit": "3edb01f912867603c2aef9079f208f0244c0885b" },
|
"nvim-treesitter": { "branch": "main", "commit": "3edb01f912867603c2aef9079f208f0244c0885b" },
|
||||||
"nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" },
|
"nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" },
|
||||||
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
||||||
|
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" },
|
||||||
"telescope.nvim": { "branch": "master", "commit": "5255aa27c422de944791318024167ad5d40aad20" },
|
"telescope.nvim": { "branch": "master", "commit": "5255aa27c422de944791318024167ad5d40aad20" },
|
||||||
"toggleterm.nvim": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" },
|
"toggleterm.nvim": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" },
|
||||||
"vim-gitgutter": { "branch": "main", "commit": "0acb772e76064cc406664ab595b58b3fac76488a" },
|
"vim-gitgutter": { "branch": "main", "commit": "0acb772e76064cc406664ab595b58b3fac76488a" },
|
||||||
|
|||||||
Reference in New Issue
Block a user