save
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
vim.cmd.colorscheme("vim")
|
|
||||||
vim.g.mapleader = " "
|
vim.g.mapleader = " "
|
||||||
vim.keymap.set("n", "<C-h>", "<C-w><C-h>")
|
vim.keymap.set("n", "<C-h>", "<C-w><C-h>")
|
||||||
vim.keymap.set("n", "<C-j>", "<C-w><C-j>")
|
vim.keymap.set("n", "<C-j>", "<C-w><C-j>")
|
||||||
@@ -19,160 +18,177 @@ vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
|
|||||||
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>d', '"+d<CR>')
|
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>d', '"+d<CR>')
|
||||||
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>y', '"+y<CR>')
|
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>y', '"+y<CR>')
|
||||||
|
|
||||||
vim.o.relativenumber = true
|
vim.cmd("set nocompatible") -- force 'nocompatible', like modern Vim
|
||||||
vim.o.number = true
|
vim.cmd("syntax off")
|
||||||
vim.o.shiftwidth = 8
|
vim.o.background = "dark"
|
||||||
vim.o.tabstop = 8
|
|
||||||
vim.o.expandtab = false
|
|
||||||
vim.o.wrap = false
|
|
||||||
vim.o.winborder = "rounded"
|
|
||||||
vim.o.clipboard = "unnamedplus"
|
vim.o.clipboard = "unnamedplus"
|
||||||
|
vim.o.cmdheight = 1
|
||||||
|
vim.o.expandtab = false
|
||||||
|
vim.o.hlsearch = false
|
||||||
|
vim.o.ignorecase = false
|
||||||
|
vim.o.incsearch = false
|
||||||
|
vim.o.laststatus = 1
|
||||||
|
vim.o.number = true
|
||||||
|
vim.o.relativenumber = true
|
||||||
|
vim.o.ruler = true
|
||||||
|
vim.o.shiftwidth = 8
|
||||||
|
vim.o.showcmd = true
|
||||||
|
vim.o.showmode = true
|
||||||
|
vim.o.showtabline = 0
|
||||||
|
vim.o.smartcase = false
|
||||||
|
vim.o.statusline = ""
|
||||||
vim.o.swapfile = false
|
vim.o.swapfile = false
|
||||||
|
vim.o.tabstop = 8
|
||||||
|
vim.o.termguicolors = false
|
||||||
|
vim.o.wildmenu = false
|
||||||
|
vim.o.winborder = "rounded"
|
||||||
|
vim.o.wrap = false
|
||||||
vim.opt.path:append("**")
|
vim.opt.path:append("**")
|
||||||
|
|
||||||
vim.keymap.set("i", "me::", function()
|
vim.keymap.set("i", "me::", function()
|
||||||
return vim.fn.strftime("Author: vx_clutch <https://vx-clutch.github.io/vxserver.dev/>\nDate: %B %d, %Y\nLicense: BSD-3-Clause")
|
return vim.fn.strftime(
|
||||||
|
"Author: vx_clutch <https://vx-clutch.github.io/vxserver.dev/>\nDate: %B %d, %Y\nLicense: BSD-3-Clause")
|
||||||
end, { expr = true })
|
end, { expr = true })
|
||||||
|
|
||||||
local augroup = vim.api.nvim_create_augroup("vxclutch", {})
|
local augroup = vim.api.nvim_create_augroup("vxclutch", {})
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("BufReadPost", {
|
vim.api.nvim_create_autocmd("BufReadPost", {
|
||||||
group = augroup,
|
group = augroup,
|
||||||
callback = function()
|
callback = function()
|
||||||
local mark = vim.api.nvim_buf_get_mark(0, '"')
|
local mark = vim.api.nvim_buf_get_mark(0, '"')
|
||||||
local lcount = vim.api.nvim_buf_line_count(0)
|
local lcount = vim.api.nvim_buf_line_count(0)
|
||||||
if mark[1] > 0 and mark[1] <= lcount then
|
if mark[1] > 0 and mark[1] <= lcount then
|
||||||
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("TermOpen", {
|
vim.api.nvim_create_autocmd("TermOpen", {
|
||||||
group = augroup,
|
group = augroup,
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.opt_local.number = false
|
vim.opt_local.number = false
|
||||||
vim.opt_local.relativenumber = false
|
vim.opt_local.relativenumber = false
|
||||||
vim.opt_local.signcolumn = "no"
|
vim.opt_local.signcolumn = "no"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
group = augroup,
|
group = augroup,
|
||||||
callback = function()
|
callback = function()
|
||||||
local dir = vim.fn.expand('<afile>:p:h')
|
local dir = vim.fn.expand('<afile>:p:h')
|
||||||
if vim.fn.isdirectory(dir) == 0 then
|
if vim.fn.isdirectory(dir) == 0 then
|
||||||
vim.fn.mkdir(dir, 'p')
|
vim.fn.mkdir(dir, 'p')
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local undodir = vim.fn.expand("~/.vim/undodir")
|
local undodir = vim.fn.expand("~/.vim/undodir")
|
||||||
if vim.fn.isdirectory(undodir) == 0 then
|
if vim.fn.isdirectory(undodir) == 0 then
|
||||||
vim.fn.mkdir(undodir, "p")
|
vim.fn.mkdir(undodir, "p")
|
||||||
end
|
end
|
||||||
|
|
||||||
local terminal_state = {
|
local terminal_state = {
|
||||||
buf = nil,
|
buf = nil,
|
||||||
win = nil,
|
win = nil,
|
||||||
is_open = false
|
is_open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
local function FloatingTerminal()
|
local function FloatingTerminal()
|
||||||
if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then
|
if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then
|
||||||
vim.api.nvim_win_close(terminal_state.win, false)
|
vim.api.nvim_win_close(terminal_state.win, false)
|
||||||
terminal_state.is_open = false
|
terminal_state.is_open = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if not terminal_state.buf or not vim.api.nvim_buf_is_valid(terminal_state.buf) then
|
if not terminal_state.buf or not vim.api.nvim_buf_is_valid(terminal_state.buf) then
|
||||||
terminal_state.buf = vim.api.nvim_create_buf(false, true)
|
terminal_state.buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
|
||||||
vim.api.nvim_buf_set_option(terminal_state.buf, 'bufhidden', 'hide')
|
vim.api.nvim_buf_set_option(terminal_state.buf, 'bufhidden', 'hide')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local width = math.floor(vim.o.columns * 0.8)
|
local width = math.floor(vim.o.columns * 0.8)
|
||||||
local height = math.floor(vim.o.lines * 0.8)
|
local height = math.floor(vim.o.lines * 0.8)
|
||||||
local row = math.floor((vim.o.lines - height) / 2)
|
local row = math.floor((vim.o.lines - height) / 2)
|
||||||
local col = math.floor((vim.o.columns - width) / 2)
|
local col = math.floor((vim.o.columns - width) / 2)
|
||||||
|
|
||||||
terminal_state.win = vim.api.nvim_open_win(terminal_state.buf, true, {
|
terminal_state.win = vim.api.nvim_open_win(terminal_state.buf, true, {
|
||||||
relative = 'editor',
|
relative = 'editor',
|
||||||
width = width,
|
width = width,
|
||||||
height = height,
|
height = height,
|
||||||
row = row,
|
row = row,
|
||||||
col = col,
|
col = col,
|
||||||
style = 'minimal',
|
style = 'minimal',
|
||||||
border = 'rounded',
|
border = 'rounded',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
vim.api.nvim_win_set_option(terminal_state.win, 'winblend', 0)
|
vim.api.nvim_win_set_option(terminal_state.win, 'winblend', 0)
|
||||||
|
|
||||||
|
|
||||||
vim.api.nvim_win_set_option(terminal_state.win, 'winhighlight',
|
vim.api.nvim_win_set_option(terminal_state.win, 'winhighlight',
|
||||||
'Normal:FloatingTermNormal,FloatBorder:FloatingTermBorder')
|
'Normal:FloatingTermNormal,FloatBorder:FloatingTermBorder')
|
||||||
|
|
||||||
|
|
||||||
vim.api.nvim_set_hl(0, "FloatingTermNormal", { bg = "none" })
|
vim.api.nvim_set_hl(0, "FloatingTermNormal", { bg = "none" })
|
||||||
vim.api.nvim_set_hl(0, "FloatingTermBorder", { bg = "none", })
|
vim.api.nvim_set_hl(0, "FloatingTermBorder", { bg = "none", })
|
||||||
|
|
||||||
|
|
||||||
local has_terminal = false
|
local has_terminal = false
|
||||||
local lines = vim.api.nvim_buf_get_lines(terminal_state.buf, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(terminal_state.buf, 0, -1, false)
|
||||||
for _, line in ipairs(lines) do
|
for _, line in ipairs(lines) do
|
||||||
if line ~= "" then
|
if line ~= "" then
|
||||||
has_terminal = true
|
has_terminal = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not has_terminal then
|
if not has_terminal then
|
||||||
vim.fn.termopen(os.getenv("SHELL"))
|
vim.fn.termopen(os.getenv("SHELL"))
|
||||||
end
|
end
|
||||||
|
|
||||||
terminal_state.is_open = true
|
terminal_state.is_open = true
|
||||||
vim.cmd("startinsert")
|
vim.cmd("startinsert")
|
||||||
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("BufLeave", {
|
vim.api.nvim_create_autocmd("BufLeave", {
|
||||||
buffer = terminal_state.buf,
|
buffer = terminal_state.buf,
|
||||||
callback = function()
|
callback = function()
|
||||||
if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then
|
if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then
|
||||||
vim.api.nvim_win_close(terminal_state.win, false)
|
vim.api.nvim_win_close(terminal_state.win, false)
|
||||||
terminal_state.is_open = false
|
terminal_state.is_open = false
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
once = true
|
once = true
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function CloseFloatingTerminal()
|
local function CloseFloatingTerminal()
|
||||||
if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then
|
if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then
|
||||||
vim.api.nvim_win_close(terminal_state.win, false)
|
vim.api.nvim_win_close(terminal_state.win, false)
|
||||||
terminal_state.is_open = false
|
terminal_state.is_open = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
vim.keymap.set("n", "<leader>t", FloatingTerminal, { noremap = true, silent = true })
|
vim.keymap.set("n", "<leader>t", FloatingTerminal, { noremap = true, silent = true })
|
||||||
vim.keymap.set("t", "<Esc>", function()
|
vim.keymap.set("t", "<Esc>", function()
|
||||||
if terminal_state.is_open then
|
if terminal_state.is_open then
|
||||||
vim.api.nvim_win_close(terminal_state.win, false)
|
vim.api.nvim_win_close(terminal_state.win, false)
|
||||||
terminal_state.is_open = false
|
terminal_state.is_open = false
|
||||||
end
|
end
|
||||||
end, { noremap = true, silent = true })
|
end, { noremap = true, silent = true })
|
||||||
vim.pack.add({
|
vim.pack.add({
|
||||||
{ src = "https://github.com/neovim/nvim-lspconfig" },
|
{ src = "https://github.com/neovim/nvim-lspconfig" },
|
||||||
})
|
})
|
||||||
local lspconfig = require("lspconfig")
|
local lspconfig = require("lspconfig")
|
||||||
local servers = { "lua_ls", "clangd" }
|
local servers = { "lua_ls", "clangd" }
|
||||||
for _, server in ipairs(servers) do
|
for _, server in ipairs(servers) do
|
||||||
lspconfig[server].setup({})
|
lspconfig[server].setup({})
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.diagnostic.config({
|
vim.diagnostic.config({
|
||||||
virtual_text = true,
|
virtual_text = true,
|
||||||
underline = true,
|
underline = true,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user