Skip to content

Commit

Permalink
feat(nvim): migrate to lazy plugin manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kutsan committed Apr 18, 2024
1 parent 5070ef3 commit 47cf395
Show file tree
Hide file tree
Showing 51 changed files with 1,092 additions and 864 deletions.
2 changes: 1 addition & 1 deletion .config/nvim/after/ftplugin/gitcommit.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
local set_undo_ftplugin = require('kutsan/utils').set_undo_ftplugin
local set_undo_ftplugin = require('user/utils').set_undo_ftplugin

set_undo_ftplugin('setlocal spell<')
2 changes: 1 addition & 1 deletion .config/nvim/after/ftplugin/ledger.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
local set_undo_ftplugin = require('kutsan/utils').set_undo_ftplugin
local set_undo_ftplugin = require('user/utils').set_undo_ftplugin

set_undo_ftplugin('setlocal commentstring<')
2 changes: 1 addition & 1 deletion .config/nvim/after/ftplugin/markdown.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local set_undo_ftplugin = require('kutsan/utils').set_undo_ftplugin
local set_undo_ftplugin = require('user/utils').set_undo_ftplugin

set_undo_ftplugin(
'setlocal number< relativenumber<' .. " | execute 'nunmap <buffer> \\r'"
Expand Down
2 changes: 1 addition & 1 deletion .config/nvim/after/ftplugin/qf.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
local set_undo_ftplugin = require('kutsan/utils').set_undo_ftplugin
local set_undo_ftplugin = require('user/utils').set_undo_ftplugin

set_undo_ftplugin('setlocal statusline<')
3 changes: 0 additions & 3 deletions .config/nvim/after/plugin/packages/colorizer.lua

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""
" Jump to last known position after reading a buffer.
"
" autocmd BufReadPost *? call kutsan#autocmds#jumplast#()
" autocmd BufReadPost *? call user#autocmds#jumplast#()
""
function! kutsan#autocmds#jumplast#() abort
function! user#autocmds#jumplast#() abort
if empty(&buftype) && index(['diff', 'gitcommit'], &filetype, 0, v:true) == -1
if line("'\"") >= 1 && line("'\"") <= line('$')
execute 'normal! g`"'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""
" Save the current buffer while keeping marks.
"
" autocmd InsertLeave,TextChanged * call kutsan#autocmds#savebuffer#()
" autocmd InsertLeave,TextChanged * call user#autocmds#savebuffer#()
""
function! kutsan#autocmds#savebuffer#() abort
function! user#autocmds#savebuffer#() abort
if empty(&buftype)
\ && !empty(bufname(''))
\ && &filetype !=# 'gitcommit'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""
" Trim trailing whitespace characters from end of each line.
"
" autocmd BufWritePre * call kutsan#autocmds#trimtrailing#()
" autocmd BufWritePre * call user#autocmds#trimtrailing#()
""
function! kutsan#autocmds#trimtrailing#() abort
function! user#autocmds#trimtrailing#() abort
if &l:modifiable && !&l:binary
let l:view = winsaveview()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
""
" Allow indented text blocks to be treated as text objects.
"
" onoremap <silent> ii :<C-u>call kutsan#mappings#motion#indent#({ 'mode': 'i' })<CR>
" xnoremap <silent> ii :<C-u>call kutsan#mappings#motion#indent#({ 'mode': 'i' })<CR>
" onoremap <silent> ai :<C-u>call kutsan#mappings#motion#indent#({ 'mode': 'a' })<CR>
" xnoremap <silent> ai :<C-u>call kutsan#mappings#motion#indent#({ 'mode': 'a' })<CR>
" onoremap <silent> io :<C-u>call kutsan#mappings#motion#indent#({ 'mode': 'o' })<CR>
" xnoremap <silent> io :<C-u>call kutsan#mappings#motion#indent#({ 'mode': 'o' })<CR>
" onoremap <silent> ii :<C-u>call user#mappings#motion#indent#({ 'mode': 'i' })<CR>
" xnoremap <silent> ii :<C-u>call user#mappings#motion#indent#({ 'mode': 'i' })<CR>
" onoremap <silent> ai :<C-u>call user#mappings#motion#indent#({ 'mode': 'a' })<CR>
" xnoremap <silent> ai :<C-u>call user#mappings#motion#indent#({ 'mode': 'a' })<CR>
" onoremap <silent> io :<C-u>call user#mappings#motion#indent#({ 'mode': 'o' })<CR>
" xnoremap <silent> io :<C-u>call user#mappings#motion#indent#({ 'mode': 'o' })<CR>
"
" @param {dictionary} options Configuration dictionary.
" @param {string} options.mode Motion to select text, whether 'a', 'i' or 'o'.
""
function! kutsan#mappings#motion#indent#(options) abort
function! user#mappings#motion#indent#(options) abort
let l:save = {
\ 'marks': {
\ "'[": getpos("'["),
Expand Down
22 changes: 22 additions & 0 deletions .config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,25 @@ g.loaded_getscriptPlugin = true
g.loaded_logipat = true
g.loaded_tutor_mode_plugin = true
g.loaded_matchit = true

-- Load lazy.nvim.
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not (vim.uv or 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)

local lazy = require('lazy')

lazy.setup('specs', {
change_detection = {
enabled = false,
},
})
35 changes: 35 additions & 0 deletions .config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"autopairs": { "branch": "master", "commit": "4f41e5940bc0443fdbe5f995e2a596847215cd2a" },
"catppuccin": { "branch": "main", "commit": "a1439ad7c584efb3d0ce14ccb835967f030450fe" },
"cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-calc": { "branch": "main", "commit": "ce91d14d2e7a8b3f6ad86d85e34d41c1ae6268d9" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-lsp-signature-help": { "branch": "main", "commit": "3d8912ebeb56e5ae08ef0906e3a54de1c66b92f1" },
"cmp-luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cokeline": { "branch": "main", "commit": "8b877a972337623f3f28f85a71611b2a08911b3a" },
"colorizer": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" },
"copilot": { "branch": "master", "commit": "f7612f5af4a7d7615babf43ab1e67a2d790c13a6" },
"devicons": { "branch": "master", "commit": "b3468391470034353f0e5110c70babb5c62967d3" },
"diffview": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" },
"dressing": { "branch": "master", "commit": "18e5beb3845f085b6a33c24112b37988f3f93c06" },
"fugitive": { "branch": "master", "commit": "dac8e5c2d85926df92672bf2afb4fc48656d96c7" },
"gitsigns": { "branch": "main", "commit": "7e38f07cab0e5387f9f41e92474db174a63a4725" },
"lazy.nvim": { "branch": "main", "commit": "31ddbea7c10b6920c9077b66c97951ca8682d5c8" },
"lspconfig": { "branch": "master", "commit": "9eb6d866840df0f3fb1d2e8f34a7e0cfdf80f980" },
"luasnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"mason": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" },
"mason-lspconfig": { "branch": "main", "commit": "44509689b9bf3984d729cc264aacb31cb7f41668" },
"nvim-tree": { "branch": "master", "commit": "81eb8d519233c105f30dc0a278607e62b20502fd" },
"plenary": { "branch": "master", "commit": "8aad4396840be7fc42896e3011751b7609ca4119" },
"schema-store": { "branch": "main", "commit": "4ace5d886d826452abee415ff92bda986e2c01c6" },
"surround": { "branch": "main", "commit": "a4e30d33add8a9743b4f518b3a788b3c8e5def71" },
"telescope": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" },
"treesitter": { "branch": "master", "commit": "208d504421e4ac53f4230a34cd4b831e8e76cb69" },
"treesitter-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" },
"treesitter-context": { "branch": "master", "commit": "e6e71047bb323fb36f5664993a42adaac252bb36" },
"treesitter-text-objects": { "branch": "master", "commit": "23b820146956b3b681c19e10d3a8bc0cbd9a1d4c" },
"undotree": { "branch": "master", "commit": "56c684a805fe948936cda0d1b19505b84ad7e065" }
}
8 changes: 8 additions & 0 deletions .config/nvim/lua/specs/autopairs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local Plugin = { 'windwp/nvim-autopairs' }

Plugin.name = 'autopairs'

Plugin.config = true
Plugin.event = 'InsertEnter'

return Plugin
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
local catppuccin = require('catppuccin')
local Plugin = { 'catppuccin/nvim' }

catppuccin.setup({
Plugin.name = 'catppuccin'

Plugin.lazy = false
Plugin.priority = 1000

Plugin.opts = {
flavour = 'mocha',
no_bold = true,
term_colors = true,
Expand Down Expand Up @@ -69,4 +74,13 @@ catppuccin.setup({
},
},
},
})
}

Plugin.config = function(_, opts)
local catppuccin = require('catppuccin')
catppuccin.setup(opts)

vim.cmd.colorscheme('catppuccin')
end

return Plugin
181 changes: 181 additions & 0 deletions .config/nvim/lua/specs/cmp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
local Plugin = { 'hrsh7th/nvim-cmp' }

Plugin.name = 'cmp'

Plugin.event = 'InsertEnter'

Plugin.dependencies = {
{ 'hrsh7th/cmp-buffer', name = 'cmp-buffer' },
{ 'hrsh7th/cmp-calc', name = 'cmp-calc' },
{ 'hrsh7th/cmp-cmdline', name = 'cmp-cmdline' },
{ 'hrsh7th/cmp-nvim-lsp', name = 'cmp-lsp' },
{ 'hrsh7th/cmp-nvim-lsp-signature-help', name = 'cmp-lsp-signature-help' },
{ 'saadparwaiz1/cmp_luasnip', name = 'cmp-luasnip' },
{ 'hrsh7th/cmp-path', name = 'cmp-path' },
'luasnip',
'autopairs',
}

Plugin.opts = function()
local cmp = require('cmp')

local kind_icons = {
Text = '',
Method = '󰆧',
Function = '󰊕',
Constructor = '',
Field = '󰇽',
Variable = '󰀫',
Class = '󰠱',
Interface = '',
Module = '',
Property = '󰜢',
Unit = '',
Value = '󰎠',
Enum = '',
Keyword = '󰌋',
Snippet = '',
Color = '󰏘',
File = '󰈙',
Reference = '',
Folder = '󰉋',
EnumMember = '',
Constant = '󰏿',
Struct = '',
Event = '',
Operator = '󰆕',
TypeParameter = '󰅲',
}

return {
snippet = {
expand = function(args)
local luasnip = require('luasnip')
luasnip.lsp_expand(args.body)
end,
},
completion = {
completeopt = 'menu,menuone,noinsert',
},
window = {
documentation = {
max_width = 60,
max_height = 15,
},
},
experimental = {
ghost_text = true,
},
formatting = {
fields = { 'kind', 'abbr', 'menu' },
format = function(_, item)
local label_width = 20
local label = item.abbr
local truncated_label = vim.fn.strcharpart(label, 0, label_width)

if truncated_label ~= label then
item.abbr = truncated_label .. ''
elseif string.len(label) < label_width then
local padding = string.rep(' ', label_width - string.len(label))
item.abbr = label .. padding
end

item.menu = item.kind
item.kind = kind_icons[item.kind]
return item
end,
},
mapping = {
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4)),
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4)),
['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item()),
['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item()),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete()),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
['<Tab>'] = cmp.mapping(function(fallback)
local function has_words_before()
local row_position, column_position =
unpack(vim.api.nvim_win_get_cursor(0))

if column_position == 0 then
return false
end

local current_line = vim.api.nvim_buf_get_lines(
0,
row_position - 1,
row_position,
false
)[1]
local character_at_cursor =
current_line:sub(column_position + 1, column_position + 1)

return character_at_cursor:match('%s') == nil
end

if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'luasnip' },
{ name = 'calc' },
}, {
{ name = 'buffer' },
}),
}
end

Plugin.config = function(_, opts)
local cmp = require('cmp')
local autopairs_cmp_completion = require('nvim-autopairs.completion.cmp')

cmp.setup(opts)

cmp.setup.cmdline(':', {
completion = {
completeopt = 'menu,menuone,noinsert,noselect',
},
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' },
}, {
{ name = 'cmdline' },
}),
})

cmp.setup.cmdline({ '/', '?' }, {
completion = {
completeopt = 'menu,menuone,noinsert,noselect',
},
view = {
entries = { name = 'wildmenu' },
},
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
},
})

cmp.event:on('confirm_done', autopairs_cmp_completion.on_confirm_done())
end

return Plugin
Loading

0 comments on commit 47cf395

Please sign in to comment.