Skip to content

Commit

Permalink
refactor: use LazyVim new utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
rafi committed May 21, 2024
1 parent 4e5404c commit 65706e6
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 246 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,6 @@ Note that,
| <kbd>Space</kbd> <kbd>o</kbd> | 𝐍 | Open Outline side | <small>[hedyhli/outline.nvim]</small>
| <kbd>Space</kbd> <kbd>?</kbd> | 𝐍 | Open the macOS dictionary on current word | <small>`:!open dict:https://`</small>
| <kbd>Space</kbd> <kbd>cp</kbd> | 𝐍 | Toggle Markdown preview | <small>iamcco/markdown-preview.nvim</small>
| <kbd>Space</kbd> <kbd>P</kbd> | 𝐍 | Use Marked 2 for real-time Markdown preview | <small>[Marked 2]</small>
| <kbd>Space</kbd> <kbd>mc</kbd> | 𝐍 | Open color-picker | <small>[uga-rosa/ccc.nvim]</small>
| <kbd>Space</kbd> <kbd>tt</kbd> | 𝐍 | Open terminal (root dir) | <small>[config/keymaps.lua]</small>
| <kbd>Space</kbd> <kbd>tT</kbd> | 𝐍 | Open terminal (cwd) | <small>[config/keymaps.lua]</small>
Expand Down Expand Up @@ -1410,5 +1409,4 @@ more mappings and usage information.
[plugins/lsp/keymaps.lua]: ./lua/rafi/plugins/lsp/keymaps.lua
[lua/rafi/util/contextmenu.lua]: ./lua/rafi/util/contextmenu.lua
[nvim-treesitter]: https://github.com/nvim-treesitter/nvim-treesitter
[Marked 2]: https://marked2app.com
[www.lazyvim.org/extras]: https://www.lazyvim.org/extras
6 changes: 3 additions & 3 deletions lua/rafi/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ vim.api.nvim_create_autocmd('TextYankPost', {
end,
})

-- resize splits if window got resized
-- Resize splits if window got resized
vim.api.nvim_create_autocmd({ 'VimResized' }, {
group = augroup('resize_splits'),
callback = function()
Expand Down Expand Up @@ -73,7 +73,7 @@ vim.api.nvim_create_autocmd({ 'InsertEnter', 'WinLeave' }, {
end,
})

-- wrap and check for spell in text filetypes
-- Wrap and check for spell in text filetypes
vim.api.nvim_create_autocmd('FileType', {
group = augroup('wrap_spell'),
pattern = { 'gitcommit', 'markdown' },
Expand All @@ -96,7 +96,7 @@ vim.api.nvim_create_autocmd({ 'FileType' }, {
vim.api.nvim_create_autocmd('BufWritePre', {
group = augroup('auto_create_dir'),
callback = function(event)
if event.match:match("^%w%w+:[\\/][\\/]") then
if event.match:match('^%w%w+:[\\/][\\/]') then
return
end
local file = vim.uv.fs_realpath(event.match) or event.match
Expand Down
58 changes: 15 additions & 43 deletions lua/rafi/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- ===
-- This file is automatically loaded by rafi.config.init

local RafiUtil = require('rafi.util')
local Util = require('rafi.util')
local map = vim.keymap.set

-- Package-manager
Expand Down Expand Up @@ -144,8 +144,8 @@ map('n', ']a', '<cmd>lnext<CR>', { desc = 'Next Loclist' })
map('n', '[a', '<cmd>lprev<CR>', { desc = 'Previous Loclist' })

-- Whitespace jump (see plugin/whitespace.vim)
map('n', ']z', function() RafiUtil.edit.whitespace_jump(1) end, { desc = 'Next Whitespace' })
map('n', '[z', function() RafiUtil.edit.whitespace_jump(-1) end, { desc = 'Previous Whitespace' })
map('n', ']z', function() Util.edit.whitespace_jump(1) end, { desc = 'Next Whitespace' })
map('n', '[z', function() Util.edit.whitespace_jump(-1) end, { desc = 'Previous Whitespace' })

-- Diagnostic movement
local diagnostic_goto = function(next, severity)
Expand Down Expand Up @@ -243,21 +243,18 @@ map('n', '!', ':!', { desc = 'Execute Shell Command' })
map('n', 'g!', ":put=execute('')<Left><Left>", { desc = 'Paste Command' })

-- Switch history search pairs, matching my bash shell
---@return string
map('c', '<Up>', '<C-p>')
map('c', '<Down>', '<C-n>')
map('c', '<C-p>', function()
return vim.fn.pumvisible() == 1 and '<C-p>' or '<Up>'
end, { expr = true })

map('c', '<C-n>', function()
return vim.fn.pumvisible() == 1 and '<C-n>' or '<Down>'
end, { expr = true })

-- Use keywordprg
map('n', '<leader>K', '<cmd>norm! K<cr>', { desc = 'Keywordprg' })

map('c', '<Up>', '<C-p>')
map('c', '<Down>', '<C-n>')

--- }}}
-- File operations {{{

Expand All @@ -281,15 +278,15 @@ map({ 'n', 'i', 'v' }, '<C-s>', '<cmd>write<CR>', { desc = 'Save File' })
-- Editor UI {{{

-- Toggle list windows
map('n', '<leader>xl', function() RafiUtil.edit.toggle_list('loclist') end, { desc = 'Toggle Location List' })
map('n', '<leader>xq', function() RafiUtil.edit.toggle_list('quickfix') end, { desc = 'Toggle Quickfix List' })
map('n', '<leader>xl', function() Util.edit.toggle_list('loclist') end, { desc = 'Toggle Location List' })
map('n', '<leader>xq', function() Util.edit.toggle_list('quickfix') end, { desc = 'Toggle Quickfix List' })

-- Set locations with diagnostics and open the list.
map('n', '<Leader>a', function()
if vim.bo.filetype ~= 'qf' then
vim.diagnostic.setloclist({ open = false })
end
RafiUtil.edit.toggle_list('loclist')
Util.edit.toggle_list('loclist')
end, { desc = 'Open Location List' })

map('n', '<leader>uf', function() LazyVim.format.toggle() end, { desc = 'Toggle Auto Format (Global)' })
Expand All @@ -298,8 +295,8 @@ map('n', '<leader>us', function() LazyVim.toggle('spell') end, { desc = 'Toggle
map('n', '<leader>uw', function() LazyVim.toggle('wrap') end, { desc = 'Toggle Word Wrap' })
map('n', '<leader>uL', function() LazyVim.toggle('relativenumber') end, { desc = 'Toggle Relative Line Numbers' })
map('n', '<leader>ul', function() LazyVim.toggle.number() end, { desc = 'Toggle Line Numbers' })
map('n', '<Leader>ud', function() RafiUtil.edit.diagnostic_toggle(false) end, { desc = 'Disable Diagnostics' })
map('n', '<Leader>uD', function() RafiUtil.edit.diagnostic_toggle(true) end, { desc = 'Disable All Diagnostics' })
map('n', '<Leader>ud', function() Util.edit.diagnostic_toggle(false) end, { desc = 'Disable Diagnostics' })
map('n', '<Leader>uD', function() Util.edit.diagnostic_toggle(true) end, { desc = 'Disable All Diagnostics' })

map('n', '<Leader>uo', '<cmd>setlocal nolist!<CR>', { desc = 'Toggle Whitespace Symbols' })
map('n', '<Leader>uu', '<cmd>nohlsearch<CR>', { desc = 'Hide Search Highlight' })
Expand All @@ -323,31 +320,19 @@ map(
{ desc = 'Redraw / Clear hlsearch / Diff Update' }
)

-- Smart wrap toggle (breakindent and colorcolumn toggle as-well)
map('n', '<Leader>uw', function()
vim.opt_local.wrap = not vim.wo.wrap
vim.opt_local.breakindent = not vim.wo.breakindent

if vim.wo.colorcolumn == '' then
vim.opt_local.colorcolumn = tostring(vim.bo.textwidth)
else
vim.opt_local.colorcolumn = ''
end
end, { desc = 'Toggle Wrap' })

-- }}}
-- Plugins & Tools {{{

-- Append mode-line to current buffer
map('n', '<Leader>ml', function() RafiUtil.edit.append_modeline() end, { desc = 'Append Modeline' })
map('n', '<Leader>ml', function() Util.edit.append_modeline() end, { desc = 'Append Modeline' })

-- Jump entire buffers throughout jumplist
map('n', 'g<C-i>', function() RafiUtil.edit.jump_buffer(1) end, { desc = 'Jump to newer buffer' })
map('n', 'g<C-o>', function() RafiUtil.edit.jump_buffer(-1) end, { desc = 'Jump to older buffer' })
map('n', 'g<C-i>', function() Util.edit.jump_buffer(1) end, { desc = 'Jump to newer buffer' })
map('n', 'g<C-o>', function() Util.edit.jump_buffer(-1) end, { desc = 'Jump to older buffer' })

-- Context aware menu. See lua/lib/contextmenu.lua
map('n', '<RightMouse>', function() RafiUtil.contextmenu.show() end)
map('n', '<LocalLeader>c', function() RafiUtil.contextmenu.show() end, { desc = 'Content-aware menu' })
map('n', '<RightMouse>', function() Util.contextmenu.show() end)
map('n', '<LocalLeader>c', function() Util.contextmenu.show() end, { desc = 'Content-aware menu' })

-- Lazygit
map('n', '<leader>tg', function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = 'Lazygit (Root Dir)' })
Expand All @@ -367,19 +352,6 @@ map('n', '<leader>tT', function() LazyVim.terminal() end, { desc = 'Terminal (cw
if vim.fn.has('mac') then
-- Open the macOS dictionary on current word
map('n', '<Leader>?', '<cmd>silent !open dict:https://<cword><CR>', { desc = 'Dictionary' })

-- Use Marked for real-time Markdown preview
-- See: https://marked2app.com/
if vim.fn.executable('/Applications/Marked 2.app') then
vim.api.nvim_create_autocmd('FileType', {
group = vim.api.nvim_create_augroup('rafi_marked_preview', {}),
pattern = 'markdown',
callback = function()
local cmd = "<cmd>silent !open -a Marked\\ 2.app '%:p'<CR>"
map('n', '<Leader>P', cmd, { desc = 'Markdown Preview' })
end,
})
end
end

-- }}}
Expand Down
36 changes: 6 additions & 30 deletions lua/rafi/config/lazy.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
-- Rafael Bodill's lazy.nvim initialization
-- Rafi's lazy.nvim initialization
-- https://github.com/rafi/vim-config

-- Clone bootstrap repositories if not already installed.
vim.uv = vim.uv or vim.loop
local function clone(remote, dest)
if not vim.uv.fs_stat(dest) then
print('Installing ' .. dest .. '')
remote = 'https://github.com/' .. remote
-- stylua: ignore
vim.fn.system({ 'git', 'clone', '--filter=blob:none', remote, '--branch=stable', dest })
end
end

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
clone('https://github.com/folke/lazy.nvim.git', lazypath)
clone('folke/lazy.nvim.git', lazypath)
---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
clone('https://github.com/LazyVim/LazyVim.git', vim.fn.stdpath('data') .. '/lazy/LazyVim')
clone('LazyVim/LazyVim.git', vim.fn.stdpath('data') .. '/lazy/LazyVim')

-- Load user options from lua/config/setup.lua
local user_lazy_opts = {}
Expand All @@ -31,34 +32,9 @@ local has_user_plugins = vim.uv.fs_stat(user_path .. '/plugins') ~= nil
-- Start lazy.nvim plugin manager.
require('lazy').setup(vim.tbl_extend('keep', user_lazy_opts, {
spec = {
-- Load LazyVim, but without any plugins (no import).
-- See all options in lua/rafi/plugins/lazyvim.lua
{
'LazyVim/LazyVim',
version = '*',
priority = 10000,
lazy = false,
cond = true,
opts = {},
config = function(_, opts)
-- Load lua/rafi/config/*
require('rafi.config').setup()
-- Setup lazyvim, but don't load lazyvim/config/* files.
package.loaded['lazyvim.config.options'] = true
require('lazyvim.config').setup(vim.tbl_deep_extend('force', opts, {
defaults = { autocmds = false, keymaps = false },
news = { lazyvim = false },
}))
end,
},

-- Load RafiVim plugins
{ import = 'rafi.plugins.lazyvim' },
{ import = 'rafi.plugins' },

-- Load custom user lua/plugins.lua or lua/plugins/*
has_user_plugins and { import = 'plugins' } or nil,

-- Load LazyExtras
{ import = 'lazyvim.plugins.xtras' },
},
concurrency = vim.uv.available_parallelism() * 2,
Expand Down
Loading

0 comments on commit 65706e6

Please sign in to comment.