neovim: rewrite config

This commit is contained in:
2023-08-29 00:42:44 +03:00
parent fd67c6c242
commit 7221b8a04b
26 changed files with 106 additions and 872 deletions

View File

@@ -1 +0,0 @@
vim.wo.colorcolumn = ""

View File

@@ -1,2 +0,0 @@
vim.wo.colorcolumn = "50"
vim.cmd("setlocal spell")

View File

@@ -1,3 +0,0 @@
vim.bo.tabstop = 4
vim.bo.shiftwidth = 4
vim.bo.expandtab = false

View File

@@ -1,3 +0,0 @@
vim.bo.tabstop = 2
vim.bo.shiftwidth = 2
vim.bo.expandtab = false

View File

@@ -1 +0,0 @@
vim.cmd("setlocal spell")

View File

@@ -1,3 +0,0 @@
vim.bo.tabstop = 2
vim.bo.shiftwidth = 2
vim.bo.expandtab = false

View File

@@ -7,11 +7,3 @@ vim.api.nvim_create_autocmd("TextYankPost", {
vim.highlight.on_yank({ timeout = 200 })
end,
})
vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*",
group = group,
callback = function()
vim.cmd(":checktime")
end,
})

View File

@@ -1,15 +0,0 @@
local git = require("daniil.git")
vim.api.nvim_create_user_command("GitShowCommit", function()
local commit = git.get_commit_hash_for_current_line()
vim.cmd(":Git show " .. commit)
end, {})
vim.api.nvim_create_user_command("OpenUnsavedBuffers", function()
require("daniil.utils").open_unsaved_buffers()
end, {})
vim.api.nvim_create_user_command("ClearQuickfixList", function()
vim.fn.setqflist({})
end, {})

View File

@@ -0,0 +1,3 @@
vim.api.nvim_create_user_command("ClearQuickfixList", function()
vim.fn.setqflist({})
end, {})

View File

@@ -1,100 +0,0 @@
local function on_attach(bufnr)
local api = require("nvim-tree.api")
local function opts(desc)
return {
desc = "nvim-tree: " .. desc,
buffer = bufnr,
noremap = true,
silent = true,
nowait = true,
}
end
vim.keymap.set("n", "tn", api.node.open.tab, opts("tabnew"))
vim.keymap.set("n", "l", api.node.open.edit, opts("edit"))
vim.keymap.set("n", "<CR>", api.node.open.edit, opts("edit ENTER"))
vim.keymap.set("n", "@", api.tree.change_root_to_node, opts("change root"))
vim.keymap.set("n", "<C-v>", api.node.open.vertical, opts("vertical split"))
vim.keymap.set("n", "<C-h>", api.node.open.horizontal, opts("horizontal split"))
vim.keymap.set("n", "a", api.fs.create, opts("create file"))
vim.keymap.set("n", "d", api.fs.remove, opts("remove file"))
vim.keymap.set("n", "r", api.fs.rename, opts("rename file"))
vim.keymap.set("n", "R", api.tree.reload, opts("reload"))
vim.keymap.set("n", "x", api.fs.cut, opts("cut"))
vim.keymap.set("n", "y", api.fs.copy.filename, opts("copy filename"))
vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("copy relative path file"))
vim.keymap.set("n", "W", api.tree.collapse_all, opts("collapse all"))
vim.keymap.set("n", "I", api.tree.toggle_gitignore_filter, opts("toggle git ignored files"))
vim.keymap.set("n", "H", api.tree.toggle_hidden_filter, opts("toggle hidden files"))
vim.keymap.set("n", "<TAB>", api.node.open.preview, opts("preview node"))
vim.keymap.set("n", "F", api.live_filter.clear, opts("clear filter"))
vim.keymap.set("n", "f", api.live_filter.start, opts("filter"))
vim.keymap.set("n", "q", api.tree.close, opts("quit"))
vim.keymap.set("n", "p", api.fs.paste, opts("paste"))
end
require("nvim-tree").setup({
disable_netrw = true,
hijack_netrw = true,
hijack_cursor = true,
open_on_tab = false,
update_cwd = true,
auto_reload_on_write = true,
reload_on_bufenter = true,
update_focused_file = {
enable = true,
},
view = {
width = 30,
adaptive_size = false,
side = "left",
preserve_window_proportions = true,
centralize_selection = true,
},
renderer = {
add_trailing = true,
group_empty = false,
highlight_git = true,
indent_markers = {
enable = true,
},
icons = {
show = {
git = true,
file = true,
folder = true,
},
glyphs = {
default = "",
symlink = "",
git = {
unstaged = "U",
staged = "S",
unmerged = "M",
renamed = "R",
untracked = "N",
deleted = "D",
},
},
},
},
filters = {
custom = { "^.git$" },
},
actions = {
open_file = {
resize_window = true,
quit_on_open = true,
},
},
git = {
ignore = true,
},
diagnostics = {
enable = true,
show_on_dirs = true,
icons = { hint = "", info = "", warning = "", error = "" },
},
on_attach = on_attach,
})

View File

@@ -0,0 +1,22 @@
local actions = require("gitsigns.actions")
require("gitsigns").setup({
signcolumn = true,
attach_to_untracked = false,
current_line_blame = true,
current_line_blame_opts = {
delay = 1000,
},
current_line_blame_formatter_opts = {
relative_time = true,
},
on_attach = function(bufnr)
vim.keymap.set("n", "gn", actions.next_hunk)
vim.keymap.set("n", "gN", actions.prev_hunk)
vim.keymap.set("n", "gr", actions.reset_hunk)
end,
})
vim.keymap.set("n", "<leader>gg", ":Git<CR>")
vim.keymap.set("n", "gh", ":diffget //2<CR>")
vim.keymap.set("n", "gl", ":diffget //3<CR>")

View File

@@ -2,32 +2,12 @@ local mason = require("mason")
local lsp_installer = require("mason-lspconfig")
local lspconfig = require("lspconfig")
local null_ls = require("null-ls")
local util = require("lspconfig").util
local u = require("daniil.utils")
local util = lspconfig.util
local formatting = null_ls.builtins.formatting
local diagnostics = null_ls.builtins.diagnostics
mason.setup()
lsp_installer.setup({
ensure_installed = {
"bashls",
"cssmodules_ls",
"dockerls",
"tailwindcss",
"tsserver",
"vimls",
"cssls",
"html",
"jsonls",
"svelte",
"emmet_ls",
"eslint",
"gopls",
},
automatic_installation = true,
})
lsp_installer.setup()
null_ls.setup({
sources = {
@@ -43,41 +23,38 @@ null_ls.setup({
pattern = "*",
group = group,
callback = function()
u.lsp_format()
vim.lsp.buf.format()
end,
})
end,
})
-- Other formats that work weird with null_ls
local group = vim.api.nvim_create_augroup("OtherLspFormatting", { clear = true })
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = { "*.svelte" },
group = group,
callback = function()
vim.lsp.buf.format()
end,
})
local function on_attach(client, bufnr)
local opts = { buffer = bufnr, remap = false }
vim.keymap.set("n", "gd", ts.lsp_definitions, opts)
vim.keymap.set("n", "gr", ts.lsp_references, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<leader>.", vim.lsp.buf.code_action, opts)
vim.keymap.set("v", "<leader>.", vim.lsp.buf.range_code_action, opts)
vim.keymap.set({ "i", "n" }, "<C-u>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<leader>ee", function()
vim.diagnostic.open_float(nil, { focus = false, scope = "line" })
end, opts)
vim.keymap.set("n", "<leader>en", function()
vim.diagnostic.goto_next({ float = false })
end)
vim.keymap.set("n", "<leader>eN", function()
vim.diagnostic.goto_prev({ float = false })
end)
end
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities.textDocument.completion.completionItem.snippetSupport = true
local lsps_with_disabled_formatting = { "tsserver", "gopls", "jsonls", "html", "sumneko_lua" }
local on_attach = function(client, bufnr)
if vim.tbl_contains(lsps_with_disabled_formatting, client.name) then
client.server_capabilities.document_formatting = false
client.server_capabilities.document_range_formatting = false
client.server_capabilities.documentFormattingProvider = false
end
if client.name == "tailwindcss" then
require("tailwindcss-colors").buf_attach(bufnr)
end
end
local servers = lsp_installer.get_installed_servers()
for _, server in ipairs(servers) do
local opts = {
capabilities = capabilities,
@@ -89,41 +66,6 @@ for _, server in ipairs(servers) do
opts.filetypes = { "html", "css", "scss", "javascripreact", "typescriptreact", "astro" }
end
if server == "jsonls" then
opts.filetypes = { "json", "jsonc", "yaml" }
opts.settings = {
json = {
format = {
enable = false,
},
schemas = require("schemastore").json.schemas({
select = {
".eslintrc",
"package.json",
"tsconfig.json",
"prettierrc.json",
"babelrc.json",
"Vercel",
"cypress.json",
"GitHub Action",
"GitHub Workflow",
"lerna.json",
"openapi.json",
".postcssrc",
"prisma.yml",
"Swagger API 2.0",
"huskyrc",
"jsdoc",
".commitlintrc",
"docker-compose.yml",
".yarnrc.yml",
"swcrc",
},
}),
},
}
end
if server == "tsserver" then
opts.settings = {
tsserver = {

View File

@@ -1,127 +0,0 @@
local lualine = require("lualine")
local devicons = require("nvim-web-devicons")
local mode = {
"mode",
}
local branch = {
"branch",
icons_enabled = true,
icon = "",
}
local diagnostics = {
"diagnostics",
sections = { "error", "warn", "info", "hint" },
always_visible = true,
}
local relative_filename = {
"filename",
path = 1,
}
local filetype = {
function()
local filetype = vim.bo.filetype
local filename = vim.fn.expand("%:t")
local fileext = vim.fn.expand("%:e")
local icon = devicons.get_icon(filename, fileext)
if filetype == "fugitive" then
icon = devicons.get_icons().git.icon
end
if not icon then
return filetype
end
return icon .. " " .. filetype
end,
}
local filename = {
function()
local filetype = vim.bo.filetype
local filename = vim.fn.expand("%:t")
local fileext = vim.fn.expand("%:e")
local icon = devicons.get_icon(filename, fileext)
local modified = vim.bo.modified
if filetype == "fugitive" then
icon = devicons.get_icons().git.icon
end
if not icon then
return filename
end
if modified then
return icon .. " " .. filename .. " " .. "[+]"
end
return icon .. " " .. filename
end,
}
local fileformat = {
function()
return "[" .. vim.bo.fileformat .. "]"
end,
}
local tabstop = {
function()
local tabstop = vim.bo.tabstop
local expandtab = vim.bo.expandtab
local method = expandtab == true and "spaces" or "tabs"
local format = tabstop .. " " .. method
return format
end,
}
local location = {
function()
local line = vim.fn.line(".")
local total_lines = vim.api.nvim_buf_line_count(0)
local percent = math.floor(line / total_lines * 100)
return line .. "/" .. total_lines .. " (" .. percent .. "%%)"
end,
}
local diff = {
"diff",
}
lualine.setup({
options = {
component_separators = "",
section_separators = "",
globalstatus = true,
disabled_filetypes = {
winbar = {
"NvimTree",
},
},
},
winbar = {
lualine_a = { filename },
},
inactive_winbar = {
lualine_a = { filename },
},
sections = {
lualine_a = { mode },
lualine_b = { branch },
lualine_c = { diagnostics, relative_filename },
lualine_x = { diff, location, tabstop, fileformat },
lualine_y = { filetype },
lualine_z = {},
},
extensions = { "nvim-tree", "fugitive", "quickfix" },
})

View File

@@ -1,49 +1,40 @@
local opt = vim.opt
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.autoindent = true
-- 2 tabs converted to spaces + autoindentation
opt.tabstop = 2
opt.shiftwidth = 2
opt.expandtab = true
opt.autoindent = true
vim.opt.guicursor = "a:blinkoff0"
vim.opt.mouse = ""
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.splitbelow = true
vim.opt.splitright = true
vim.opt.signcolumn = "yes"
vim.opt.laststatus = 3
vim.opt.cmdheight = 0
vim.opt.showcmd = false
vim.opt.cursorline = true
vim.opt.clipboard = "unnamedplus"
vim.opt.autoread = true
vim.opt.colorcolumn = "80"
vim.opt.showtabline = 2
vim.opt.wrap = true
vim.opt.encoding = "utf-8"
vim.opt.updatetime = 300
vim.opt.fillchars:append({ eob = " " })
vim.opt.scrolloff = 5
vim.opt.redrawtime = 4000
vim.opt.showmode = false
vim.opt.hidden = true
-- What the **** is this
opt.shortmess = "filnxtToOFc"
vim.opt.swapfile = false
vim.opt.writebackup = false
-- Create splits like a normal human being
opt.splitbelow = true
opt.splitright = true
vim.opt.smartcase = true
vim.opt.ignorecase = true
-- Other settings
opt.termguicolors = true
opt.number = true
opt.relativenumber = true
opt.wrap = true
opt.swapfile = false
opt.hidden = true
opt.writebackup = false
opt.encoding = "utf-8"
opt.updatetime = 300
opt.mouse = ""
opt.cursorline = true
opt.clipboard = "unnamedplus"
opt.signcolumn = "yes"
opt.fillchars:append({ eob = " " })
opt.showtabline = 2
opt.showcmd = false
opt.guicursor = "a:blinkoff0"
opt.fileformat = "unix"
opt.fileformats = { "unix", "dos", "mac" }
opt.laststatus = 3
opt.cmdheight = 0
opt.smartcase = true
opt.ignorecase = true
opt.scrolloff = 5
opt.colorcolumn = "120"
opt.autoread = true
opt.showmode = false
opt.redrawtime = 4000
opt.list = true
opt.listchars = { multispace = "·", tab = ">~" }
vim.opt.list = true
vim.opt.listchars = { multispace = "·", tab = ">~" }
opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
opt.undofile = true
vim.cmd("colorscheme gruvbox-material")

View File

@@ -1,32 +1,11 @@
local ts = require("telescope.builtin")
local u = require("daniil.utils")
local git = require("daniil.git")
local ls = require("luasnip")
-- General keymaps
vim.keymap.set("n", "<C-c>", ":nohl<CR>")
-- Quickfix and location list remaps
vim.keymap.set("n", "<C-q>", u.toggle_qflist)
vim.keymap.set("n", "<leader>q", u.toggle_locationlist)
-- Disable different keys and commands
vim.keymap.set({ "n", "i", "v" }, "<PageDown>", "<nop>")
vim.keymap.set({ "n", "i", "v" }, "<PageUp>", "<nop>")
vim.keymap.set({ "n", "i", "v" }, "<F1>", "<nop>")
vim.keymap.set("n", "q:", "<nop>")
-- Move focus between splits
vim.keymap.set("n", "<leader>h", "<C-w>h")
vim.keymap.set("n", "<leader>l", "<C-w>l")
vim.keymap.set("n", "<leader>j", "<C-w>j")
vim.keymap.set("n", "<leader>k", "<C-w>k")
-- Resize splits
vim.keymap.set("n", "<C-h>", ":vert :res -10<CR>")
vim.keymap.set("n", "<C-l>", ":vert :res +10<CR>")
vim.keymap.set("n", "<C-j>", ":res -5<CR>")
vim.keymap.set("n", "<C-k>", ":res +5<CR>")
vim.keymap.set("n", "<leader><leader>", vim.cmd.Ex)
vim.keymap.set("n", "<C-c>", vim.cmd.nohl)
-- Move lines easily
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
@@ -41,93 +20,7 @@ vim.keymap.set("n", "Th", ":split | :term<CR>")
vim.keymap.set("n", "Tv", ":vs | :term<CR>")
-- Tabs
vim.keymap.set("n", "H", ":tabprev<CR>")
vim.keymap.set("n", "L", ":tabnext<CR>")
vim.keymap.set("n", "tn", ":tabnew<CR>")
vim.keymap.set("n", "tN", ":-tabnew<CR>")
vim.keymap.set("n", "tf", function()
require("daniil.tabs").find_tab()
end)
vim.keymap.set("n", "<A-h>", ":-tabmove<CR>")
vim.keymap.set("n", "<A-l>", ":+tabmove<CR>")
-- Nvim Tree
vim.keymap.set("n", "<leader><leader>", ":NvimTreeToggle<CR>")
-- Telescope
vim.keymap.set("n", "<leader>f", function()
ts.find_files({ hidden = true })
end)
vim.keymap.set("n", "<leader>p", function()
ts.builtin()
end)
vim.keymap.set("n", "<leader>b", function()
ts.buffers()
end)
-- LSP
vim.keymap.set("n", "gd", function()
ts.lsp_definitions()
end)
vim.keymap.set("n", "gr", function()
ts.lsp_references()
end)
vim.keymap.set("n", "K", function()
vim.lsp.buf.hover()
end)
vim.keymap.set("n", "<F2>", function()
vim.lsp.buf.rename()
end)
vim.keymap.set("n", "<leader>.", function()
vim.lsp.buf.code_action()
end)
vim.keymap.set("v", "<leader>.", function()
vim.lsp.buf.range_code_action()
end)
vim.keymap.set({ "i", "n" }, "<C-;>", vim.lsp.buf.signature_help)
-- Diagnostics
vim.keymap.set("n", "<leader>ee", function()
vim.diagnostic.open_float(nil, { focus = false, scope = "line" })
end)
vim.keymap.set("n", "<leader>ey", function()
u.copy_diagnostic_message()
end)
vim.keymap.set("n", "<leader>en", function()
vim.diagnostic.goto_next({ float = false })
end)
vim.keymap.set("n", "<leader>eN", function()
vim.diagnostic.goto_prev({ float = false })
end)
-- Git
vim.keymap.set("n", "<leader>gg", ":G<CR>")
vim.keymap.set("n", "<leader>go", function()
git.open_commit_on_github()
end)
vim.keymap.set("n", "gh", ":diffget //2<CR>")
vim.keymap.set("n", "gl", ":diffget //3<CR>")
-- Luasnip
local function next_choice()
if ls.jumpable(1) then
ls.jump(1)
end
end
local function prev_choice()
if ls.jumpable(-1) then
ls.jump(-1)
end
end
vim.keymap.set("i", "<C-l>", next_choice, { noremap = true, silent = true })
vim.keymap.set("s", "<C-l>", next_choice, { noremap = true, silent = true })
vim.keymap.set("i", "<C-h>", prev_choice, { noremap = true, silent = true })
vim.keymap.set("s", "<C-h>", prev_choice, { noremap = true, silent = true })
-- Undotree
vim.keymap.set("n", "<leader>u", function()
vim.cmd([[
UndotreeToggle
UndotreeFocus
]])
end)
vim.keymap.set("n", "H", ":tabprev<CR>")
vim.keymap.set("n", "L", ":tabnext<CR>")

View File

@@ -1,22 +0,0 @@
local ls = require("luasnip")
local s, i = ls.s, ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt
-- NOTE: this is not working right now, i need to RTFM
ls.filetype_extend("javascript", { "javascriptreact", "javascript.jsx" })
ls.filetype_extend("typescript", { "typescriptreact", "typescript.jsx" })
local clg = s(
"clg",
fmt([[console.log({});]], {
i(0),
})
)
ls.add_snippets("javascript", { clg })
ls.add_snippets("typescript", { clg })
ls.add_snippets("svelte", { clg })
require("luasnip.loaders.from_vscode").lazy_load({
include = { "go" },
})

View File

@@ -1,6 +1,7 @@
local telescope = require("telescope")
local actions = require("telescope.actions")
local layout_actions = require("telescope.actions.layout")
local builtin = require("telescope.builtin")
telescope.setup({
defaults = {
@@ -14,9 +15,6 @@ telescope.setup({
["<C-p>"] = layout_actions.toggle_preview,
},
n = {
["<C-d>"] = function(prompt_bufnr)
actions.delete_buffer(prompt_bufnr)
end,
["<C-p>"] = layout_actions.toggle_preview,
},
},
@@ -28,19 +26,9 @@ telescope.setup({
lsp_definitions = {
initial_mode = "normal",
},
buffers = {
mappings = {
i = {
["<C-d>"] = function(prompt_bufnr)
actions.delete_buffer(prompt_bufnr)
end,
},
n = {
["<C-d>"] = function(prompt_bufnr)
actions.delete_buffer(prompt_bufnr)
end,
},
},
find_files = {
hidden = true,
no_ignore = true,
},
},
extensions = {
@@ -53,4 +41,6 @@ telescope.setup({
},
})
require("telescope").load_extension("fzf")
telescope.load_extension("fzf")
vim.keymap.set("n", "<leader>f", builtin.find_files)

View File

@@ -1,8 +0,0 @@
vim.api.nvim_set_hl(0, "SpellBad", {
fg = "red",
})
vim.cmd([[
colorscheme gruvbox-material
hi clear SignColumn
]])

View File

@@ -35,7 +35,4 @@ require("nvim-treesitter.configs").setup({
context_commentstring = {
enable = true,
},
autotag = {
enable = true,
},
})

View File

@@ -13,63 +13,22 @@ end
require("packer").startup(function(use)
use({ "wbthomason/packer.nvim" })
use({ "nvim-lua/plenary.nvim" })
-- Colorschemes go here
use({ "sainnhe/gruvbox-material" })
-- Make commenting code great
use({ "nvim-treesitter/nvim-treesitter" })
use({ "JoosepAlviste/nvim-ts-context-commentstring" })
use({
"numToStr/Comment.nvim",
event = "BufRead",
config = function()
require("daniil.plugins.comment")
end,
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
{ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }
})
-- Icons used by many plugins
use({ "kyazdani42/nvim-web-devicons" })
-- Auto pairs plugin that automatically closes brackets and quotes
use({
"windwp/nvim-autopairs",
event = "BufRead",
config = function()
require("nvim-autopairs").setup({})
end,
})
-- File tree
use({ "kyazdani42/nvim-tree.lua" })
-- Treesitter for better syntax highlighting
use({
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
{
{ "JoosepAlviste/nvim-ts-context-commentstring" },
{ "windwp/nvim-ts-autotag" },
},
})
-- Git things
use({
"lewis6991/gitsigns.nvim",
event = "BufRead",
config = function()
require("daniil.plugins.gitsigns")
end,
})
use({ "tpope/vim-fugitive" })
use({ "lewis6991/gitsigns.nvim" })
-- LSP stuff
use({ "neovim/nvim-lspconfig" })
use({ "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim" })
use({ "jose-elias-alvarez/null-ls.nvim" })
use({ "b0o/SchemaStore.nvim" })
-- Completion, snippets, etc
use({
"hrsh7th/nvim-cmp",
{
@@ -83,21 +42,10 @@ require("packer").startup(function(use)
use({ "L3MON4D3/LuaSnip", {
"saadparwaiz1/cmp_luasnip",
} })
use({ "rafamadriz/friendly-snippets" })
use({
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
{
"nvim-telescope/telescope-fzf-native.nvim",
run = "make",
},
})
-- Statusline
use({ "nvim-lualine/lualine.nvim" })
use({ "mbbill/undotree" })
use({ "neovim/nvim-lspconfig" })
use({ "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim" })
use({ "jose-elias-alvarez/null-ls.nvim" })
if PACKER_BOOTSTRAP then
require("packer").sync()

View File

@@ -1,55 +0,0 @@
local u = require("daniil.utils")
local git = {}
--- @return string commit_hash
function git.get_commit_hash_for_current_line()
local fullpath = vim.api.nvim_buf_get_name(0)
local cwd = vim.loop.cwd()
local relative_path = string.gsub(fullpath, cwd .. "/", "")
local line = unpack(vim.api.nvim_win_get_cursor(0))
local f = io.popen("git blame -L " .. line .. ",+1 " .. relative_path, "r")
local data = f:read("*a")
f:close()
local commit_hash = vim.split(data, " ")[1]
return commit_hash
end
--- @return string git_remote_url
function git.get_remote_url()
local f = io.popen("git remote get-url origin", "r")
local remote_url = f:read("*l")
f:close()
if string.sub(remote_url, 0, 4) == "git@" then
remote_url = string.gsub(remote_url, "git@", "")
remote_url = string.gsub(remote_url, ".git", "")
remote_url = string.gsub(remote_url, ":", "/")
end
if string.sub(remote_url, 0, 5) ~= "https" then
remote_url = "https://" .. remote_url
end
return remote_url
end
function git.open_commit_on_github()
local commit_hash = git.get_commit_hash_for_current_line()
local remote_url = git.get_remote_url()
if commit_hash == "00000000" then
print("Not committed yet")
return
end
local commit_url = remote_url .. "/commit/" .. commit_hash
u.open_url_in_browser(commit_url)
end
return git

View File

@@ -0,0 +1 @@
print "fuck"

View File

@@ -1,25 +0,0 @@
require("Comment").setup({
pre_hook = function(ctx)
-- Only calculate commentstring for tsx filetypes
if vim.bo.filetype == "typescriptreact" or vim.bo.filetype == "javascriptreact" then
local U = require("Comment.utils")
-- Detemine whether to use linewise or blockwise commentstring
-- local type = ctx.ctype == U.ctype.line and "__default" or "__multiline"
local type = "__default"
-- Determine the location where to calculate commentstring from
local location = nil
if ctx.ctype == U.ctype.block then
location = require("ts_context_commentstring.utils").get_cursor_location()
elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
location = require("ts_context_commentstring.utils").get_visual_start_location()
end
return require("ts_context_commentstring.internal").calculate_commentstring({
key = type,
location = location,
})
end
end,
})

View File

@@ -1,43 +0,0 @@
local a = require("gitsigns.actions")
require("gitsigns").setup({
signcolumn = true,
attach_to_untracked = false,
current_line_blame = true,
current_line_blame_opts = {
delay = 1000,
},
current_line_blame_formatter_opts = {
relative_time = true,
},
on_attach = function(bufnr)
vim.keymap.set("n", "<leader>gs", function()
a.stage_hunk()
end)
vim.keymap.set("n", "<leader>gu", function()
a.undo_stage_hunk()
end)
vim.keymap.set("n", "<leader>gr", function()
a.reset_hunk()
end)
vim.keymap.set("n", "<leader>gp", function()
a.preview_hunk()
end)
vim.keymap.set("n", "<leader>gn", function()
a.next_hunk()
end)
vim.keymap.set("n", "<leader>gN", function()
a.prev_hunk()
end)
vim.keymap.set("v", "gs", function()
a.stage_hunk()
end)
vim.keymap.set("v", "gu", function()
a.undo_stage_hunk()
end)
vim.keymap.set("v", "gr", function()
a.reset_hunk()
end)
end,
})

View File

@@ -1,34 +0,0 @@
local M = {}
M.find_tab = function()
local tabpages = vim.api.nvim_list_tabpages()
local tabs = {}
for _, tabnr in ipairs(tabpages) do
local winnr = vim.api.nvim_tabpage_get_win(tabnr)
local bufnr = vim.api.nvim_win_get_buf(winnr)
local bufname = vim.api.nvim_buf_get_name(bufnr)
local root = vim.loop.cwd()
local relative_path = string.gsub(bufname, root .. "/", "")
table.insert(tabs, {
bufname = relative_path,
tabnr = tabnr,
})
end
vim.ui.select(tabs, {
prompt = "Choose a tab: ",
format_item = function(item)
return item.tabnr .. " - " .. item.bufname
end,
}, function(item)
if not item then
return
end
vim.api.nvim_set_current_tabpage(item.tabnr)
end)
end
return M

View File

@@ -1,103 +0,0 @@
local M = {}
M.yank = function(message)
vim.cmd(":!echo -n '" .. message .. "' | wl-copy")
end
--- @param diagnostics list
--- @param prompt string
--- @return string
M.select_diagnostic = function(diagnostics, prompt)
if #diagnostics == 0 then
return ""
end
local message = ""
if #diagnostics == 1 then
message = diagnostics[1].message
else
local d = {}
for _, diagnostic in ipairs(diagnostics) do
table.insert(d, diagnostic.message)
end
vim.ui.select(d, { prompt = prompt }, function(item)
message = item
end)
end
return message
end
M.copy_diagnostic_message = function()
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
local message = M.select_diagnostic(diagnostics, "Pick a diagnostic to yank")
M.yank(message)
print("Diagnostic message was yanked")
end
M.open_url_in_browser = function(url)
local _url = string.format('"%s"', url)
vim.cmd(":!exec xdg-open " .. _url)
end
function M.lsp_format(bufnr)
bufnr = bufnr or 0
vim.lsp.buf.format({
filter = function(client)
if client.name == "tsserver" then
return false
end
return true
end,
bufnr = bufnr,
})
end
function M.open_unsaved_buffers()
local buffers = vim.api.nvim_list_bufs()
local unsaved_buffers = {}
local og_bufnr = vim.api.nvim_get_current_buf()
for _, bufnr in ipairs(buffers) do
local is_saved = vim.api.nvim_buf_get_option(bufnr, "modified")
if is_saved and bufnr ~= og_bufnr then
local bufname = vim.api.nvim_buf_get_name(bufnr)
table.insert(unsaved_buffers, bufnr)
vim.cmd("tabnew " .. bufname)
end
end
if #unsaved_buffers > 0 then
vim.notify("Opened " .. #unsaved_buffers .. " unsaved buffers")
end
end
function M.toggle_qflist()
if vim.bo.ft == "qf" then
vim.cmd(":cclose")
else
vim.cmd(":copen")
end
end
function M.toggle_locationlist()
if vim.bo.ft == "qf" then
vim.cmd(":lclose")
else
vim.cmd(":lopen")
end
end
return M