summaryrefslogtreecommitdiffstats
path: root/.config
diff options
context:
space:
mode:
Diffstat (limited to '.config')
-rw-r--r--.config/nvim/ftplugin/lua.lua3
-rw-r--r--.config/nvim/init.lua219
-rw-r--r--.config/nvim/lua/lines.lua121
3 files changed, 147 insertions, 196 deletions
diff --git a/.config/nvim/ftplugin/lua.lua b/.config/nvim/ftplugin/lua.lua
index 956ba20..6633c77 100644
--- a/.config/nvim/ftplugin/lua.lua
+++ b/.config/nvim/ftplugin/lua.lua
@@ -1 +1,2 @@
-require("lazydev").setup {}
+
+require'lazydev'.setup {}
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua
index 8a2de27..038e37b 100644
--- a/.config/nvim/init.lua
+++ b/.config/nvim/init.lua
@@ -1,3 +1,5 @@
+vim.loader.enable()
+
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
@@ -13,6 +15,7 @@ vim.opt.splitbelow = true
vim.g.netrw_keepdir = 0
vim.g.netrw_banner = 0
+vim.g.netrw_winsize = 30
vim.g.loaded_node_provider = 0
vim.g.loaded_perl_provider = 0
@@ -46,120 +49,15 @@ vim.keymap.set('n', '<S-Right>', vim.cmd.bnext)
vim.keymap.set('n', '<S-Left>', vim.cmd.bprev)
----@param buffer integer
----@return string
-local function get_formated_bufname(buffer)
- buffer = buffer or 0
-
- local name = vim.api.nvim_buf_get_name(buffer)
- local buftype = vim.bo[buffer].buftype
- if buftype == "terminal" then
- name = vim.b[buffer].term_title
- else
- if #name == 0 then
- name = '[No Name] (' .. (buftype or vim.bo[buffer].filetype) .. ')'
- end
- local modified = vim.bo[buffer].modified and '[+]' or ""
- local readonly = vim.bo[buffer].readonly and '[RO]' or ""
- name = name .. modified .. readonly
- end
-
- return name
-end
-
----@class Line
-Line = {
- ---@return string
- status = function()
- local buffer = vim.api.nvim_win_get_buf(vim.g.statusline_winid)
- local buftype = vim.bo[buffer].buftype
- print(buftype)
- if buftype == "terminal" then
- return table.concat({ vim.b[buffer].term_title, vim.api.nvim_buf_get_name(buffer) }, '%=')
- end
- local a = ""
- if vim.opt.ruler:get() then
- a = "%8l:%c%V %8p%%"
- end
-
- local clients = {}
- for _, client in ipairs(vim.lsp.get_clients()) do
- if client.attached_buffers[buffer] then
- table.insert(clients, client.name)
- end
- end
-
- return table.concat({
- vim.api.nvim_get_mode().mode:upper(),
- get_formated_bufname(buffer),
- "%=",
- vim.bo.filetype,
- "(" .. table.concat(clients, ", ") .. ")",
- vim.bo.spelllang,
- vim.bo.fileencoding,
- vim.bo.fileformat,
- a
- }, " ")
- end,
-
- ---@return string
- tab = function()
- local tabs = vim.api.nvim_list_tabpages()
- local format = vim.tbl_map(function(tab)
- local str = ""
- if tab == vim.api.nvim_get_current_tabpage() then
- str = '%#TabLineSel#'
- else
- str = '%#TabLine#'
- end
- local buffer = vim.api.nvim_win_get_buf(vim.api.nvim_tabpage_get_win(tab))
- return
- table.concat {
- str,
- "%", tab, 'T',
- get_formated_bufname(buffer),
- " %", tab, 'XX'
- }
- end, tabs)
- local tabline = table.concat(format, " ")
-
- return tabline .. '%#TabLineFill#%T'
- end,
-
- ---@return string
- column = function()
- local col = {}
- if vim.opt.foldenable:get() then
- local foldchar = " "
- local hl = vim.fn.line(".") == vim.v.lnum and "CursorLineFold#" or "FoldColumn#"
- if vim.v.virtnum == 0 and vim.fn.foldlevel(vim.v.lnum)
- and vim.fn.foldlevel(vim.v.lnum) > vim.fn.foldlevel(vim.v.lnum - 1) then
- foldchar = vim.fn.foldclosed(vim.v.lnum) == -1 and "⌵" or "›"
- end
-
- foldchar = "%#" .. hl .. foldchar .. "%*"
- table.insert(col, foldchar)
- end
+Line = require 'lines'
- if vim.opt.number:get() or vim.opt.relativenumber:get() then
- local linenr = " "
- if vim.v.virtnum == 0 then
- if vim.opt.number:get() and not vim.opt.relativenumber:get() then
- linenr = vim.v.lnum
- elseif not vim.opt.number:get() and vim.opt.relativenumber:get() then
- linenr = vim.v.relnum
- else
- linenr = vim.v.relnum ~= 0 and vim.v.relnum or vim.v.lnum
- end
- end
- linenr = "%=" .. linenr
- table.insert(col, linenr)
- end
+vim.keymap.set('n', '<leader>o', function()
+ vim.cmd.Lexplore(vim.fn.expand "%:p:h")
+end)
- table.insert(col, "%s")
- return table.concat(col, "")
- end
-}
+vim.keymap.set('n', '<leader>O', function()
+ vim.cmd.Lexplore(vim.fn.expand "%:p:h")
+end)
require 'nvim-treesitter.configs'.setup {
highlight = {
@@ -169,75 +67,9 @@ require 'nvim-treesitter.configs'.setup {
auto_install = true,
}
-local set = require 'set'
-
----@param dir string
-function Filepicker(dir)
- vim.fs.normalize(dir)
- local function action(result)
- if result[2] == "directory" then
- Filepicker(result[1])
- elseif result[2] == "link"
- then
- action({ result[3], result[4] })
- else
- vim.cmd("edit " .. result[1])
- end
- end
- local function format(tbl)
- if tbl[2] == "directory" then
- return tbl[1] .. "/"
- elseif tbl[2] == "link" then
- return tbl[1] .. " -> " .. format({ tbl[3], tbl[4] })
- else
- return tbl[1]
- end
- end
- local file_iter = vim.iter(vim.fs.dir(dir, { depth = 1 }))
- local files = file_iter:totable()
- table.insert(files, 1, { "..", "link" })
- files = vim.tbl_map(function(tbl)
- if tbl[2] == "link" then
- local path = vim.fs.joinpath(dir, tbl[1])
- tbl[#tbl + 1] = vim.uv.fs_realpath(path)
- if tbl[3] then
- tbl[#tbl + 1] = vim.uv.fs_stat(tbl[3]).type
- else
- tbl[#tbl + 1] = "broken"
- end
- end
- return tbl
- end, files)
- files = vim.tbl_filter(function(tbl)
- local valid = set:new { "file", "directory" }
- if tbl[2] == "link" then
- return valid:has(tbl[4])
- else
- return valid:has(tbl[2])
- end
- end, files)
- vim.ui.select(files, {
- prompt = 'Open: ',
- format_item = format
- }, function(result)
- if result then
- result[1] = vim.fs.joinpath(dir, result[1])
- action(result)
- end
- end)
-end
-
-vim.keymap.set('n', '<leader>o', function()
- Filepicker(vim.fn.getcwd())
-end)
-
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
-require("conform").setup {
- formatters_by_ft = {
- python = { "isort", "black" },
- },
-}
+require 'conform'.setup {}
vim.opt.formatexpr = "v:lua.require'conform'.formatexpr()"
vim.keymap.set('n', '<leader>f', function()
@@ -253,7 +85,7 @@ vim.api.nvim_create_user_command("Format", function(args)
["end"] = { args.line2, end_line:len() },
}
end
- require("conform").format({ async = true, lsp_format = "fallback", range = range })
+ require("conform").format { async = true, lsp_format = "fallback", range = range }
end, { range = true })
vim.keymap.set('n', '<leader>b', function()
@@ -265,7 +97,7 @@ vim.keymap.set('n', '<leader>b', function()
)
vim.ui.select(bufs, {
prompt = 'Buffer: ',
- format_item = get_formated_bufname
+ format_item = Line.get_formated_bufname
}, function(result)
if result then
vim.api.nvim_set_current_buf(result)
@@ -279,7 +111,7 @@ vim.keymap.set('n', '<leader>t', function()
prompt = 'Tab: ',
format_item = function(tab)
local buffer = vim.api.nvim_win_get_buf(vim.api.nvim_tabpage_get_win(tab))
- return get_formated_bufname(buffer)
+ return Line.get_formated_bufname(buffer)
end
}, function(result)
if result then
@@ -315,12 +147,12 @@ vim.api.nvim_create_autocmd('LspAttach', {
vim.lsp.inlay_hint.enable()
- vim.lsp.codelens.refresh({ bufnr = ev.buf })
+ vim.lsp.codelens.refresh(opts)
vim.api.nvim_create_autocmd({ 'CursorHold', 'InsertLeave' }, {
buffer = ev.buf,
callback = function()
- vim.lsp.codelens.refresh({ bufnr = ev.buf })
+ vim.lsp.codelens.refresh(opts)
end,
})
@@ -355,15 +187,14 @@ local function setupLSP(server_name, settings)
"force",
{},
vim.lsp.protocol.make_client_capabilities(),
- require('cmp_nvim_lsp').default_capabilities()
+ require 'cmp_nvim_lsp'.default_capabilities()
)
- local config = require("lspconfig")
- require("lspconfig")[server_name].setup(settings)
+ require "lspconfig"[server_name].setup(settings)
end
-require('mason').setup {}
-require('mason-lspconfig').setup {
+require 'mason'.setup {}
+require 'mason-lspconfig'.setup {
ensure_installed = { 'lua_ls' },
handlers = {
function(server_name)
@@ -399,7 +230,7 @@ require('mason-lspconfig').setup {
compositeLiteralTypes = true,
functionTypeParameters = true,
},
- codelenses ={
+ codelenses = {
gc_details = true,
}
},
@@ -455,10 +286,10 @@ require('mason-lspconfig').setup {
}
}
-local cmp = require('cmp')
+local cmp = require 'cmp'
local cmp_select = { behavior = cmp.SelectBehavior.Select }
-cmp.setup({
+cmp.setup {
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
@@ -477,6 +308,4 @@ cmp.setup({
}, {
{ name = 'buffer' },
})
-})
-
--- require("fidget").setup {}
+}
diff --git a/.config/nvim/lua/lines.lua b/.config/nvim/lua/lines.lua
new file mode 100644
index 0000000..167ed10
--- /dev/null
+++ b/.config/nvim/lua/lines.lua
@@ -0,0 +1,121 @@
+---@class Line
+local line = {}
+
+---@param buffer integer
+---@return string
+function line.get_formated_bufname(buffer)
+ buffer = buffer or 0
+
+ local name = vim.api.nvim_buf_get_name(buffer)
+ local buftype = vim.bo[buffer].buftype
+ if buftype == "terminal" then
+ name = vim.b[buffer].term_title
+ else
+ if #name == 0 then
+ name = '[No Name] (' .. (buftype or vim.bo[buffer].filetype) .. ')'
+ end
+ local modified = vim.bo[buffer].modified and '[+]' or ""
+ local readonly = vim.bo[buffer].readonly and '[RO]' or ""
+ name = name .. modified .. readonly
+ end
+
+ return name
+end
+
+---@return string
+function line.status()
+ local buffer = vim.api.nvim_win_get_buf(vim.g.statusline_winid)
+ local buftype = vim.bo[buffer].buftype
+ print(buftype)
+ if buftype == "terminal" then
+ return table.concat({ vim.b[buffer].term_title, vim.api.nvim_buf_get_name(buffer) }, '%=')
+ end
+ local a = ""
+ if vim.opt.ruler then
+ a = "%8l:%c%V %8p%%"
+ end
+
+ local clients = {}
+ for _, client in ipairs(vim.lsp.get_clients()) do
+ if client.attached_buffers[buffer] then
+ table.insert(clients, client.name)
+ end
+ end
+
+ local cli = ""
+ if #clients ~= 0 then
+ cli = "(" .. table.concat(clients, ", ") .. ")"
+ end
+
+ return table.concat({
+ vim.api.nvim_get_mode().mode:upper(),
+ line.get_formated_bufname(buffer),
+ "%=",
+ vim.bo.filetype,
+ cli,
+ vim.bo.spelllang,
+ vim.bo.fileencoding,
+ vim.bo.fileformat,
+ a
+ }, " ")
+end
+
+---@return string
+function line.tab()
+ local tabs = vim.api.nvim_list_tabpages()
+ local format = vim.tbl_map(function(tab)
+ local str = ""
+ if tab == vim.api.nvim_get_current_tabpage() then
+ str = '%#TabLineSel#'
+ else
+ str = '%#TabLine#'
+ end
+ local buffer = vim.api.nvim_win_get_buf(vim.api.nvim_tabpage_get_win(tab))
+ return
+ table.concat {
+ str,
+ "%", tab, 'T',
+ line.get_formated_bufname(buffer),
+ " %", tab, 'XX'
+ }
+ end, tabs)
+ local tabline = table.concat(format, " ")
+
+ return tabline .. '%#TabLineFill#%T'
+end
+
+---@return string
+function line.column()
+ local col = {}
+ if vim.opt.foldenable:get() then
+ local foldchar = " "
+ local hl = vim.fn.line(".") == vim.v.lnum and "CursorLineFold#" or "FoldColumn#"
+ if vim.v.virtnum == 0 and vim.fn.foldlevel(vim.v.lnum)
+ and vim.fn.foldlevel(vim.v.lnum) > vim.fn.foldlevel(vim.v.lnum - 1) then
+ foldchar = vim.fn.foldclosed(vim.v.lnum) == -1 and "⌵" or "›"
+ end
+
+ foldchar = "%#" .. hl .. foldchar .. "%*"
+ table.insert(col, foldchar)
+ end
+
+ if vim.opt.number or vim.opt.relativenumber then
+ local linenr = 0
+ if vim.v.virtnum == 0 then
+ if vim.opt.number and not vim.opt.relativenumber then
+ linenr = vim.v.lnum
+ elseif not vim.opt.number and vim.opt.relativenumber then
+ linenr = vim.v.relnum
+ else
+ linenr = vim.v.relnum ~= 0 and vim.v.relnum or vim.v.lnum
+ end
+ end
+ local linenum = "%=" .. linenr
+ table.insert(col, linenum)
+ end
+
+ table.insert(col, "%s")
+ return table.concat(col, "")
+end
+
+return line