Skip to content

Commit

Permalink
refactor(nvim): Remove autoload
Browse files Browse the repository at this point in the history
- Migrated trailing space trim and write+execute to Lua
- Drop `has_lsp` left over from Lightline config
- Drop unused `Redir` and `Pcol` functions
  • Loading branch information
ZeroKnight committed Oct 9, 2023
1 parent f62b279 commit 31f3bb8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 62 deletions.
60 changes: 0 additions & 60 deletions .config/nvim/autoload/zeroknight/util.vim

This file was deleted.

4 changes: 2 additions & 2 deletions .config/nvim/lua/zeroknight/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ wk.register({
L = { vim.diagnostic.setloclist, 'Dump diagnostics to location list' },
Q = { vim.diagnostic.setqflist, 'Dump diagnostics to quickfix list' },
},
wx = { '<Cmd>call zeroknight#util#save_and_exec()<CR>', 'Write and Execute' },
wx = { '<Cmd>write | source %<CR>', 'Write and Execute' },
y = { '"+y', 'Yank to clipboard', mode = { 'n', 'v' } },
Y = { '"+Y', 'Yank til EOL to clipboard' },
}, { prefix = '<Leader>' })
Expand All @@ -106,7 +106,7 @@ wk.register({
wk.register({
K = { 'K', 'Run keywordprg on word' },
r = {
s = { '<Cmd>call zeroknight#util#TrimTrailingSpace()<CR>', 'Trim trailing spaces' },
s = { util.trim_whitespace, 'Trim trailing spaces' },
w = { ':%s/\\<<C-r><C-w>\\>//gI<Left><Left><Left>', 'Substitute cursor word' },
W = { ':%s/\\<<C-r><C-a>\\>//gI<Left><Left><Left>', 'Substitute cursor WORD' },
},
Expand Down
9 changes: 9 additions & 0 deletions .config/nvim/lua/zeroknight/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ function M.toggle_background()
end
end

-- Trim trailing whitespace in buffer while preserving state/position
function M.trim_whitespace(buffer)
buffer = buffer or 0
local trimmed = vim.tbl_map(function(x)
return x:gsub('%s+$', '')
end, vim.api.nvim_buf_get_lines(buffer, 0, -1, true))
vim.api.nvim_buf_set_lines(buffer, 0, -1, true, trimmed)
end

-- From LazyVim
-- returns the root directory based on:
-- * lsp workspace folders
Expand Down

0 comments on commit 31f3bb8

Please sign in to comment.