new
This commit is contained in:
@@ -29,6 +29,39 @@ vim.api.nvim_create_user_command('MessagesToBuffer', function()
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
end, { desc = 'Open :messages output in a scratch buffer' })
|
||||
|
||||
vim.api.nvim_create_user_command('CmdToBuffer', function(opts)
|
||||
local cmd = table.concat(opts.fargs, ' ')
|
||||
|
||||
vim.g.__cmd_to_buffer_cmd = cmd
|
||||
vim.g.__cmd_to_buffer_out = nil
|
||||
|
||||
local exec_line = opts.bang and 'silent execute' or 'execute'
|
||||
local ok, err = pcall(vim.cmd, string.format(
|
||||
[[
|
||||
redir => g:__cmd_to_buffer_out
|
||||
%s g:__cmd_to_buffer_cmd
|
||||
redir END
|
||||
]],
|
||||
exec_line
|
||||
))
|
||||
if not ok then
|
||||
pcall(vim.cmd, 'redir END')
|
||||
error(err)
|
||||
end
|
||||
|
||||
local output = vim.g.__cmd_to_buffer_out or ''
|
||||
vim.g.__cmd_to_buffer_cmd = nil
|
||||
vim.g.__cmd_to_buffer_out = nil
|
||||
local lines = vim.split(output, '\n', { plain = true, trimempty = false })
|
||||
|
||||
vim.cmd('new')
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
vim.bo[bufnr].buftype = 'nofile'
|
||||
vim.bo[bufnr].bufhidden = 'wipe'
|
||||
vim.bo[bufnr].swapfile = false
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
end, { nargs = '+', bang = true, complete = 'command', desc = 'Run an Ex command and open its output in a scratch buffer' })
|
||||
|
||||
-- Automatically create a scratch buffer if Neovim starts with no files
|
||||
au('VimEnter', {
|
||||
group = group,
|
||||
|
||||
@@ -22,6 +22,15 @@ vim.keymap.set('x', 'K', ":m '<-2<CR>gv=gv")
|
||||
|
||||
vim.keymap.set('n', '<leader>s', [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/g<Left><Left><Left>]])
|
||||
|
||||
-- Scroll
|
||||
-- vim.keymap.set('n', '<C-d>', function()
|
||||
-- vim.cmd('normal! ' .. math.floor(vim.api.nvim_win_get_height(0) * 0.25) .. 'j')
|
||||
-- end)
|
||||
--
|
||||
-- vim.keymap.set('n', '<C-u>', function()
|
||||
-- vim.cmd('normal! ' .. math.floor(vim.api.nvim_win_get_height(0) * 0.25) .. 'k')
|
||||
-- end)
|
||||
|
||||
-- Easy to use registers
|
||||
map('x', '<leader>p', '"_dP')
|
||||
map({ 'n', 'x' }, '<leader>y', '"+y')
|
||||
@@ -38,6 +47,7 @@ map('n', '<C-k>', '<C-w>k')
|
||||
-- Tab management
|
||||
map('n', ']t', cmd('tabnext'))
|
||||
map('n', '[t', cmd('tabprevious'))
|
||||
map('n', '<leader>t', '<nop>')
|
||||
map('n', '<leader>tt', cmd('tabnew'))
|
||||
map('n', '<leader>tn', cmd('tabnew'))
|
||||
map('n', '<leader>tc', cmd('tabclose'))
|
||||
|
||||
@@ -71,6 +71,7 @@ vim.opt.autoindent = true -- Copy indent from the current line when starting a n
|
||||
vim.opt.smartindent = true -- Automatically inserts indents in code blocks (for C-like languages)
|
||||
|
||||
-- Scroll and mouse
|
||||
vim.opt.scroll = 20
|
||||
vim.opt.scrolloff = 10
|
||||
vim.opt.sidescrolloff = 5
|
||||
vim.opt.mousescroll = 'hor:1,ver:1'
|
||||
|
||||
@@ -15,6 +15,8 @@ function M.get()
|
||||
{ 'https://github.com/mfussenegger/nvim-lint' },
|
||||
{ 'https://github.com/stevearc/conform.nvim' },
|
||||
|
||||
{ 'https://github.com/tpope/vim-fugitive' },
|
||||
|
||||
-- { 'https://github.com/MeanderingProgrammer/render-markdown.nvim' },
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user