split things out into multiple files
This commit is contained in:
+46
-504
@@ -8,78 +8,67 @@ vim.g.python3_host_prog = get_python_venv_path()
|
|||||||
|
|
||||||
-- GENERAL SETTINGS {{{1
|
-- GENERAL SETTINGS {{{1
|
||||||
vim.cmd [=[
|
vim.cmd [=[
|
||||||
set autowriteall
|
autocmd BufEnter *__virtual* setlocal buftype=nofile bufhidden=hide noswapfile
|
||||||
set exrc
|
autocmd BufWinEnter *.* silent! loadview
|
||||||
set secure
|
autocmd BufWinLeave *.* silent! mkview
|
||||||
set clipboard=unnamedplus
|
autocmd FileType * setlocal indentexpr=
|
||||||
set tabstop=4
|
autocmd TextYankPost * silent! lua vim.highlight.on_yank {higroup='Visual', timeout=100}
|
||||||
set shiftwidth=0
|
filetype plugin off
|
||||||
set nu
|
inoremap <c-f> <c-x><c-f>
|
||||||
set path=**
|
inoremap <c-o> <c-x><c-o>
|
||||||
set nowrap
|
nnoremap ,a <C-a>
|
||||||
set shiftround
|
nnoremap ,cD :call setqflist(filter(getqflist(), 'v:val != getqflist()[getqflist({"idx": 0}).idx - 1]'))<CR>
|
||||||
set expandtab
|
|
||||||
set incsearch
|
|
||||||
set guicursor=n-v-c:block-Cursor
|
|
||||||
set cursorline
|
|
||||||
set noswapfile
|
|
||||||
set list
|
|
||||||
set tags+=~/tags
|
|
||||||
set grepprg=rg\ --vimgrep\ --hidden\ --smart-case\ -g\ \'!**/tags\'\ -g\ \'!**/.git\'
|
|
||||||
set grepformat=%f:%l:%c:%m
|
|
||||||
|
|
||||||
nnoremap ,co :copen<CR>
|
|
||||||
nnoremap ,cc :cclose<CR>
|
nnoremap ,cc :cclose<CR>
|
||||||
|
nnoremap ,co :copen<CR>
|
||||||
nnoremap ,cq :call setqflist([])<CR>:cclose<CR>
|
nnoremap ,cq :call setqflist([])<CR>:cclose<CR>
|
||||||
nnoremap <c-n> :cnext<CR>zz
|
|
||||||
nnoremap <c-p> :cprevious<CR>zz
|
|
||||||
nnoremap ,cu :colder<CR>
|
|
||||||
nnoremap ,cr :cnewer<CR>
|
nnoremap ,cr :cnewer<CR>
|
||||||
|
nnoremap ,cu :colder<CR>
|
||||||
nnoremap ,h H
|
nnoremap ,h H
|
||||||
nnoremap ,l L
|
nnoremap ,l L
|
||||||
nnoremap H ^
|
nnoremap ,m :wa<CR>:make<CR>
|
||||||
nnoremap L $
|
nnoremap ,rl :checktime<CR>
|
||||||
xnoremap H ^
|
nnoremap ,t <c-w>v<c-w>l:terminal<CR>a
|
||||||
xnoremap L $
|
nnoremap ,x <C-x>
|
||||||
nnoremap <C-a> <Nop>
|
nnoremap <C-a> <Nop>
|
||||||
nnoremap <C-x> <Nop>
|
nnoremap <C-x> <Nop>
|
||||||
nnoremap ,a <C-a>
|
nnoremap <c-d> <c-d>zz
|
||||||
nnoremap ,x <C-x>
|
|
||||||
nnoremap ,rl :checktime<CR>
|
|
||||||
nnoremap ,m :wa<CR>:make<CR>
|
|
||||||
nnoremap <silent> <Esc> :noh<CR><Esc>
|
|
||||||
inoremap <c-o> <c-x><c-o>
|
|
||||||
inoremap <c-f> <c-x><c-f>
|
|
||||||
|
|
||||||
nnoremap ,cD :call setqflist(filter(getqflist(), 'v:val != getqflist()[getqflist({"idx": 0}).idx - 1]'))<CR>
|
|
||||||
|
|
||||||
nnoremap ,t <c-w>v<c-w>l:terminal<CR>a
|
|
||||||
|
|
||||||
" Don't include curdir, it just causes pain.
|
|
||||||
set viewoptions=folds,cursor
|
|
||||||
autocmd BufWinLeave *.* silent! mkview
|
|
||||||
autocmd BufWinEnter *.* silent! loadview
|
|
||||||
|
|
||||||
nnoremap <c-h> <c-w>h
|
nnoremap <c-h> <c-w>h
|
||||||
nnoremap <c-j> <c-w>j
|
nnoremap <c-j> <c-w>j
|
||||||
nnoremap <c-k> <c-w>k
|
nnoremap <c-k> <c-w>k
|
||||||
nnoremap <c-l> <c-w>l
|
nnoremap <c-l> <c-w>l
|
||||||
|
nnoremap <c-n> :cnext<CR>zz
|
||||||
nnoremap <c-d> <c-d>zz
|
nnoremap <c-p> :cprevious<CR>zz
|
||||||
nnoremap <c-u> <c-u>zz
|
nnoremap <c-u> <c-u>zz
|
||||||
|
nnoremap <silent> <Esc> :noh<CR><Esc>
|
||||||
|
nnoremap H ^
|
||||||
|
nnoremap L $
|
||||||
|
set autowriteall
|
||||||
|
set clipboard=unnamedplus
|
||||||
|
set cursorline
|
||||||
|
set expandtab
|
||||||
|
set exrc
|
||||||
|
set grepformat=%f:%l:%c:%m
|
||||||
|
set grepprg=rg\ --vimgrep\ --hidden\ --smart-case\ -g\ \'!**/tags\'\ -g\ \'!**/.git\'
|
||||||
|
set guicursor=n-v-c:block-Cursor
|
||||||
|
set incsearch
|
||||||
|
set list
|
||||||
|
set noswapfile
|
||||||
|
set nowrap
|
||||||
|
set nu
|
||||||
|
set path=**
|
||||||
|
set secure
|
||||||
|
set shiftround
|
||||||
|
set shiftwidth=0
|
||||||
|
set tabstop=4
|
||||||
|
set tags+=~/tags
|
||||||
|
set viewoptions=folds,cursor
|
||||||
tnoremap <c-w>c <c-\><c-n><c-w>c
|
tnoremap <c-w>c <c-\><c-n><c-w>c
|
||||||
|
xnoremap H ^
|
||||||
autocmd TextYankPost * silent! lua vim.highlight.on_yank {higroup='Visual', timeout=100}
|
xnoremap L $
|
||||||
autocmd BufEnter *__virtual* setlocal buftype=nofile bufhidden=hide noswapfile
|
|
||||||
|
|
||||||
" Disable STUPID default rust plugin. And others
|
|
||||||
filetype plugin off
|
|
||||||
|
|
||||||
" remove annoying and bad indentation
|
|
||||||
autocmd FileType * setlocal indentexpr=
|
|
||||||
]=]
|
]=]
|
||||||
|
|
||||||
|
vim.opt.completeopt = { 'menu', 'popup', 'preview', 'fuzzy' }
|
||||||
|
|
||||||
vim.keymap.set('n', ',cf', function()
|
vim.keymap.set('n', ',cf', function()
|
||||||
local qf = vim.fn.getqflist()
|
local qf = vim.fn.getqflist()
|
||||||
for i, item in ipairs(qf) do
|
for i, item in ipairs(qf) do
|
||||||
@@ -118,226 +107,6 @@ vim.api.nvim_create_autocmd({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- FILE SPECIFIC AND AUTOCMDS {{{1
|
|
||||||
local file_specific = {
|
|
||||||
c = function()
|
|
||||||
vim.bo.expandtab = false
|
|
||||||
end,
|
|
||||||
make = function()
|
|
||||||
vim.bo.expandtab = false
|
|
||||||
end,
|
|
||||||
tsv = function()
|
|
||||||
vim.bo.tabstop = 32
|
|
||||||
vim.bo.expandtab = false
|
|
||||||
end,
|
|
||||||
odin = function()
|
|
||||||
vim.bo.expandtab = false
|
|
||||||
end,
|
|
||||||
go = function()
|
|
||||||
vim.bo.expandtab = false
|
|
||||||
end,
|
|
||||||
yaml = function()
|
|
||||||
vim.bo.tabstop = 2
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd('BufEnter', {
|
|
||||||
callback = function()
|
|
||||||
local conf = file_specific[vim.bo.filetype]
|
|
||||||
if conf then conf() end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- CENTER TEXT "zen mode" {{{1
|
|
||||||
do
|
|
||||||
-- one shared statusline looks better for the split.
|
|
||||||
vim.o.laststatus = 3
|
|
||||||
|
|
||||||
local ID = '4f2de2e3-a1bf-481f-919c-7f68ec6511c9'
|
|
||||||
local function is_padding_window(win)
|
|
||||||
local ok, _ = pcall(vim.api.nvim_buf_get_var, vim.api.nvim_win_get_buf(win), ID)
|
|
||||||
return ok
|
|
||||||
end
|
|
||||||
|
|
||||||
local function calculate_padding()
|
|
||||||
local screen_width = vim.o.columns
|
|
||||||
local padding = math.floor((screen_width / 2 - 84 / 2) + 0.5)
|
|
||||||
if padding <= 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
return padding
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_padding_window()
|
|
||||||
local windows = vim.api.nvim_list_wins()
|
|
||||||
for _, win in ipairs(windows) do
|
|
||||||
if is_padding_window(win) then
|
|
||||||
return win
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local padding_buffer = _G[ID]
|
|
||||||
if padding_buffer == nil then
|
|
||||||
padding_buffer = vim.api.nvim_create_buf(false, true)
|
|
||||||
vim.api.nvim_set_option_value('buftype', 'nofile', {buf = padding_buffer})
|
|
||||||
vim.api.nvim_set_option_value('modifiable', false, {buf = padding_buffer})
|
|
||||||
vim.api.nvim_create_autocmd('WinEnter', {
|
|
||||||
callback = function()
|
|
||||||
local curr_buff = vim.api.nvim_get_current_buf()
|
|
||||||
if curr_buff == padding_buffer then
|
|
||||||
if #vim.api.nvim_list_wins() == 1 then
|
|
||||||
vim.cmd"q"
|
|
||||||
end
|
|
||||||
local padding_window = vim.api.nvim_get_current_win()
|
|
||||||
|
|
||||||
vim.cmd"wincmd p"
|
|
||||||
local prev_win = vim.api.nvim_get_current_win()
|
|
||||||
local padding_window_info = vim.fn.getwininfo(padding_window)[1]
|
|
||||||
local prev_win_info = vim.fn.getwininfo(prev_win)[1]
|
|
||||||
if padding_window ~= prev_win and padding_window_info.wincol ~= prev_win_info.wincol then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local windows = vim.api.nvim_list_wins()
|
|
||||||
local leftmost_non_padding_window = nil
|
|
||||||
local min_col = math.huge
|
|
||||||
for _, win in ipairs(windows) do
|
|
||||||
local info = vim.fn.getwininfo(win)[1]
|
|
||||||
if info.wincol < min_col and padding_window_info.wincol < info.wincol then
|
|
||||||
min_col = info.wincol
|
|
||||||
leftmost_non_padding_window = win
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if leftmost_non_padding_window ~= nil then
|
|
||||||
vim.api.nvim_set_current_win(leftmost_non_padding_window)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
vim.api.nvim_create_autocmd('VimResized', {
|
|
||||||
callback = function()
|
|
||||||
local padding_window = get_padding_window()
|
|
||||||
if padding_window ~= nil then
|
|
||||||
local padding = calculate_padding()
|
|
||||||
if padding == nil then
|
|
||||||
vim.api.nvim_win_close(padding_window, true)
|
|
||||||
else
|
|
||||||
vim.api.nvim_win_set_width(padding_window, padding)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
vim.cmd"wincmd ="
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
vim.api.nvim_buf_set_var(padding_buffer, ID, true)
|
|
||||||
_G[ID] = padding_buffer
|
|
||||||
end
|
|
||||||
|
|
||||||
local function toggle_padding()
|
|
||||||
local padding_window = get_padding_window()
|
|
||||||
if padding_window == nil then
|
|
||||||
vim.cmd"only"
|
|
||||||
local padding = calculate_padding()
|
|
||||||
if padding == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local win = vim.api.nvim_open_win(padding_buffer, false, {
|
|
||||||
split = 'left',
|
|
||||||
win = -1,
|
|
||||||
width = padding,
|
|
||||||
})
|
|
||||||
vim.api.nvim_set_option_value('number', false, {win = win})
|
|
||||||
vim.api.nvim_set_option_value('relativenumber', false, {win = win})
|
|
||||||
vim.api.nvim_set_option_value('cursorline', false, {win = win})
|
|
||||||
vim.api.nvim_set_option_value('winfixwidth', true, {win = win})
|
|
||||||
vim.api.nvim_set_option_value("fillchars", "eob: ", { win = win })
|
|
||||||
vim.cmd"wincmd ="
|
|
||||||
else
|
|
||||||
vim.api.nvim_win_close(padding_window, true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.keymap.set('n', ',z', toggle_padding)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- auto select compiler {{{1
|
|
||||||
do
|
|
||||||
local compiler_mapping = {
|
|
||||||
dotnet={'*.csproj', '*.sln'},
|
|
||||||
basedpyright={'requirements.txt', 'pyproject.toml', '.venv'},
|
|
||||||
go={'go.mod'},
|
|
||||||
gcc={'*.c'},
|
|
||||||
['g++']={'*.cpp'},
|
|
||||||
cargo={'Cargo.toml'},
|
|
||||||
zig={'*.zig'}
|
|
||||||
}
|
|
||||||
|
|
||||||
---@param dir string?
|
|
||||||
---@param glob_pattern string
|
|
||||||
---@return boolean
|
|
||||||
local function file_or_folder_exists(dir, glob_pattern)
|
|
||||||
if dir == nil then return false end
|
|
||||||
return vim.fn.globpath(dir, glob_pattern, false, false, false) ~= ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local all_folders_till_root = function()
|
|
||||||
local cwd = vim.fn.getcwd()
|
|
||||||
local folders = {cwd} -- array of all folders from cwd to root
|
|
||||||
for dir in vim.fs.parents(cwd) do
|
|
||||||
table.insert(folders, dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param _ any
|
|
||||||
---@param i integer
|
|
||||||
---@return integer?
|
|
||||||
---@return string?
|
|
||||||
local function iter(_, i)
|
|
||||||
if file_or_folder_exists(folders[i], '.git') then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
i = i + 1
|
|
||||||
local f = folders[i]
|
|
||||||
if f == nil then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
return i, f
|
|
||||||
end
|
|
||||||
|
|
||||||
return iter, nil, 0
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param glob_pattern string
|
|
||||||
---@return boolean
|
|
||||||
local function look_for_file(glob_pattern)
|
|
||||||
for _, dir in all_folders_till_root() do
|
|
||||||
if file_or_folder_exists(dir, glob_pattern) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local function auto_select_compiler()
|
|
||||||
for compiler, glob_patterns in pairs(compiler_mapping) do
|
|
||||||
for _, glob_pattern in ipairs(glob_patterns) do
|
|
||||||
if look_for_file(glob_pattern) then
|
|
||||||
vim.cmd('compiler! '..compiler)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if look_for_file('justfile') then
|
|
||||||
vim.go.makeprg = 'just'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
auto_select_compiler()
|
|
||||||
vim.api.nvim_create_autocmd('DirChanged', {
|
|
||||||
callback = auto_select_compiler,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- LAZY.NVIM BOOTSTRAP {{{1
|
-- LAZY.NVIM BOOTSTRAP {{{1
|
||||||
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
|
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
|
||||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||||
@@ -588,67 +357,8 @@ require'lazy'.setup{ --{{{1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
require'mason-lspconfig'.setup()
|
require'mason-lspconfig'.setup()
|
||||||
vim.opt.completeopt = { 'menu', 'popup', 'preview', 'fuzzy' }
|
|
||||||
|
|
||||||
|
|
||||||
vim.lsp.config.zls = {
|
|
||||||
before_init = function(_, _)
|
|
||||||
vim.g.zig_fmt_autosave = false -- may not be needed anymore?
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
vim.lsp.config.lua_ls = {
|
|
||||||
settings = {
|
|
||||||
Lua = { runtime = { version = 'LuaJIT' } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vim.lsp.config.gopls = {
|
|
||||||
filetypes = { -- unsure if this is entirely correct...
|
|
||||||
'go',
|
|
||||||
'gomod',
|
|
||||||
'gowork',
|
|
||||||
'gotmpl',
|
|
||||||
'html'
|
|
||||||
},
|
|
||||||
settings = {
|
|
||||||
gopls = {
|
|
||||||
templateExtensions = {'html', 'gotmpl'}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vim.lsp.config.basedpyright = {
|
|
||||||
settings = {
|
|
||||||
basedpyright = {
|
|
||||||
analysis = {
|
|
||||||
useLibraryCodeForTypes = true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
vim.lsp.config.sourcekit = {
|
|
||||||
filetypes = {"swift"}
|
|
||||||
}
|
|
||||||
vim.lsp.config.ols = {
|
|
||||||
settings = {
|
|
||||||
verbose=true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do -- turtle config
|
|
||||||
local turtle_server = vim.fn.exepath("turtle-language-server")
|
|
||||||
local node = vim.fn.exepath("node")
|
|
||||||
if turtle_server ~= "" and node ~= "" then
|
|
||||||
vim.lsp.config['turtle-language-server'] = {
|
|
||||||
cmd={ node, turtle_server, '--stdio' },
|
|
||||||
filetypes = { 'turtle', 'ttl' },
|
|
||||||
}
|
|
||||||
vim.lsp.enable('turtle-language-server')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.lsp.enable('gdscript')
|
vim.lsp.enable('gdscript')
|
||||||
vim.lsp.config('hls', {
|
|
||||||
filetypes = { 'haskell', 'lhaskell', 'cabal' },
|
|
||||||
})
|
|
||||||
vim.lsp.enable('hls')
|
vim.lsp.enable('hls')
|
||||||
vim.lsp.enable('sourcekit')
|
vim.lsp.enable('sourcekit')
|
||||||
|
|
||||||
@@ -885,171 +595,3 @@ require'lazy'.setup{ --{{{1
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
do -- split line {{{1
|
|
||||||
local SPLIT_DELIMETERS = { -- single characters only
|
|
||||||
[','] = true,
|
|
||||||
[';'] = true,
|
|
||||||
['|'] = true,
|
|
||||||
}
|
|
||||||
local SPLIT_BETWEEN = { -- single characters only
|
|
||||||
['('] = ')',
|
|
||||||
['['] = ']',
|
|
||||||
['{'] = '}',
|
|
||||||
['<'] = '>',
|
|
||||||
}
|
|
||||||
local SPLIT_IGNORE_BETWEEN = { --single characters only
|
|
||||||
['"'] = '"',
|
|
||||||
["'"] = "'",
|
|
||||||
}
|
|
||||||
|
|
||||||
local split_line = function()
|
|
||||||
local SPLIT_WHITESPACE = ' '
|
|
||||||
if vim.o.expandtab then
|
|
||||||
SPLIT_WHITESPACE = ''
|
|
||||||
for _ = 1, vim.o.tabstop do
|
|
||||||
SPLIT_WHITESPACE = SPLIT_WHITESPACE .. ' '
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local line = vim.api.nvim_get_current_line()
|
|
||||||
local _, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
||||||
col = col + 1 -- Doing this to make it 1-indexed
|
|
||||||
|
|
||||||
---@type integer?
|
|
||||||
local first_bracket_i = nil
|
|
||||||
for i = col, #line do
|
|
||||||
local char = line:sub(i, i)
|
|
||||||
if SPLIT_BETWEEN[char] ~= nil then
|
|
||||||
first_bracket_i = i
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not first_bracket_i then
|
|
||||||
print('No opening brackets found after cursor on this line.')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type integer[]
|
|
||||||
local split_indexes = {} -- Populate this array
|
|
||||||
---@type integer?
|
|
||||||
local last_bracket_i = nil -- And find this index
|
|
||||||
|
|
||||||
do
|
|
||||||
---@type string[]
|
|
||||||
local closing_bracket_stack = {}
|
|
||||||
local icon_to_close_ignore = ''
|
|
||||||
local in_ignore = false
|
|
||||||
|
|
||||||
for i = first_bracket_i, #line do
|
|
||||||
local char = line:sub(i,i)
|
|
||||||
|
|
||||||
if in_ignore then
|
|
||||||
in_ignore = not (char == icon_to_close_ignore)
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
|
|
||||||
if SPLIT_IGNORE_BETWEEN[char] ~= nil then
|
|
||||||
icon_to_close_ignore = SPLIT_IGNORE_BETWEEN[char]
|
|
||||||
in_ignore = true
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
-- string handling complete
|
|
||||||
|
|
||||||
if SPLIT_BETWEEN[char] ~= nil then
|
|
||||||
table.insert(
|
|
||||||
closing_bracket_stack,
|
|
||||||
SPLIT_BETWEEN[char]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
if char == closing_bracket_stack[#closing_bracket_stack] then
|
|
||||||
table.remove(closing_bracket_stack)
|
|
||||||
end
|
|
||||||
|
|
||||||
if #closing_bracket_stack == 1 and SPLIT_DELIMETERS[char] then
|
|
||||||
table.insert(split_indexes, i)
|
|
||||||
end
|
|
||||||
|
|
||||||
if #closing_bracket_stack == 0 then
|
|
||||||
last_bracket_i = i
|
|
||||||
break
|
|
||||||
end
|
|
||||||
::continue::
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not last_bracket_i then
|
|
||||||
print('The first opening bracket found after the cursor was not closed on this line.')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type string
|
|
||||||
local leading_whitespace = string.match(line, '^%s*')
|
|
||||||
local first_line = line:sub(1, first_bracket_i)
|
|
||||||
local last_line = leading_whitespace .. line:sub(last_bracket_i, #line)
|
|
||||||
if #split_indexes == 0 then
|
|
||||||
if (last_bracket_i - first_bracket_i == 1) then return end
|
|
||||||
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
|
|
||||||
line = line:sub(first_bracket_i+1, last_bracket_i-1)
|
|
||||||
local leading_pattern = '^[%s'
|
|
||||||
for k, _ in pairs(SPLIT_DELIMETERS) do
|
|
||||||
leading_pattern = leading_pattern .. k
|
|
||||||
end
|
|
||||||
leading_pattern = leading_pattern .. ']*'
|
|
||||||
line = line:gsub(leading_pattern, leading_whitespace .. SPLIT_WHITESPACE, 1)
|
|
||||||
line = line:gsub('[%s]*$', '', 1)
|
|
||||||
vim.api.nvim_buf_set_lines(0, row-1, row, false, {first_line})
|
|
||||||
vim.api.nvim_buf_set_lines(0, row, row, false, {last_line})
|
|
||||||
vim.api.nvim_buf_set_lines(0, row, row, false, {line})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local middle_lines = {}
|
|
||||||
table.insert(
|
|
||||||
middle_lines,
|
|
||||||
line:sub(first_bracket_i+1, split_indexes[1])
|
|
||||||
)
|
|
||||||
for i = 1, #split_indexes-1 do
|
|
||||||
table.insert(
|
|
||||||
middle_lines,
|
|
||||||
line:sub(split_indexes[i], split_indexes[i+1])
|
|
||||||
)
|
|
||||||
end
|
|
||||||
table.insert(
|
|
||||||
middle_lines,
|
|
||||||
line:sub(split_indexes[#split_indexes], last_bracket_i-1)
|
|
||||||
)
|
|
||||||
|
|
||||||
local leading_pattern = '^[%s'
|
|
||||||
for k, _ in pairs(SPLIT_DELIMETERS) do
|
|
||||||
leading_pattern = leading_pattern .. k
|
|
||||||
end
|
|
||||||
leading_pattern = leading_pattern .. ']*'
|
|
||||||
|
|
||||||
-- Cleanup step
|
|
||||||
for i, middle_line in ipairs(middle_lines) do
|
|
||||||
middle_line = middle_line:gsub(leading_pattern, leading_whitespace .. SPLIT_WHITESPACE, 1)
|
|
||||||
middle_line = middle_line:gsub('[%s]*$', '', 1)
|
|
||||||
middle_lines[i] = middle_line
|
|
||||||
end
|
|
||||||
|
|
||||||
if middle_lines[#middle_lines]:match('^%s*$') ~= nil then
|
|
||||||
table.remove(middle_lines)
|
|
||||||
end
|
|
||||||
|
|
||||||
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
|
|
||||||
vim.api.nvim_buf_set_lines(0, row-1, row, false, {first_line})
|
|
||||||
vim.api.nvim_buf_set_lines(0, row, row, false, {last_line})
|
|
||||||
vim.api.nvim_buf_set_lines(0, row, row, false, middle_lines)
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.keymap.set(
|
|
||||||
'n',
|
|
||||||
',s',
|
|
||||||
split_line,
|
|
||||||
{ silent = true }
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
return {
|
||||||
|
settings = {
|
||||||
|
basedpyright = {
|
||||||
|
analysis = {
|
||||||
|
useLibraryCodeForTypes = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
return {
|
||||||
|
filetypes = { -- unsure if this is entirely correct...
|
||||||
|
'go',
|
||||||
|
'gomod',
|
||||||
|
'gowork',
|
||||||
|
'gotmpl',
|
||||||
|
'html'
|
||||||
|
},
|
||||||
|
settings = {
|
||||||
|
gopls = {
|
||||||
|
templateExtensions = {'html', 'gotmpl'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
return {
|
||||||
|
filetypes = { 'haskell', 'lhaskell', 'cabal' },
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
return {
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
runtime = {
|
||||||
|
version = 'LuaJIT'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
return {
|
||||||
|
settings = {
|
||||||
|
verbose=true,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
return {
|
||||||
|
filetypes = {"swift"}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
return {
|
||||||
|
before_init = function(_, _)
|
||||||
|
vim.g.zig_fmt_autosave = false -- may not be needed anymore?
|
||||||
|
end,
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
local compiler_mapping = {
|
||||||
|
dotnet={'*.csproj', '*.sln'},
|
||||||
|
basedpyright={'requirements.txt', 'pyproject.toml', '.venv'},
|
||||||
|
go={'go.mod'},
|
||||||
|
gcc={'*.c'},
|
||||||
|
['g++']={'*.cpp'},
|
||||||
|
cargo={'Cargo.toml'},
|
||||||
|
zig={'*.zig'}
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param dir string?
|
||||||
|
---@param glob_pattern string
|
||||||
|
---@return boolean
|
||||||
|
local function file_or_folder_exists(dir, glob_pattern)
|
||||||
|
if dir == nil then return false end
|
||||||
|
return vim.fn.globpath(dir, glob_pattern, false, false, false) ~= ''
|
||||||
|
end
|
||||||
|
|
||||||
|
local all_folders_till_root = function()
|
||||||
|
local cwd = vim.fn.getcwd()
|
||||||
|
local folders = {cwd} -- array of all folders from cwd to root
|
||||||
|
for dir in vim.fs.parents(cwd) do
|
||||||
|
table.insert(folders, dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param _ any
|
||||||
|
---@param i integer
|
||||||
|
---@return integer?
|
||||||
|
---@return string?
|
||||||
|
local function iter(_, i)
|
||||||
|
if file_or_folder_exists(folders[i], '.git') then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
i = i + 1
|
||||||
|
local f = folders[i]
|
||||||
|
if f == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return i, f
|
||||||
|
end
|
||||||
|
|
||||||
|
return iter, nil, 0
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param glob_pattern string
|
||||||
|
---@return boolean
|
||||||
|
local function look_for_file(glob_pattern)
|
||||||
|
for _, dir in all_folders_till_root() do
|
||||||
|
if file_or_folder_exists(dir, glob_pattern) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function auto_select_compiler()
|
||||||
|
for compiler, glob_patterns in pairs(compiler_mapping) do
|
||||||
|
for _, glob_pattern in ipairs(glob_patterns) do
|
||||||
|
if look_for_file(glob_pattern) then
|
||||||
|
vim.cmd('compiler! '..compiler)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if look_for_file('justfile') then
|
||||||
|
vim.go.makeprg = 'just'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
auto_select_compiler()
|
||||||
|
vim.api.nvim_create_autocmd('DirChanged', {
|
||||||
|
callback = auto_select_compiler,
|
||||||
|
})
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
local file_specific = {
|
||||||
|
c = function()
|
||||||
|
vim.bo.expandtab = false
|
||||||
|
end,
|
||||||
|
make = function()
|
||||||
|
vim.bo.expandtab = false
|
||||||
|
end,
|
||||||
|
tsv = function()
|
||||||
|
vim.bo.tabstop = 32
|
||||||
|
vim.bo.expandtab = false
|
||||||
|
end,
|
||||||
|
odin = function()
|
||||||
|
vim.bo.expandtab = false
|
||||||
|
end,
|
||||||
|
go = function()
|
||||||
|
vim.bo.expandtab = false
|
||||||
|
end,
|
||||||
|
yaml = function()
|
||||||
|
vim.bo.tabstop = 2
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd('BufEnter', {
|
||||||
|
callback = function()
|
||||||
|
local conf = file_specific[vim.bo.filetype]
|
||||||
|
if conf then conf() end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
local SPLIT_DELIMETERS = { -- single characters only
|
||||||
|
[','] = true,
|
||||||
|
[';'] = true,
|
||||||
|
['|'] = true,
|
||||||
|
}
|
||||||
|
local SPLIT_BETWEEN = { -- single characters only
|
||||||
|
['('] = ')',
|
||||||
|
['['] = ']',
|
||||||
|
['{'] = '}',
|
||||||
|
['<'] = '>',
|
||||||
|
}
|
||||||
|
local SPLIT_IGNORE_BETWEEN = { --single characters only
|
||||||
|
['"'] = '"',
|
||||||
|
["'"] = "'",
|
||||||
|
}
|
||||||
|
|
||||||
|
local split_line = function()
|
||||||
|
local SPLIT_WHITESPACE = ' '
|
||||||
|
if vim.o.expandtab then
|
||||||
|
SPLIT_WHITESPACE = ''
|
||||||
|
for _ = 1, vim.o.tabstop do
|
||||||
|
SPLIT_WHITESPACE = SPLIT_WHITESPACE .. ' '
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local line = vim.api.nvim_get_current_line()
|
||||||
|
local _, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
col = col + 1 -- Doing this to make it 1-indexed
|
||||||
|
|
||||||
|
---@type integer?
|
||||||
|
local first_bracket_i = nil
|
||||||
|
for i = col, #line do
|
||||||
|
local char = line:sub(i, i)
|
||||||
|
if SPLIT_BETWEEN[char] ~= nil then
|
||||||
|
first_bracket_i = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not first_bracket_i then
|
||||||
|
print('No opening brackets found after cursor on this line.')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type integer[]
|
||||||
|
local split_indexes = {} -- Populate this array
|
||||||
|
---@type integer?
|
||||||
|
local last_bracket_i = nil -- And find this index
|
||||||
|
|
||||||
|
do
|
||||||
|
---@type string[]
|
||||||
|
local closing_bracket_stack = {}
|
||||||
|
local icon_to_close_ignore = ''
|
||||||
|
local in_ignore = false
|
||||||
|
|
||||||
|
for i = first_bracket_i, #line do
|
||||||
|
local char = line:sub(i,i)
|
||||||
|
|
||||||
|
if in_ignore then
|
||||||
|
in_ignore = not (char == icon_to_close_ignore)
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
|
if SPLIT_IGNORE_BETWEEN[char] ~= nil then
|
||||||
|
icon_to_close_ignore = SPLIT_IGNORE_BETWEEN[char]
|
||||||
|
in_ignore = true
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
-- string handling complete
|
||||||
|
|
||||||
|
if SPLIT_BETWEEN[char] ~= nil then
|
||||||
|
table.insert(
|
||||||
|
closing_bracket_stack,
|
||||||
|
SPLIT_BETWEEN[char]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if char == closing_bracket_stack[#closing_bracket_stack] then
|
||||||
|
table.remove(closing_bracket_stack)
|
||||||
|
end
|
||||||
|
|
||||||
|
if #closing_bracket_stack == 1 and SPLIT_DELIMETERS[char] then
|
||||||
|
table.insert(split_indexes, i)
|
||||||
|
end
|
||||||
|
|
||||||
|
if #closing_bracket_stack == 0 then
|
||||||
|
last_bracket_i = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not last_bracket_i then
|
||||||
|
print('The first opening bracket found after the cursor was not closed on this line.')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type string
|
||||||
|
local leading_whitespace = string.match(line, '^%s*')
|
||||||
|
local first_line = line:sub(1, first_bracket_i)
|
||||||
|
local last_line = leading_whitespace .. line:sub(last_bracket_i, #line)
|
||||||
|
if #split_indexes == 0 then
|
||||||
|
if (last_bracket_i - first_bracket_i == 1) then return end
|
||||||
|
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
line = line:sub(first_bracket_i+1, last_bracket_i-1)
|
||||||
|
local leading_pattern = '^[%s'
|
||||||
|
for k, _ in pairs(SPLIT_DELIMETERS) do
|
||||||
|
leading_pattern = leading_pattern .. k
|
||||||
|
end
|
||||||
|
leading_pattern = leading_pattern .. ']*'
|
||||||
|
line = line:gsub(leading_pattern, leading_whitespace .. SPLIT_WHITESPACE, 1)
|
||||||
|
line = line:gsub('[%s]*$', '', 1)
|
||||||
|
vim.api.nvim_buf_set_lines(0, row-1, row, false, {first_line})
|
||||||
|
vim.api.nvim_buf_set_lines(0, row, row, false, {last_line})
|
||||||
|
vim.api.nvim_buf_set_lines(0, row, row, false, {line})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local middle_lines = {}
|
||||||
|
table.insert(
|
||||||
|
middle_lines,
|
||||||
|
line:sub(first_bracket_i+1, split_indexes[1])
|
||||||
|
)
|
||||||
|
for i = 1, #split_indexes-1 do
|
||||||
|
table.insert(
|
||||||
|
middle_lines,
|
||||||
|
line:sub(split_indexes[i], split_indexes[i+1])
|
||||||
|
)
|
||||||
|
end
|
||||||
|
table.insert(
|
||||||
|
middle_lines,
|
||||||
|
line:sub(split_indexes[#split_indexes], last_bracket_i-1)
|
||||||
|
)
|
||||||
|
|
||||||
|
local leading_pattern = '^[%s'
|
||||||
|
for k, _ in pairs(SPLIT_DELIMETERS) do
|
||||||
|
leading_pattern = leading_pattern .. k
|
||||||
|
end
|
||||||
|
leading_pattern = leading_pattern .. ']*'
|
||||||
|
|
||||||
|
-- Cleanup step
|
||||||
|
for i, middle_line in ipairs(middle_lines) do
|
||||||
|
middle_line = middle_line:gsub(leading_pattern, leading_whitespace .. SPLIT_WHITESPACE, 1)
|
||||||
|
middle_line = middle_line:gsub('[%s]*$', '', 1)
|
||||||
|
middle_lines[i] = middle_line
|
||||||
|
end
|
||||||
|
|
||||||
|
if middle_lines[#middle_lines]:match('^%s*$') ~= nil then
|
||||||
|
table.remove(middle_lines)
|
||||||
|
end
|
||||||
|
|
||||||
|
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
vim.api.nvim_buf_set_lines(0, row-1, row, false, {first_line})
|
||||||
|
vim.api.nvim_buf_set_lines(0, row, row, false, {last_line})
|
||||||
|
vim.api.nvim_buf_set_lines(0, row, row, false, middle_lines)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set(
|
||||||
|
'n',
|
||||||
|
',s',
|
||||||
|
split_line,
|
||||||
|
{ silent = true }
|
||||||
|
)
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
-- one shared statusline looks better for the split.
|
||||||
|
vim.o.laststatus = 3
|
||||||
|
|
||||||
|
local ID = '4f2de2e3-a1bf-481f-919c-7f68ec6511c9'
|
||||||
|
local function is_padding_window(win)
|
||||||
|
local ok, _ = pcall(vim.api.nvim_buf_get_var, vim.api.nvim_win_get_buf(win), ID)
|
||||||
|
return ok
|
||||||
|
end
|
||||||
|
|
||||||
|
local function calculate_padding()
|
||||||
|
local screen_width = vim.o.columns
|
||||||
|
local padding = math.floor((screen_width / 2 - 84 / 2) + 0.5)
|
||||||
|
if padding <= 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return padding
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_padding_window()
|
||||||
|
local windows = vim.api.nvim_list_wins()
|
||||||
|
for _, win in ipairs(windows) do
|
||||||
|
if is_padding_window(win) then
|
||||||
|
return win
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local padding_buffer = _G[ID]
|
||||||
|
if padding_buffer == nil then
|
||||||
|
padding_buffer = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_set_option_value('buftype', 'nofile', {buf = padding_buffer})
|
||||||
|
vim.api.nvim_set_option_value('modifiable', false, {buf = padding_buffer})
|
||||||
|
vim.api.nvim_create_autocmd('WinEnter', {
|
||||||
|
callback = function()
|
||||||
|
local curr_buff = vim.api.nvim_get_current_buf()
|
||||||
|
if curr_buff == padding_buffer then
|
||||||
|
if #vim.api.nvim_list_wins() == 1 then
|
||||||
|
vim.cmd"q"
|
||||||
|
end
|
||||||
|
local padding_window = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
|
vim.cmd"wincmd p"
|
||||||
|
local prev_win = vim.api.nvim_get_current_win()
|
||||||
|
local padding_window_info = vim.fn.getwininfo(padding_window)[1]
|
||||||
|
local prev_win_info = vim.fn.getwininfo(prev_win)[1]
|
||||||
|
if padding_window ~= prev_win and padding_window_info.wincol ~= prev_win_info.wincol then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local windows = vim.api.nvim_list_wins()
|
||||||
|
local leftmost_non_padding_window = nil
|
||||||
|
local min_col = math.huge
|
||||||
|
for _, win in ipairs(windows) do
|
||||||
|
local info = vim.fn.getwininfo(win)[1]
|
||||||
|
if info.wincol < min_col and padding_window_info.wincol < info.wincol then
|
||||||
|
min_col = info.wincol
|
||||||
|
leftmost_non_padding_window = win
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if leftmost_non_padding_window ~= nil then
|
||||||
|
vim.api.nvim_set_current_win(leftmost_non_padding_window)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_autocmd('VimResized', {
|
||||||
|
callback = function()
|
||||||
|
local padding_window = get_padding_window()
|
||||||
|
if padding_window ~= nil then
|
||||||
|
local padding = calculate_padding()
|
||||||
|
if padding == nil then
|
||||||
|
vim.api.nvim_win_close(padding_window, true)
|
||||||
|
else
|
||||||
|
vim.api.nvim_win_set_width(padding_window, padding)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.cmd"wincmd ="
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_var(padding_buffer, ID, true)
|
||||||
|
_G[ID] = padding_buffer
|
||||||
|
end
|
||||||
|
|
||||||
|
local function toggle_padding()
|
||||||
|
local padding_window = get_padding_window()
|
||||||
|
if padding_window == nil then
|
||||||
|
vim.cmd"only"
|
||||||
|
local padding = calculate_padding()
|
||||||
|
if padding == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local win = vim.api.nvim_open_win(padding_buffer, false, {
|
||||||
|
split = 'left',
|
||||||
|
win = -1,
|
||||||
|
width = padding,
|
||||||
|
})
|
||||||
|
vim.api.nvim_set_option_value('number', false, {win = win})
|
||||||
|
vim.api.nvim_set_option_value('relativenumber', false, {win = win})
|
||||||
|
vim.api.nvim_set_option_value('cursorline', false, {win = win})
|
||||||
|
vim.api.nvim_set_option_value('winfixwidth', true, {win = win})
|
||||||
|
vim.api.nvim_set_option_value("fillchars", "eob: ", { win = win })
|
||||||
|
vim.cmd"wincmd ="
|
||||||
|
else
|
||||||
|
vim.api.nvim_win_close(padding_window, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('n', ',z', toggle_padding)
|
||||||
Reference in New Issue
Block a user