summaryrefslogtreecommitdiffstats
path: root/.config/nvim
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim')
-rw-r--r--.config/nvim/init.lua197
-rw-r--r--.config/nvim/lua/lines.lua85
-rw-r--r--.config/nvim/plugin/backports.lua198
3 files changed, 333 insertions, 147 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua
index 038e37b..b28863e 100644
--- a/.config/nvim/init.lua
+++ b/.config/nvim/init.lua
@@ -3,15 +3,15 @@ vim.loader.enable()
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-vim.opt.number = true
-vim.opt.relativenumber = true
-vim.opt.title = true
-vim.opt.termguicolors = true
+vim.o.number = true
+vim.o.relativenumber = true
+vim.o.title = true
+vim.o.termguicolors = true
vim.opt.shortmess:append("sI")
-vim.opt.splitright = true
-vim.opt.splitbelow = true
+vim.o.splitright = true
+vim.o.splitbelow = true
vim.g.netrw_keepdir = 0
vim.g.netrw_banner = 0
@@ -21,38 +21,44 @@ vim.g.loaded_node_provider = 0
vim.g.loaded_perl_provider = 0
vim.g.loaded_python_provider = 0
-vim.opt.list = true
-vim.opt.mouse = 'a'
+vim.o.list = true
+vim.o.mouse = 'a'
-vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
-vim.opt.foldmethod = "expr"
-vim.opt.foldcolumn = "auto"
+vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
+vim.o.foldmethod = "expr"
+vim.o.foldcolumn = "auto"
-vim.opt.cursorline = true
-vim.opt.laststatus = 2
-vim.opt.statusline = "%!v:lua.Line.status()"
-vim.opt.tabline = "%!v:lua.Line.tab()"
-vim.opt.signcolumn = 'yes'
-vim.opt.statuscolumn = "%!v:lua.Line.column()"
-vim.opt.showtabline = 2
+vim.o.cursorline = true
+vim.o.laststatus = 2
+vim.o.statusline = "%!v:lua.require'lines'.status()"
+vim.o.tabline = "%!v:lua.require'lines'.tab()"
+vim.o.signcolumn = 'yes'
+vim.opt.fillchars = {
+ foldopen = "⌵",
+ foldclose = "›",
+ eob = " "
+}
+
+vim.o.showtabline = 2
vim.keymap.set({ 'n', 'x' }, '<leader>y', '"+y')
vim.keymap.set('n', '<leader>p', '"+p')
vim.keymap.set('x', '<leader>p', '"+P')
-vim.opt.colorcolumn = '+1'
-
-vim.opt.hlsearch = true
-vim.keymap.set('n', '<Esc>', vim.cmd.nohlsearch)
-
-vim.keymap.set('n', '<S-Right>', vim.cmd.bnext)
-vim.keymap.set('n', '<S-Left>', vim.cmd.bprev)
+vim.o.colorcolumn = '+1'
+vim.o.hlsearch = true
+vim.keymap.set('n', '<Esc>', function()
+ vim.cmd.nohlsearch()
+end)
-Line = require 'lines'
+vim.keymap.set('n', '<leader>t', function()
+ vim.cmd.vsplit()
+ vim.cmd.terminal()
+end)
vim.keymap.set('n', '<leader>o', function()
- vim.cmd.Lexplore(vim.fn.expand "%:p:h")
+ vim.cmd.Lexplore()
end)
vim.keymap.set('n', '<leader>O', function()
@@ -67,11 +73,13 @@ require 'nvim-treesitter.configs'.setup {
auto_install = true,
}
-vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
+vim.keymap.set('n', '<leader>q', function()
+ vim.diagnostic.setloclist()
+end)
require 'conform'.setup {}
-vim.opt.formatexpr = "v:lua.require'conform'.formatexpr()"
+vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
vim.keymap.set('n', '<leader>f', function()
require('conform').format { async = true, lsp_format = "fallback", }
end)
@@ -88,93 +96,82 @@ vim.api.nvim_create_user_command("Format", function(args)
require("conform").format { async = true, lsp_format = "fallback", range = range }
end, { range = true })
-vim.keymap.set('n', '<leader>b', function()
- local bufs = vim.tbl_filter(
- function(buffer)
- return vim.bo[buffer].buflisted
- end,
- vim.api.nvim_list_bufs()
- )
- vim.ui.select(bufs, {
- prompt = 'Buffer: ',
- format_item = Line.get_formated_bufname
- }, function(result)
- if result then
- vim.api.nvim_set_current_buf(result)
- end
- end)
+vim.keymap.set({ 'n', 'v' }, 'grl', function()
+ vim.lsp.codelens.run()
end)
-vim.keymap.set('n', '<leader>t', function()
- local tabs = vim.api.nvim_list_tabpages()
- vim.ui.select(tabs, {
- prompt = 'Tab: ',
- format_item = function(tab)
- local buffer = vim.api.nvim_win_get_buf(vim.api.nvim_tabpage_get_win(tab))
- return Line.get_formated_bufname(buffer)
- end
+vim.keymap.set('n', '<leader>wa', function()
+ vim.lsp.buf.add_workspace_folder()
+end)
+
+vim.keymap.set('n', '<leader>wr', function()
+ vim.lsp.buf.remove_workspace_folder()
+end)
+
+vim.keymap.set('n', '<leader>wl', function()
+ local dir = vim.lsp.buf.list_workspace_folders()
+ vim.ui.select(dir, {
+ prompt = 'Workspace Dir: ',
}, function(result)
if result then
- vim.api.nvim_set_current_tabpage(result)
+ vim.api.nvim_set_current_dir(result)
end
end)
end)
+vim.api.nvim_create_user_command("Symbols", function(args)
+ if args.args == ""
+ then
+ vim.lsp.buf.workspace_symbol()
+ else
+ vim.lsp.buf.workspace_symbol(args.args)
+ end
+end, { nargs = "?" })
+
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(ev)
local opts = { buffer = ev.buf }
+ local client = vim.lsp.get_client_by_id(ev.data.client_id)
- vim.keymap.set('n', 'grn', vim.lsp.buf.rename, opts)
- vim.keymap.set({ 'n', 'v' }, 'gra', vim.lsp.buf.code_action, opts)
- vim.keymap.set({ 'n', 'v' }, 'grl', vim.lsp.codelens.run, opts)
- vim.keymap.set('n', 'grr', vim.lsp.buf.references, opts)
- vim.keymap.set('n', 'gri', vim.lsp.buf.implementation, opts)
- vim.keymap.set('n', 'gO', vim.lsp.buf.document_symbol, opts)
- vim.keymap.set('n', '<C-s>', vim.lsp.buf.signature_help, opts)
-
- vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts)
- vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, opts)
- vim.keymap.set('n', '<leader>wl', function()
- local dir = vim.lsp.buf.list_workspace_folders()
- vim.ui.select(dir, {
- prompt = 'Workspace Dir: ',
- }, function(result)
- if result then
- vim.api.nvim_set_current_dir(result)
- end
- end)
- end, opts)
-
- vim.lsp.inlay_hint.enable()
-
- vim.lsp.codelens.refresh(opts)
+ if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
+ vim.lsp.inlay_hint.enable()
+ end
- vim.api.nvim_create_autocmd({ 'CursorHold', 'InsertLeave' }, {
- buffer = ev.buf,
- callback = function()
- vim.lsp.codelens.refresh(opts)
- end,
- })
+ if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then
+ local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight',
+ { clear = false })
+ vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
+ buffer = ev.buf,
+ group = highlight_augroup,
+ callback = vim.lsp.buf.document_highlight,
+ })
- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
- buffer = ev.buf,
- callback = function()
- vim.lsp.buf.document_highlight()
- end,
- })
+ vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
+ buffer = ev.buf,
+ group = highlight_augroup,
+ callback = vim.lsp.buf.clear_references,
+ })
- vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
- buffer = ev.buf,
- callback = function()
- vim.lsp.buf.clear_references()
- end,
- })
+ vim.api.nvim_create_autocmd('LspDetach', {
+ callback = function(event)
+ vim.lsp.buf.clear_references()
+ vim.api.nvim_clear_autocmds {
+ group = highlight_augroup,
+ buffer = event.buf
+ }
+ end,
+ })
+ end
- vim.api.nvim_create_autocmd('LspDetach', {
- callback = function()
- vim.lsp.buf.clear_references()
- end,
- })
+ if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_codelens) then
+ vim.lsp.codelens.refresh(opts)
+ vim.api.nvim_create_autocmd({ 'CursorHold', 'InsertLeave' }, {
+ buffer = ev.buf,
+ callback = function()
+ vim.lsp.codelens.refresh(opts)
+ end,
+ })
+ end
end,
})
diff --git a/.config/nvim/lua/lines.lua b/.config/nvim/lua/lines.lua
index 167ed10..3e0b539 100644
--- a/.config/nvim/lua/lines.lua
+++ b/.config/nvim/lua/lines.lua
@@ -24,15 +24,38 @@ end
---@return string
function line.status()
- local buffer = vim.api.nvim_win_get_buf(vim.g.statusline_winid)
+ local window = vim.g.statusline_winid
+ local fillchar
+ if window == vim.api.nvim_get_current_win() then
+ fillchar = vim.opt.fillchars:get()["stl"]
+ else
+ fillchar = vim.opt.fillchars:get()["stlnc"]
+ end
+
+ if fillchar == nil then
+ fillchar = " "
+ end
+
+ local buffer = vim.api.nvim_win_get_buf(window)
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%%"
+
+ if vim.bo[buffer].filetype == "netrw"
+ then
+ return "%f"
+ end
+
+ -- return '%=%-11.S%k%-14.(%l,%c%V%) %P'
+ local ruler = ""
+ if vim.o.ruler then
+ ruler = vim.o.rulerformat
+ if #ruler == 0 then
+ ruler = "%-14.(%l:%c%V%)" .. fillchar .. "%P"
+ end
end
local clients = {}
@@ -48,16 +71,18 @@ function line.status()
end
return table.concat({
- vim.api.nvim_get_mode().mode:upper(),
- line.get_formated_bufname(buffer),
+ '%<%f',
+ '%h%w%m%r',
"%=",
- vim.bo.filetype,
+ vim.bo[buffer].filetype,
cli,
- vim.bo.spelllang,
- vim.bo.fileencoding,
- vim.bo.fileformat,
- a
- }, " ")
+ vim.bo[buffer].spelllang,
+ vim.bo[buffer].fileencoding,
+ vim.bo[buffer].fileformat,
+ '%-12.k',
+ '%S',
+ ruler
+ }, fillchar)
end
---@return string
@@ -84,38 +109,4 @@ function line.tab()
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
diff --git a/.config/nvim/plugin/backports.lua b/.config/nvim/plugin/backports.lua
new file mode 100644
index 0000000..c6ba87b
--- /dev/null
+++ b/.config/nvim/plugin/backports.lua
@@ -0,0 +1,198 @@
+-- backports from nightly to 0.10
+
+-- LSP Stuff
+vim.keymap.set('n', 'grn', function()
+ vim.lsp.buf.rename()
+end)
+
+vim.keymap.set({ 'n', 'x' }, 'gra', function()
+ vim.lsp.buf.code_action()
+end)
+
+vim.keymap.set('n', 'grr', function()
+ vim.lsp.buf.references()
+end)
+
+vim.keymap.set('n', 'gri', function()
+ vim.lsp.buf.implementation()
+end)
+
+vim.keymap.set('n', 'gO', function()
+ vim.lsp.buf.document_symbol()
+end)
+
+vim.keymap.set({ 'i', 's' }, '<C-S>', function()
+ vim.lsp.buf.signature_help()
+end)
+
+-- Terminal AutoSetup
+vim.api.nvim_create_autocmd('TermOpen', {
+ desc = 'Default settings for :terminal buffers',
+ callback = function()
+ vim.bo.modifiable = false
+ vim.bo.undolevels = -1
+ vim.bo.scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback)
+ vim.bo.textwidth = 0
+ vim.wo[0][0].wrap = false
+ vim.wo[0][0].list = false
+ vim.wo[0][0].number = false
+ vim.wo[0][0].relativenumber = false
+ vim.wo[0][0].signcolumn = 'no'
+ vim.wo[0][0].foldcolumn = '0'
+
+ -- This is gross. Proper list options support when?
+ local winhl = vim.o.winhighlight
+ if winhl ~= '' then
+ winhl = winhl .. ','
+ end
+ vim.wo[0][0].winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC'
+ end,
+})
+
+-- Vim Unpaired
+-- ]<Space> and [<Space> not ported
+
+--- Execute a command and print errors without a stacktrace.
+--- @param opts table Arguments to |nvim_cmd()|
+local function cmd(opts)
+ local ok, err = pcall(vim.api.nvim_cmd, opts, {})
+ if not ok then
+ vim.api.nvim_err_writeln(err:sub(#'Vim:' + 1))
+ end
+end
+
+-- Quickfix mappings
+vim.keymap.set('n', '[q', function()
+ cmd({ cmd = 'cprevious', count = vim.v.count1 })
+end, { desc = ':cprevious' })
+
+vim.keymap.set('n', ']q', function()
+ cmd({ cmd = 'cnext', count = vim.v.count1 })
+end, { desc = ':cnext' })
+
+vim.keymap.set('n', '[Q', function()
+ cmd({ cmd = 'crewind', count = vim.v.count ~= 0 and vim.v.count or nil })
+end, { desc = ':crewind' })
+
+vim.keymap.set('n', ']Q', function()
+ cmd({ cmd = 'clast', count = vim.v.count ~= 0 and vim.v.count or nil })
+end, { desc = ':clast' })
+
+vim.keymap.set('n', '[<C-Q>', function()
+ cmd({ cmd = 'cpfile', count = vim.v.count1 })
+end, { desc = ':cpfile' })
+
+vim.keymap.set('n', ']<C-Q>', function()
+ cmd({ cmd = 'cnfile', count = vim.v.count1 })
+end, { desc = ':cnfile' })
+
+-- Location list mappings
+vim.keymap.set('n', '[l', function()
+ cmd({ cmd = 'lprevious', count = vim.v.count1 })
+end, { desc = ':lprevious' })
+
+vim.keymap.set('n', ']l', function()
+ cmd({ cmd = 'lnext', count = vim.v.count1 })
+end, { desc = ':lnext' })
+
+vim.keymap.set('n', '[L', function()
+ cmd({ cmd = 'lrewind', count = vim.v.count ~= 0 and vim.v.count or nil })
+end, { desc = ':lrewind' })
+
+vim.keymap.set('n', ']L', function()
+ cmd({ cmd = 'llast', count = vim.v.count ~= 0 and vim.v.count or nil })
+end, { desc = ':llast' })
+
+vim.keymap.set('n', '[<C-L>', function()
+ cmd({ cmd = 'lpfile', count = vim.v.count1 })
+end, { desc = ':lpfile' })
+
+vim.keymap.set('n', ']<C-L>', function()
+ cmd({ cmd = 'lnfile', count = vim.v.count1 })
+end, { desc = ':lnfile' })
+
+-- Argument list
+vim.keymap.set('n', '[a', function()
+ cmd({ cmd = 'previous', count = vim.v.count1 })
+end, { desc = ':previous' })
+
+vim.keymap.set('n', ']a', function()
+ -- count doesn't work with :next, must use range. See #30641.
+ cmd({ cmd = 'next', range = { vim.v.count1 } })
+end, { desc = ':next' })
+
+vim.keymap.set('n', '[A', function()
+ if vim.v.count ~= 0 then
+ cmd({ cmd = 'argument', count = vim.v.count })
+ else
+ cmd({ cmd = 'rewind' })
+ end
+end, { desc = ':rewind' })
+
+vim.keymap.set('n', ']A', function()
+ if vim.v.count ~= 0 then
+ cmd({ cmd = 'argument', count = vim.v.count })
+ else
+ cmd({ cmd = 'last' })
+ end
+end, { desc = ':last' })
+
+-- Tags
+vim.keymap.set('n', '[t', function()
+ -- count doesn't work with :tprevious, must use range. See #30641.
+ cmd({ cmd = 'tprevious', range = { vim.v.count1 } })
+end, { desc = ':tprevious' })
+
+vim.keymap.set('n', ']t', function()
+ -- count doesn't work with :tnext, must use range. See #30641.
+ cmd({ cmd = 'tnext', range = { vim.v.count1 } })
+end, { desc = ':tnext' })
+
+vim.keymap.set('n', '[T', function()
+ -- count doesn't work with :trewind, must use range. See #30641.
+ cmd({ cmd = 'trewind', range = vim.v.count ~= 0 and { vim.v.count } or nil })
+end, { desc = ':trewind' })
+
+vim.keymap.set('n', ']T', function()
+ -- :tlast does not accept a count, so use :trewind if count given
+ if vim.v.count ~= 0 then
+ cmd({ cmd = 'trewind', range = { vim.v.count } })
+ else
+ cmd({ cmd = 'tlast' })
+ end
+end, { desc = ':tlast' })
+
+vim.keymap.set('n', '[<C-T>', function()
+ -- count doesn't work with :ptprevious, must use range. See #30641.
+ cmd({ cmd = 'ptprevious', range = { vim.v.count1 } })
+end, { desc = ' :ptprevious' })
+
+vim.keymap.set('n', ']<C-T>', function()
+ -- count doesn't work with :ptnext, must use range. See #30641.
+ cmd({ cmd = 'ptnext', range = { vim.v.count1 } })
+end, { desc = ':ptnext' })
+
+-- Buffers
+vim.keymap.set('n', '[b', function()
+ cmd({ cmd = 'bprevious', count = vim.v.count1 })
+end, { desc = ':bprevious' })
+
+vim.keymap.set('n', ']b', function()
+ cmd({ cmd = 'bnext', count = vim.v.count1 })
+end, { desc = ':bnext' })
+
+vim.keymap.set('n', '[B', function()
+ if vim.v.count ~= 0 then
+ cmd({ cmd = 'buffer', count = vim.v.count })
+ else
+ cmd({ cmd = 'brewind' })
+ end
+end, { desc = ':brewind' })
+
+vim.keymap.set('n', ']B', function()
+ if vim.v.count ~= 0 then
+ cmd({ cmd = 'buffer', count = vim.v.count })
+ else
+ cmd({ cmd = 'blast' })
+ end
+end, { desc = ':blast' })