Markdown easy line
This commit is contained in:
parent
50d6df2de7
commit
814895b1ca
@ -1,7 +1,7 @@
|
||||
---@type ChadrcConfig
|
||||
local M = {}
|
||||
|
||||
M.ui = { theme = 'oceanic-light' }
|
||||
M.ui = { theme = 'one_light' }
|
||||
M.plugins = 'custom.plugins'
|
||||
M.mappings = require "custom.mappings"
|
||||
return M
|
||||
|
||||
6
lua/custom/language_specific_commands/markdown.lua
Normal file
6
lua/custom/language_specific_commands/markdown.lua
Normal file
@ -0,0 +1,6 @@
|
||||
vim.keymap.set(
|
||||
"n",
|
||||
"<leader>li",
|
||||
"<M-i>The quick brown fox jumps over the lazy dog. The dog stays blissfully asleep. :)",
|
||||
{ desc = "Print a standard 80 character string for Markdown formatting." }
|
||||
)
|
||||
@ -1,45 +1,66 @@
|
||||
-- We modify our previously defined Cargo user command:
|
||||
vim.api.nvim_create_user_command("Cargo", function(opts)
|
||||
-- Split the entire command-line input (opts.args) by spaces.
|
||||
-- For example, if someone types :Cargo new test_project --bin
|
||||
-- the split might be {"new", "test_project", "--bin"}.
|
||||
local args = vim.split(opts.args, "%s+")
|
||||
local function open_float_terminal_with_command(cmd)
|
||||
-- 1. Create a scratch buffer (not listed, no file)
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
|
||||
|
||||
-- The first item is the subcommand: "run", "build", or "new".
|
||||
-- 2. Get the dimensions of the current window (the active split)
|
||||
local cur_width = vim.api.nvim_win_get_width(0)
|
||||
local cur_height = vim.api.nvim_win_get_height(0)
|
||||
|
||||
-- 3. Calculate floating window dimensions relative to the current window.
|
||||
-- Here we're using 80% of the current window's width/height.
|
||||
local width = math.floor(cur_width * 0.8)
|
||||
local height = math.floor(cur_height * 0.8)
|
||||
local row = math.floor((cur_height - height) / 2)
|
||||
local col = math.floor((cur_width - width) / 2)
|
||||
|
||||
-- 4. Open the floating window relative to the current window
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "win", -- Relative to the current window instead of the editor
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
-- 5. Launch your default shell in the new buffer.
|
||||
vim.fn.termopen(vim.o.shell)
|
||||
|
||||
-- 6. Use chansend to send the desired command followed by Enter.
|
||||
vim.fn.chansend(vim.b.terminal_job_id, cmd .. "\n")
|
||||
end
|
||||
|
||||
-- Create the :Cargo command that accepts subcommands.
|
||||
vim.api.nvim_create_user_command(
|
||||
"Cargo",
|
||||
function(opts)
|
||||
local args = vim.split(opts.args, "%s+")
|
||||
local subcommand = args[1]
|
||||
|
||||
if subcommand == "run" then
|
||||
vim.cmd "!cargo run"
|
||||
open_float_terminal_with_command "cargo run"
|
||||
elseif subcommand == "build" then
|
||||
vim.cmd "!cargo build"
|
||||
open_float_terminal_with_command "cargo build"
|
||||
elseif subcommand == "new" then
|
||||
-- Everything after 'new' is the project name plus optional flags.
|
||||
-- Let's remove 'new' from the table, then join the rest with spaces.
|
||||
table.remove(args, 1) -- remove 'new'
|
||||
table.remove(args, 1) -- Remove the "new" literal.
|
||||
local new_args = table.concat(args, " ")
|
||||
if #new_args == 0 then
|
||||
if new_args == "" then
|
||||
print "Usage: :Cargo new <name> [options]"
|
||||
return
|
||||
end
|
||||
|
||||
-- Run "cargo new whatever-is-left"
|
||||
vim.cmd("!cargo new " .. new_args)
|
||||
open_float_terminal_with_command("cargo new " .. new_args)
|
||||
else
|
||||
print(
|
||||
"Please provide 'run', 'build', or 'new' as an argument to :Cargo. "
|
||||
.. "For 'new', also specify <name> [options]."
|
||||
)
|
||||
print "Valid subcommands: run, build, new"
|
||||
end
|
||||
end, {
|
||||
-- We make nargs = '*' so you can type multiple arguments
|
||||
-- e.g. ':Cargo new test_project --bin'
|
||||
nargs = "*",
|
||||
})
|
||||
end,
|
||||
{ nargs = "*" } -- Allow multiple arguments (e.g. for 'new').
|
||||
)
|
||||
|
||||
-- Keymaps remain the same, or you could add more if you want:
|
||||
vim.keymap.set("n", "<leader>cr", ":Cargo run<CR>", { desc = "Cargo: run" })
|
||||
vim.keymap.set("n", "<leader>cb", ":Cargo build<CR>", { desc = "Cargo: build" })
|
||||
-- Optionally, bind something for "new":
|
||||
vim.keymap.set("n", "<leader>cn", ":Cargo new ", { desc = "Cargo: new" })
|
||||
-- Notice we didn't put <CR> at the end of ':Cargo new ' because you typically
|
||||
-- want to type your project name before pressing Enter.
|
||||
-- Key mappings to trigger our Cargo commands in a floating terminal.
|
||||
vim.keymap.set("n", "<leader>cr", ":Cargo run<CR>", { desc = "Cargo: run in floating terminal" })
|
||||
vim.keymap.set("n", "<leader>cb", ":Cargo build<CR>", { desc = "Cargo: build in floating terminal" })
|
||||
vim.keymap.set("n", "<leader>cn", ":Cargo new ", { desc = "Cargo: new in floating terminal" })
|
||||
|
||||
print "Rust Keybinds Loaded"
|
||||
|
||||
@ -47,5 +47,6 @@ vim.api.nvim_set_keymap("n", "<leader>e", "<cmd>lua vim.diagnostic.open_float()<
|
||||
|
||||
require "custom.language_specific_commands.matlab"
|
||||
require "custom.language_specific_commands.rust"
|
||||
require "custom.language_specific_commands.markdown"
|
||||
|
||||
return M
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user