Markdown easy line
This commit is contained in:
parent
50d6df2de7
commit
814895b1ca
@ -1,7 +1,7 @@
|
|||||||
---@type ChadrcConfig
|
---@type ChadrcConfig
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.ui = { theme = 'oceanic-light' }
|
M.ui = { theme = 'one_light' }
|
||||||
M.plugins = 'custom.plugins'
|
M.plugins = 'custom.plugins'
|
||||||
M.mappings = require "custom.mappings"
|
M.mappings = require "custom.mappings"
|
||||||
return M
|
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:
|
local function open_float_terminal_with_command(cmd)
|
||||||
vim.api.nvim_create_user_command("Cargo", function(opts)
|
-- 1. Create a scratch buffer (not listed, no file)
|
||||||
-- Split the entire command-line input (opts.args) by spaces.
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
-- For example, if someone types :Cargo new test_project --bin
|
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
|
||||||
-- the split might be {"new", "test_project", "--bin"}.
|
|
||||||
local args = vim.split(opts.args, "%s+")
|
|
||||||
|
|
||||||
-- The first item is the subcommand: "run", "build", or "new".
|
-- 2. Get the dimensions of the current window (the active split)
|
||||||
local subcommand = args[1]
|
local cur_width = vim.api.nvim_win_get_width(0)
|
||||||
|
local cur_height = vim.api.nvim_win_get_height(0)
|
||||||
|
|
||||||
if subcommand == "run" then
|
-- 3. Calculate floating window dimensions relative to the current window.
|
||||||
vim.cmd "!cargo run"
|
-- Here we're using 80% of the current window's width/height.
|
||||||
elseif subcommand == "build" then
|
local width = math.floor(cur_width * 0.8)
|
||||||
vim.cmd "!cargo build"
|
local height = math.floor(cur_height * 0.8)
|
||||||
elseif subcommand == "new" then
|
local row = math.floor((cur_height - height) / 2)
|
||||||
-- Everything after 'new' is the project name plus optional flags.
|
local col = math.floor((cur_width - width) / 2)
|
||||||
-- Let's remove 'new' from the table, then join the rest with spaces.
|
|
||||||
table.remove(args, 1) -- remove 'new'
|
-- 4. Open the floating window relative to the current window
|
||||||
local new_args = table.concat(args, " ")
|
local win = vim.api.nvim_open_win(buf, true, {
|
||||||
if #new_args == 0 then
|
relative = "win", -- Relative to the current window instead of the editor
|
||||||
print "Usage: :Cargo new <name> [options]"
|
width = width,
|
||||||
return
|
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
|
||||||
|
open_float_terminal_with_command "cargo run"
|
||||||
|
elseif subcommand == "build" then
|
||||||
|
open_float_terminal_with_command "cargo build"
|
||||||
|
elseif subcommand == "new" then
|
||||||
|
table.remove(args, 1) -- Remove the "new" literal.
|
||||||
|
local new_args = table.concat(args, " ")
|
||||||
|
if new_args == "" then
|
||||||
|
print "Usage: :Cargo new <name> [options]"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
open_float_terminal_with_command("cargo new " .. new_args)
|
||||||
|
else
|
||||||
|
print "Valid subcommands: run, build, new"
|
||||||
end
|
end
|
||||||
|
end,
|
||||||
|
{ nargs = "*" } -- Allow multiple arguments (e.g. for 'new').
|
||||||
|
)
|
||||||
|
|
||||||
-- Run "cargo new whatever-is-left"
|
-- Key mappings to trigger our Cargo commands in a floating terminal.
|
||||||
vim.cmd("!cargo new " .. new_args)
|
vim.keymap.set("n", "<leader>cr", ":Cargo run<CR>", { desc = "Cargo: run in floating terminal" })
|
||||||
else
|
vim.keymap.set("n", "<leader>cb", ":Cargo build<CR>", { desc = "Cargo: build in floating terminal" })
|
||||||
print(
|
vim.keymap.set("n", "<leader>cn", ":Cargo new ", { desc = "Cargo: new in floating terminal" })
|
||||||
"Please provide 'run', 'build', or 'new' as an argument to :Cargo. "
|
|
||||||
.. "For 'new', also specify <name> [options]."
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end, {
|
|
||||||
-- We make nargs = '*' so you can type multiple arguments
|
|
||||||
-- e.g. ':Cargo new test_project --bin'
|
|
||||||
nargs = "*",
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Keymaps remain the same, or you could add more if you want:
|
print "Rust Keybinds Loaded"
|
||||||
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.
|
|
||||||
|
|||||||
@ -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.matlab"
|
||||||
require "custom.language_specific_commands.rust"
|
require "custom.language_specific_commands.rust"
|
||||||
|
require "custom.language_specific_commands.markdown"
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user