mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-16 21:54:04 +00:00
feat(nvim): another configuration tweak round
added snippets!
This commit is contained in:
9
config/nvim/lua/plugins/comment.lua
Normal file
9
config/nvim/lua/plugins/comment.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-- Commenting
|
||||||
|
-- "gc" to comment visual regions/lines
|
||||||
|
-- https://github.com/numToStr/Comment.nvim
|
||||||
|
return {
|
||||||
|
'numToStr/Comment.nvim',
|
||||||
|
version = '*',
|
||||||
|
event = { 'BufRead', 'BufNewFile' },
|
||||||
|
opts = {},
|
||||||
|
}
|
||||||
84
config/nvim/lua/plugins/conform.lua
Normal file
84
config/nvim/lua/plugins/conform.lua
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
-- ── Formatting ──────────────────────────────────────────────────────
|
||||||
|
-- Lightweight yet powerful formatter plugin for Neovim
|
||||||
|
-- https://github.com/stevearc/conform.nvim
|
||||||
|
return {
|
||||||
|
'stevearc/conform.nvim',
|
||||||
|
event = { 'BufWritePre' },
|
||||||
|
cmd = { 'ConformInfo' },
|
||||||
|
config = function()
|
||||||
|
-- Select first conform formatter that is available
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param ... string
|
||||||
|
---@return string
|
||||||
|
local function first(bufnr, ...)
|
||||||
|
local conform = require 'conform'
|
||||||
|
for i = 1, select('#', ...) do
|
||||||
|
local formatter = select(i, ...)
|
||||||
|
if conform.get_formatter_info(formatter, bufnr).available then
|
||||||
|
return formatter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return select(1, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
require('conform').setup {
|
||||||
|
-- Enable or disable logging
|
||||||
|
notify_on_error = true,
|
||||||
|
-- Set the default formatter for all filetypes
|
||||||
|
default_formatter = 'injected',
|
||||||
|
-- Set the default formatter for all filetypes
|
||||||
|
default_formatter_opts = {
|
||||||
|
lsp_format = 'fallback',
|
||||||
|
-- Set the default formatter for all filetypes
|
||||||
|
-- formatter = 'injected',
|
||||||
|
-- Set the default formatter for all filetypes
|
||||||
|
-- formatter_opts = {},
|
||||||
|
},
|
||||||
|
formatters_by_ft = {
|
||||||
|
markdown = function(bufnr)
|
||||||
|
return { first(bufnr, 'prettierd', 'prettier'), 'injected' }
|
||||||
|
end,
|
||||||
|
javascript = function(bufnr)
|
||||||
|
return { first(bufnr, 'prettier', 'eslint'), 'injected' }
|
||||||
|
end,
|
||||||
|
lua = { 'stylua' },
|
||||||
|
-- Conform will run multiple formatters sequentially
|
||||||
|
-- python = { 'isort', 'black', lsp_format = 'fallback' },
|
||||||
|
-- You can customize some of the format options for the filetype (:help conform.format)
|
||||||
|
-- rust = { 'rustfmt', lsp_format = 'fallback' },
|
||||||
|
},
|
||||||
|
format_on_save = function(bufnr)
|
||||||
|
-- Disable autoformat on certain filetypes
|
||||||
|
local ignore_filetypes = {
|
||||||
|
'c',
|
||||||
|
'cpp',
|
||||||
|
'sql',
|
||||||
|
'java',
|
||||||
|
}
|
||||||
|
if vim.tbl_contains(ignore_filetypes, vim.bo[bufnr].filetype) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- Disable with a global or buffer-local variable
|
||||||
|
if
|
||||||
|
vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat
|
||||||
|
then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- Disable autoformat for files in a certain path
|
||||||
|
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||||
|
if bufname:match '/node_modules/' then return end
|
||||||
|
if bufname:match '/vendor/' then return end
|
||||||
|
if bufname:match '/dist/' then return end
|
||||||
|
if bufname:match '/build/' then return end
|
||||||
|
|
||||||
|
return { timeout_ms = 500, lsp_format = 'fallback' }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
init = function()
|
||||||
|
-- If you want the formatexpr, here is the place to set it
|
||||||
|
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
||||||
|
end,
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
39
config/nvim/lua/plugins/flash.lua
Normal file
39
config/nvim/lua/plugins/flash.lua
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
return {
|
||||||
|
'folke/flash.nvim',
|
||||||
|
event = 'VeryLazy',
|
||||||
|
opts = {},
|
||||||
|
keys = {
|
||||||
|
{
|
||||||
|
'zk',
|
||||||
|
mode = { 'n', 'x', 'o' },
|
||||||
|
function() require('flash').jump() end,
|
||||||
|
desc = 'Flash',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'Zk',
|
||||||
|
mode = { 'n', 'x', 'o' },
|
||||||
|
function() require('flash').treesitter() end,
|
||||||
|
desc = 'Flash Treesitter',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'r',
|
||||||
|
mode = 'o',
|
||||||
|
function() require('flash').remote() end,
|
||||||
|
desc = 'Remote Flash',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'R',
|
||||||
|
mode = { 'o', 'x' },
|
||||||
|
function() require('flash').treesitter_search() end,
|
||||||
|
desc = 'Treesitter Search',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'<m-s>',
|
||||||
|
mode = { 'c' },
|
||||||
|
function() require('flash').toggle() end,
|
||||||
|
desc = 'Toggle Flash Search',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- vim: ts=2 sts=2 sw=2 et
|
||||||
47
config/nvim/lua/plugins/harpoon.lua
Normal file
47
config/nvim/lua/plugins/harpoon.lua
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
-- Getting you where you want with the fewest keystrokes.
|
||||||
|
-- https://github.com/ThePrimeagen/harpoon
|
||||||
|
return {
|
||||||
|
'ThePrimeagen/harpoon',
|
||||||
|
branch = 'harpoon2',
|
||||||
|
dependencies = {
|
||||||
|
'nvim-lua/plenary.nvim',
|
||||||
|
'nvim-telescope/telescope.nvim',
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
local harpoon = require 'harpoon'
|
||||||
|
harpoon:setup {}
|
||||||
|
|
||||||
|
-- basic telescope configuration
|
||||||
|
local conf = require('telescope.config').values
|
||||||
|
local function toggle_telescope(harpoon_files)
|
||||||
|
local file_paths = {}
|
||||||
|
for _, item in ipairs(harpoon_files.items) do
|
||||||
|
table.insert(file_paths, item.value)
|
||||||
|
end
|
||||||
|
|
||||||
|
require('telescope.pickers')
|
||||||
|
.new({}, {
|
||||||
|
prompt_title = 'Harpoon',
|
||||||
|
finder = require('telescope.finders').new_table {
|
||||||
|
results = file_paths,
|
||||||
|
},
|
||||||
|
previewer = conf.file_previewer {},
|
||||||
|
sorter = conf.generic_sorter {},
|
||||||
|
})
|
||||||
|
:find()
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set(
|
||||||
|
'n',
|
||||||
|
'<leader>hw',
|
||||||
|
function() toggle_telescope(harpoon:list()) end,
|
||||||
|
{ desc = 'Open harpoon window with telescope' }
|
||||||
|
)
|
||||||
|
vim.keymap.set(
|
||||||
|
'n',
|
||||||
|
'<leader>ht',
|
||||||
|
function() harpoon.ui:toggle_quick_menu(harpoon:list()) end,
|
||||||
|
{ desc = 'Open Harpoon Quick menu' }
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
}
|
||||||
21
config/nvim/lua/plugins/lsp-saga.lua
Normal file
21
config/nvim/lua/plugins/lsp-saga.lua
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
-- improve neovim lsp experience
|
||||||
|
-- https://github.com/nvimdev/lspsaga.nvim
|
||||||
|
-- https://nvimdev.github.io/lspsaga/
|
||||||
|
return {
|
||||||
|
'nvimdev/lspsaga.nvim',
|
||||||
|
event = 'LspAttach',
|
||||||
|
dependencies = {
|
||||||
|
'nvim-treesitter/nvim-treesitter', -- optional
|
||||||
|
'nvim-tree/nvim-web-devicons', -- optional
|
||||||
|
},
|
||||||
|
opts = {
|
||||||
|
code_action = {
|
||||||
|
show_server_name = true,
|
||||||
|
},
|
||||||
|
diagnostic = {
|
||||||
|
keys = {
|
||||||
|
quit = { 'q', '<ESC>' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
8
config/nvim/lua/plugins/neogen.lua
Normal file
8
config/nvim/lua/plugins/neogen.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
-- A better annotation generator.
|
||||||
|
-- Supports multiple languages and annotation conventions.
|
||||||
|
-- https://github.com/danymat/neogen
|
||||||
|
return {
|
||||||
|
'danymat/neogen',
|
||||||
|
version = '*',
|
||||||
|
opts = { enabled = true, snippet_engine = 'luasnip' },
|
||||||
|
}
|
||||||
8
config/nvim/lua/plugins/refactoring.lua
Normal file
8
config/nvim/lua/plugins/refactoring.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
-- The Refactoring library based off the Refactoring book by Martin Fowler
|
||||||
|
-- https://github.com/ThePrimeagen/refactoring.nvim
|
||||||
|
return {
|
||||||
|
'ThePrimeagen/refactoring.nvim',
|
||||||
|
version = '*',
|
||||||
|
dependencies = { 'nvim-lua/plenary.nvim', 'nvim-treesitter/nvim-treesitter' },
|
||||||
|
opts = {},
|
||||||
|
}
|
||||||
8
config/nvim/lua/plugins/surround.lua
Normal file
8
config/nvim/lua/plugins/surround.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
-- Add/change/delete surrounding delimiter pairs with ease.
|
||||||
|
-- https://github.com/kylechui/nvim-surround
|
||||||
|
return {
|
||||||
|
'kylechui/nvim-surround',
|
||||||
|
version = '*',
|
||||||
|
event = 'VeryLazy',
|
||||||
|
opts = {},
|
||||||
|
}
|
||||||
8
config/nvim/lua/plugins/todo-comments.lua
Normal file
8
config/nvim/lua/plugins/todo-comments.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
-- Highlight, list and search todo comments in your projects
|
||||||
|
-- https://github.com/folke/todo-comments.nvim
|
||||||
|
return {
|
||||||
|
'folke/todo-comments.nvim',
|
||||||
|
version = '*',
|
||||||
|
dependencies = { 'nvim-lua/plenary.nvim' },
|
||||||
|
opts = {},
|
||||||
|
}
|
||||||
9
config/nvim/lua/plugins/treesj.lua
Normal file
9
config/nvim/lua/plugins/treesj.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-- Neovim plugin for splitting/joining blocks of code
|
||||||
|
-- https://github.com/Wansmer/treesj
|
||||||
|
return {
|
||||||
|
'Wansmer/treesj',
|
||||||
|
dependencies = { 'nvim-treesitter/nvim-treesitter' },
|
||||||
|
opts = {
|
||||||
|
use_default_keymaps = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
116
config/nvim/lua/plugins/ufo.lua
Normal file
116
config/nvim/lua/plugins/ufo.lua
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
-- Not UFO in the sky, but an ultra fold in Neovim.
|
||||||
|
-- https://github.com/kevinhwang91/nvim-ufo/
|
||||||
|
return {
|
||||||
|
'kevinhwang91/nvim-ufo',
|
||||||
|
version = '*',
|
||||||
|
dependencies = {
|
||||||
|
{ 'neovim/nvim-lspconfig' },
|
||||||
|
{ 'kevinhwang91/promise-async' },
|
||||||
|
{ 'nvim-treesitter/nvim-treesitter' },
|
||||||
|
{
|
||||||
|
-- Status column plugin that provides a configurable
|
||||||
|
-- 'statuscolumn' and click handlers.
|
||||||
|
-- https://github.com/luukvbaal/statuscol.nvim
|
||||||
|
'luukvbaal/statuscol.nvim',
|
||||||
|
config = function()
|
||||||
|
local builtin = require 'statuscol.builtin'
|
||||||
|
require('statuscol').setup {
|
||||||
|
relculright = true,
|
||||||
|
segments = {
|
||||||
|
{
|
||||||
|
text = { builtin.foldfunc },
|
||||||
|
click = 'v:lua.ScFa',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sign = {
|
||||||
|
namespace = { 'diagnostic/signs' },
|
||||||
|
maxwidth = 2,
|
||||||
|
-- auto = true,
|
||||||
|
},
|
||||||
|
click = 'v:lua.ScSa',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text = { builtin.lnumfunc, ' ' },
|
||||||
|
click = 'v:lua.ScLa',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
capabilities.textDocument.foldingRange = {
|
||||||
|
dynamicRegistration = false,
|
||||||
|
lineFoldingOnly = true,
|
||||||
|
}
|
||||||
|
local language_servers = require('lspconfig').util.available_servers() -- or list servers manually like {'gopls', 'clangd'}
|
||||||
|
for _, ls in ipairs(language_servers) do
|
||||||
|
require('lspconfig')[ls].setup {
|
||||||
|
capabilities = capabilities,
|
||||||
|
-- you can add other fields for setting up lsp server in this table
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
require('ufo').setup {
|
||||||
|
open_fold_hl_timeout = 150,
|
||||||
|
close_fold_kinds_for_ft = { 'imports', 'comment' },
|
||||||
|
preview = {
|
||||||
|
win_config = {
|
||||||
|
border = { '', '─', '', '', '', '─', '', '' },
|
||||||
|
winhighlight = 'Normal:Folded',
|
||||||
|
winblend = 0,
|
||||||
|
},
|
||||||
|
mappings = {
|
||||||
|
scrollU = '<C-u>',
|
||||||
|
scrollD = '<C-d>',
|
||||||
|
jumpTop = '[',
|
||||||
|
jumpBot = ']',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
provider_selector = function(_, _, _) -- bufnr, filetype, buftype
|
||||||
|
return { 'treesitter', 'indent' }
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- fold_virt_text_handler
|
||||||
|
--
|
||||||
|
-- This handler is called when the fold text is too long to fit in the window.
|
||||||
|
-- It is expected to truncate the text and return a new list of virtual text.
|
||||||
|
--
|
||||||
|
---@param virtText table The current virtual text list.
|
||||||
|
---@param lnum number The line number of the first line in the fold.
|
||||||
|
---@param endLnum number The line number of the last line in the fold.
|
||||||
|
---@param width number The width of the window.
|
||||||
|
---@param truncate function Truncate function
|
||||||
|
---@return table
|
||||||
|
fold_virt_text_handler = function(virtText, lnum, endLnum, width, truncate)
|
||||||
|
local newVirtText = {}
|
||||||
|
local suffix = (' %d '):format(endLnum - lnum)
|
||||||
|
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
||||||
|
local targetWidth = width - sufWidth
|
||||||
|
local curWidth = 0
|
||||||
|
for _, chunk in ipairs(virtText) do
|
||||||
|
local chunkText = chunk[1]
|
||||||
|
local chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
||||||
|
if targetWidth > curWidth + chunkWidth then
|
||||||
|
table.insert(newVirtText, chunk)
|
||||||
|
else
|
||||||
|
chunkText = truncate(chunkText, targetWidth - curWidth)
|
||||||
|
local hlGroup = chunk[2]
|
||||||
|
table.insert(newVirtText, { chunkText, hlGroup })
|
||||||
|
chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
||||||
|
-- str width returned from truncate() may less than 2nd argument, need padding
|
||||||
|
if curWidth + chunkWidth < targetWidth then
|
||||||
|
suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth)
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
curWidth = curWidth + chunkWidth
|
||||||
|
end
|
||||||
|
table.insert(newVirtText, { suffix, 'MoreMsg' })
|
||||||
|
return newVirtText
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
3
config/nvim/lua/plugins/vim-sleuth.lua
Normal file
3
config/nvim/lua/plugins/vim-sleuth.lua
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
-- Detect tabstop and shiftwidth automatically
|
||||||
|
-- https://github.com/tpope/vim-sleuth
|
||||||
|
return { 'tpope/vim-sleuth' }
|
||||||
Reference in New Issue
Block a user