diff --git a/init.lua b/init.lua index b66be43..c3c5215 100644 --- a/init.lua +++ b/init.lua @@ -1,93 +1,50 @@ local keymap = { - leader_key = ';', - - -- Terminal mode ------------------------------------------------------------------------------------ - exit_terminal_mode = '', - toggle_terminal = '', - - -- Normal mode -------------------------------------------------------------------------------------- - telescope_search_for_files_in_working_directory = 'd', - telescope_search_for_previously_opened_files = '', - telescope_live_grep = 'g', - telescope_search_help_pages = 'h', - telescope_search_current_buffer = 'j', - telescope_search_buffers = 'o', - - lsp_rename_symbol = 'rn', - lsp_code_action = 'ca', - lsp_go_to_definition = 'gd', - lsp_go_to_type_definition = 'gt', - lsp_go_to_implementation = 'gi', - lsp_show_references = 'gr', - lsp_hovering_documentation = 'K', - lsp_next_diagnostic = 'j', - lsp_hovering_diagnostics = 'k', - - test_execute_script = 'e', - - navigation_toggle_file_explorer ='', + leader_key = ' ', navigation_move_to_panel_left = '', navigation_move_to_panel_down = '', navigation_move_to_panel_up = '', navigation_move_to_panel_right = '', - formatting_split_line = "s", + exit_terminal_mode = '', + + split_line = "s", --> Splits the current line with comma separated items in paranthesis into multiple lines. --> Works on all types of parenthesis, and is aware of strings. - -- Insert / Selection mode -------------------------------------------------------------------------- - snippet_confirm = '', - snippet_jump_forward = '', - snippet_jump_backward = '', - --> Edit snippets for the current file with the custom S command. - --> Follow the printed instructions on failure. - - debug_continue = 'r', - debug_run_to_cursor = 'c', - debug_toggle_breakpoint = 'b', - debug_clear_breakpoints = 'B', - debug_step_over = '', - debug_step_into = '', - debug_step_out = '', - debug_state = 's', - debug_terminate = 't', - debug_view_expr_value = 'e', - debug_frames = 'f', - + execute_script_leading = "e", -- er: executes .r.sh in bash } -local TAB_WIDTH = 4 -local EXPAND_TAB = true ---@type installed_themes ---local colorscheme = 'slate' -local colorscheme = 'gruvbox' - +local colorscheme = 'habamax' +vim.o.termguicolors = true +vim.cmd('colorscheme ' .. colorscheme) vim.cmd [[ autocmd VimEnter * NoMatchParen ]] vim.g.mapleader = keymap.leader_key vim.g.maplocalleader = keymap.leader_key -vim.opt.tabstop = TAB_WIDTH-- Character width of a tab -vim.opt.shiftwidth = 0-- Will always be eual to the tabstop -vim.opt.rnu = true-- Shows relative line numbers -vim.opt.nu = true-- Shows current line number -vim.opt.wrap = false-- Don't wrap the line. Let it go offscreen. +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 0 +vim.opt.rnu = true +vim.opt.nu = true +vim.opt.wrap = false vim.opt.shiftround = true -vim.opt.expandtab = EXPAND_TAB -vim.opt.hlsearch = false-- Don't highlight searches -vim.opt.incsearch = true-- Highlight matching patterns as the you are typing it. -vim.opt.scrolloff = 8-- Always keep 8 lines of code between the cursor and the top/bottom of the screen. +vim.opt.expandtab = true +vim.opt.hlsearch = false +vim.opt.incsearch = true +vim.opt.scrolloff = 8 + vim.api.nvim_set_option("clipboard", "unnamedplus") + vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_left, 'wincmd h', {silent = true}) vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_down, 'wincmd j', {silent = true}) vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_up, 'wincmd k', {silent = true}) vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_right, 'wincmd l', {silent = true}) - -vim.api.nvim_set_keymap('t', keymap.exit_terminal_mode, '', {silent = true}) vim.api.nvim_set_keymap('t', keymap.navigation_move_to_panel_left, 'wincmd h', {silent = true}) vim.api.nvim_set_keymap('t', keymap.navigation_move_to_panel_down, 'wincmd j', {silent = true}) vim.api.nvim_set_keymap('t', keymap.navigation_move_to_panel_up, 'wincmd k', {silent = true}) vim.api.nvim_set_keymap('t', keymap.navigation_move_to_panel_right, 'wincmd l', {silent = true}) +vim.api.nvim_set_keymap('t', keymap.exit_terminal_mode, '', {silent = true}) vim.cmd [[ autocmd BufEnter * if &buftype == 'terminal' | :startinsert | endif ]] vim.cmd [[ autocmd BufWinLeave *.* silent! mkview ]] @@ -101,266 +58,17 @@ vim.g.python_indent = { -- Fixes retarded default python indentation. closed_paren_align_last_line = false, searchpair_timeout = 300, } + vim.api.nvim_create_autocmd('TextYankPost', { -- Highlights yanked text. desc = 'Highlight when yanking text', group = vim.api.nvim_create_augroup('highlight-yank', {clear = true}), - callback = function() - vim.highlight.on_yank() - end + callback = vim.highlight.on_yank }) vim.o.exrc = true -- Allows project specific .nvim.lua config files. + vim.cmd [[ autocmd FileType * set formatoptions-=cro ]] -- Disable automatic comment. -local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) - vim.cmd [[packadd packer.nvim]] - return true - end - return false -end -local packer_bootstrap = ensure_packer() - -local function packer_startup(use) - use 'wbthomason/packer.nvim' - - use 'nvim-tree/nvim-tree.lua'-- File explorer. - use 'nvim-tree/nvim-web-devicons'-- Provides Pretty icons to look at. Makes the plugin above and below pretty. - use 'nvim-lualine/lualine.nvim'-- Provides file information on status bar on the bottom of the wihdow. - - use 'nvim-treesitter/nvim-treesitter'-- Provides syntax highlighting for many lanugages. - - use 'hrsh7th/nvim-cmp'-- Autocompletion framework - use 'hrsh7th/cmp-nvim-lsp'-- Autocompletion lsp integration - use 'folke/neodev.nvim'-- lsp integration with the nvim lua API - - use 'dcampos/nvim-snippy'-- Snippet engine Handles the actual - -- pasting of lsp suggestions. As well as custom snippets - -- (Custom snippets are awesome) - - use 'dcampos/cmp-snippy'-- nvim-cmp integration - - use {-- LSP - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', - 'neovim/nvim-lspconfig', } - - use {-- FuzzyFind your way through previously open files, or project files. - 'nvim-telescope/telescope.nvim', - branch = '0.1.x', - requires = { {'nvim-lua/plenary.nvim'} } - } - - use 'folke/zen-mode.nvim' -- For centering the text on screen giving a better editing experience in full-screen mode. - - use 'michaeljsmith/vim-indent-object' -- Treats lines of the same indentation as a new text object, access with i and I. - use 'tpope/vim-surround' -- Allows you to surround text with tags, quotes and brackets. - use 'tpope/vim-repeat' -- Needed for above plugin to repeat actions. - - use 'mfussenegger/nvim-dap' - use 'mfussenegger/nvim-dap-python' -- follow instructions or start venv before starting nvim. - use 'theHamsta/nvim-dap-virtual-text' - use 'leoluz/nvim-dap-go' - - use "ellisonleao/gruvbox.nvim" - - use {"akinsho/toggleterm.nvim", tag = '*', config = function() - require("toggleterm").setup{ } - end} - - if packer_bootstrap then --Comes after packages - require('packer').sync() - end - - -- set colors after packer, because colorscheme might be installed - vim.o.termguicolors = true - vim.cmd('colorscheme ' .. colorscheme) - - vim.g.loaded_netrw = 1-- Disables some built in plugin - vim.g.loaded_netrwPlugin = 1--Disables some built in plugin - require'nvim-tree'.setup() - vim.keymap.set('n', keymap.navigation_toggle_file_explorer, 'NvimTreeFindFileToggle', {silent = true}) - - require'lualine'.setup{} - - require('nvim-treesitter.configs').setup { - ensure_installed = 'all', - sync_install = false, - auto_install = true, - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - } - } - - local cmp = require('cmp') - local types = require('cmp.types') - local snippy = require('snippy') - - cmp.setup{ - mapping = { - [''] = { i = cmp.mapping.select_next_item{ behavior = types.cmp.SelectBehavior.Select } }, - [''] = { i = cmp.mapping.select_prev_item{ behavior = types.cmp.SelectBehavior.Select } }, - [keymap.snippet_confirm] = cmp.mapping( - function (_) - cmp.confirm{ select = true } - end, - { "i", "s" } - ), - [keymap.snippet_jump_backward] = cmp.mapping( - function (_) - if snippy.can_jump(-1) then - snippy.previous() - end - end, - { "i", "s" } - ), - [keymap.snippet_jump_forward] = cmp.mapping( - function(_) - if snippy.can_jump(1) then - snippy.next() - end - end, - { "i", "s" } - ), - }, - snippet = { - expand = function(args) - snippy.expand_snippet(args.body) - end, - }, - sources = cmp.config.sources( - { - { name = 'snippy' }, - { name = 'nvim_lsp' }, - }, - {{ name = 'buffer' }} - ) - } - - require('mason').setup() - require('mason-lspconfig').setup{ - ensure_installed = { - 'clangd', - 'kotlin_language_server', - 'ltex', - 'lua_ls', - 'marksman', - 'pyright', - 'rust_analyzer', - 'gopls' - } - } - local capabilities = require('cmp_nvim_lsp').default_capabilities() - require("mason-lspconfig").setup_handlers { - function (server_name) -- default_handler - require("lspconfig")[server_name].setup { - capabilities = capabilities - } - end, - lua_ls = function() - require("neodev").setup{} -- load the neovim api - require("lspconfig").lua_ls.setup { - capabilities = capabilities, - settings = { - Lua = { - runtime = { - version = 'LuaJIT', - }, - workspace = { - checkThirdParty = true, - }, - - } - } - } - end, - } --- * `Lua.runtime.special`: set the property `love.filesystem.load` to `"loadfile"`; --- * `Lua.workspace.library`: add element `"${3rd}/love2d/library"` ; - - require("lspconfig").gdscript.setup{ - capabilities = capabilities - } - require('lspconfig').zls.setup{ - capabilities = capabilities - } - local telescope_builtin = require('telescope.builtin') - vim.keymap.set('n', keymap.lsp_rename_symbol, vim.lsp.buf.rename, {}) - vim.keymap.set('n', keymap.lsp_code_action, vim.lsp.buf.code_action, {}) - vim.keymap.set('n', keymap.lsp_go_to_definition, telescope_builtin.lsp_definitions, {}) - vim.keymap.set('n', keymap.lsp_go_to_type_definition, telescope_builtin.lsp_type_definitions, {}) - vim.keymap.set('n', keymap.lsp_go_to_implementation, telescope_builtin.lsp_implementations, {}) - vim.keymap.set('n', keymap.lsp_show_references, telescope_builtin.lsp_references, {}) - vim.keymap.set('n', keymap.lsp_hovering_documentation, vim.lsp.buf.hover, {}) - vim.keymap.set('n', keymap.lsp_next_diagnostic, vim.diagnostic.goto_next, {}) - vim.keymap.set('n', keymap.lsp_hovering_diagnostics, vim.diagnostic.open_float, {}) - - vim.keymap.set('n', keymap.telescope_search_for_files_in_working_directory, telescope_builtin.find_files, {}) - vim.keymap.set('n', keymap.telescope_search_for_previously_opened_files, telescope_builtin.oldfiles, {}) - vim.keymap.set('n', keymap.telescope_live_grep, telescope_builtin.live_grep, {}) - vim.keymap.set('n', keymap.telescope_search_help_pages, telescope_builtin.help_tags, {}) - vim.keymap.set('n', keymap.telescope_search_current_buffer, telescope_builtin.current_buffer_fuzzy_find, {}) - vim.keymap.set('n', keymap.telescope_search_buffers, telescope_builtin.buffers, {}) - - local dap = require'dap' - local widgets = require('dap.ui.widgets') - local my_sidebar = widgets.sidebar(widgets.scopes) - local my_centered = widgets.centered_float(widgets.frames) - - vim.api.nvim_create_autocmd('VimEnter', { -- Close the middle window that automatically opens for some reason. - desc = 'Close the window floating in the middle as vim opens.', - group = vim.api.nvim_create_augroup('close-dap-frames', {clear = true}), - callback = function() - my_centered.close() - end - }) --TODO change this if I can. Super hacky. - - vim.keymap.set('n', keymap.debug_continue, dap.continue, {}) - vim.keymap.set('n', keymap.debug_toggle_breakpoint, dap.toggle_breakpoint, {}) - vim.keymap.set('n', keymap.debug_clear_breakpoints, dap.clear_breakpoints, {}) - vim.keymap.set('n', keymap.debug_step_over, dap.step_over, {}) - vim.keymap.set('n', keymap.debug_step_into, dap.step_into, {}) - vim.keymap.set('n', keymap.debug_step_out, dap.step_out, {}) - vim.keymap.set('n', keymap.debug_state, my_sidebar.toggle, {}) - vim.keymap.set('n', keymap.debug_frames, my_centered.toggle, {}) - vim.keymap.set('n', keymap.debug_terminate, dap.terminate, {}) - vim.keymap.set('n', keymap.debug_run_to_cursor, dap.run_to_cursor, {}) - vim.keymap.set('n', keymap.debug_view_expr_value, widgets.hover, {}) - - -- More configurations: - -- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#go - require'dap-python'.setup('~/.virtualenvs/debugpy/bin/python') - require'dap-go'.setup() - - - dap.adapters.gdb = { - type = "executable", - command = "gdb", - args = { "-i", "dap" } - } - - dap.configurations.c = { - { - name = "Launch", - type = "gdb", - request = "launch", - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') - end, - cwd = "${workspaceFolder}", - stopAtBeginningOfMainSubprogram = false, - }, - } - - -- nicer debugging. displays variable values inline - -- https://github.com/theHamsta/nvim-dap-virtual-text - require'nvim-dap-virtual-text'.setup{} -end - ---@param name string ---@return boolean local function file_exists(name) @@ -432,9 +140,6 @@ vim.api.nvim_create_user_command( ) ---{ "frames": [ { "filename": "cape", "frame": { "x": 32, "y": 45, "w": 4, "h": 7 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 7 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "cape", "frame": { "x": 12, "y": 46, "w": 5, "h": 5 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 19, "w": 5, "h": 5 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "cape", "frame": { "x": 32, "y": 45, "w": 4, "h": 7 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 7 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 12, "y": 46, "w": 5, "h": 5 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 19, "w": 5, "h": 5 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 37, "y": 45, "w": 4, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 27, "y": 46, "w": 3, "h": 5 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 16, "w": 3, "h": 5 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 22, "y": 46, "w": 4, "h": 4 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 4 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 42, "y": 49, "w": 2, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 18, "w": 2, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 18, "y": 46, "w": 3, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 18, "w": 3, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "cape", "frame": { "x": 72, "y": 43, "w": 12, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 3, "y": 18, "w": 12, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 50, "y": 32, "w": 3, "h": 7 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 3, "h": 7 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 37, "y": 45, "w": 4, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 27, "y": 46, "w": 3, "h": 5 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 16, "w": 3, "h": 5 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 22, "y": 46, "w": 4, "h": 4 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 4 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 42, "y": 49, "w": 2, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 18, "w": 2, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 37, "y": 45, "w": 4, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 27, "y": 46, "w": 3, "h": 5 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 16, "w": 3, "h": 5 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 22, "y": 46, "w": 4, "h": 4 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 1, "y": 17, "w": 4, "h": 4 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "cape", "frame": { "x": 42, "y": 49, "w": 2, "h": 6 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 18, "w": 2, "h": 6 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 1, "y": 31, "w": 10, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 10, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "hero", "frame": { "x": 12, "y": 31, "w": 9, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 9, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "hero", "frame": { "x": 1, "y": 31, "w": 10, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 10, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 12, "y": 31, "w": 9, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 9, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 67, "y": 29, "w": 11, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 3, "y": 11, "w": 11, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 54, "y": 29, "w": 12, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 10, "w": 12, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 42, "y": 16, "w": 11, "h": 15 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 10, "w": 11, "h": 15 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 22, "y": 31, "w": 9, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 9, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 32, "y": 31, "w": 9, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 12, "w": 9, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "hero", "frame": { "x": 23, "y": 1, "w": 19, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 19, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 43, "y": 1, "w": 19, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 19, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 63, "y": 1, "w": 20, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 3, "y": 11, "w": 20, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 63, "y": 15, "w": 20, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 10, "w": 20, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 1, "y": 1, "w": 21, "h": 15 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 10, "w": 21, "h": 15 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 23, "y": 16, "w": 18, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 18, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 63, "y": 1, "w": 20, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 3, "y": 11, "w": 20, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 63, "y": 15, "w": 20, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 10, "w": 20, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 1, "y": 1, "w": 21, "h": 15 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 2, "y": 10, "w": 21, "h": 15 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "hero", "frame": { "x": 23, "y": 16, "w": 18, "h": 14 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 4, "y": 11, "w": 18, "h": 14 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 1000 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 84, "y": 1, "w": 1, "h": 1 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 0, "y": 0, "w": 1, "h": 1 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 61, "y": 43, "w": 10, "h": 9 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 18, "y": 15, "w": 10, "h": 9 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 14, "y": 17, "w": 8, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 11, "y": 11, "w": 8, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 1, "y": 17, "w": 12, "h": 13 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 12, "y": 8, "w": 12, "h": 13 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 42, "y": 32, "w": 7, "h": 16 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 21, "y": 8, "w": 7, "h": 16 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 1, "y": 46, "w": 10, "h": 4 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 15, "y": 6, "w": 10, "h": 4 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 54, "y": 16, "w": 8, "h": 10 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 10, "y": 0, "w": 8, "h": 10 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 50, "y": 43, "w": 10, "h": 10 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 17, "y": 0, "w": 10, "h": 10 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 }, { "filename": "particle", "frame": { "x": 79, "y": 29, "w": 4, "h": 12 }, "rotated": false, "trimmed": true, "spriteSourceSize": { "x": 24, "y": 8, "w": 4, "h": 12 }, "sourceSize": { "w": 28, "h": 25 }, "duration": 100 } ], "meta": { "app": "https://www.aseprite.org/", "version": "1.3.5-x64", "image": "testSprite.ase.png", "format": "I8", "size": { "w": 86, "h": 56 }, "scale": "1", "frameTags": [ { "name": "idle", "from": 0, "to": 1, "direction": "forward", "color": "#000000ff" }, { "name": "laugh", "from": 2, "to": 3, "direction": "forward", "color": "#000000ff" }, { "name": "run", "from": 4, "to": 7, "direction": "forward", "color": "#000000ff" }, { "name": "draw_gun", "from": 8, "to": 10, "direction": "forward", "repeat": "1", "color": "#000000ff" }, { "name": "run_gun", "from": 11, "to": 18, "direction": "forward", "color": "#000000ff" } ], "layers": [ { "name": "cape", "opacity": 255, "blendMode": "normal", "cels": [{ "frame": 1, "color": "#57b9f2ff" }] }, { "name": "hero", "opacity": 255, "blendMode": "normal" }, { "name": "particle", "opacity": 255, "blendMode": "normal", "cels": [{ "frame": 13, "zIndex": -1, "data": "some user data here" }] } ], "slices": [ { "name": "hurtbox", "color": "#0000ffff", "data": "some user data", "keys": [{ "frame": 0, "bounds": {"x": 5, "y": 12, "w": 7, "h": 13 } }, { "frame": 1, "bounds": {"x": 5, "y": 12, "w": 6, "h": 13 } }, { "frame": 2, "bounds": {"x": 5, "y": 12, "w": 7, "h": 13 } }, { "frame": 3, "bounds": {"x": 5, "y": 12, "w": 6, "h": 13 } }, { "frame": 4, "bounds": {"x": 5, "y": 12, "w": 7, "h": 10 } }, { "frame": 5, "bounds": {"x": 5, "y": 11, "w": 6, "h": 11 } }, { "frame": 6, "bounds": {"x": 5, "y": 11, "w": 6, "h": 12 } }, { "frame": 7, "bounds": {"x": 5, "y": 12, "w": 6, "h": 13 } }, { "frame": 8, "bounds": {"x": 5, "y": 13, "w": 6, "h": 12 } }, { "frame": 9, "bounds": {"x": 5, "y": 12, "w": 6, "h": 13 } }, { "frame": 11, "bounds": {"x": 5, "y": 12, "w": 7, "h": 10 } }, { "frame": 12, "bounds": {"x": 5, "y": 11, "w": 6, "h": 11 } }, { "frame": 13, "bounds": {"x": 5, "y": 11, "w": 6, "h": 12 } }, { "frame": 14, "bounds": {"x": 5, "y": 12, "w": 6, "h": 13 } }, { "frame": 15, "bounds": {"x": 5, "y": 12, "w": 7, "h": 10 } }, { "frame": 16, "bounds": {"x": 5, "y": 11, "w": 6, "h": 11 } }, { "frame": 17, "bounds": {"x": 5, "y": 11, "w": 6, "h": 12 } }, { "frame": 18, "bounds": {"x": 5, "y": 12, "w": 6, "h": 13 } }] } ] } } - - do ---Returns function that runs the given script_name in the current working directory. ---Only implemented for Linux. ( Uses the sh command ) @@ -467,44 +172,32 @@ do local char = alphabet:sub(i, i) vim.keymap.set( 'n', - keymap.test_execute_script .. char, + keymap.execute_script_leading .. char, get_run_script_function("." .. char .. ".sh"), { silent = true } ) end end ----Splits the line under the cursor into multiple lines. ----Works on lines with properly opening and closing brackets: (),[],{} ----Starts at the cursor position and moves to the right until it finds an opening bracket. ----Then formats all comma separated items within that bracket scope, and splits the line into multiple. ----The function is aware for strings starting with ' or ", and keeps track of how deeply nested it is ----in the brackets. ----The function will properly indent all the lines, taking into consideration the TAB_WHITESPACE and EXPAND_TAB constants. ----It is currently tied to this init.lua file by a couple of variables. Might become a separate package at some point. ---@type function local split_line do - local TAB_WHITESPACE = '\t' - if EXPAND_TAB then - TAB_WHITESPACE = '' - for _ = 1, TAB_WIDTH do - TAB_WHITESPACE = TAB_WHITESPACE .. ' ' - end - end - local get_closing_bracket = function(char) - if char == '(' then return ')' end - if char == '[' then return ']' end - if char == '{' then return '}' end - error("Not an opening bracket") - end - - ---@param char string - ---@return boolean - local is_opening_bracket = function(char) - return char == '(' or char == '[' or char == '{' - end + -- split_line settings + local SPLIT_WHITESPACE = ' ' + local SPLIT_DELIMETERS = { -- single characters only + [','] = true, + [';'] = true, + } + local SPLIT_BETWEEN = { -- single characters only + ['('] = ')', + ['['] = ']', + ['{'] = '}', + } + local SPLIT_IGNORE_BETWEEN = { --single characters only + ['"'] = '"', + ["'"] = "'", + } split_line = function() local line = vim.api.nvim_get_current_line() @@ -515,7 +208,7 @@ do local first_bracket_i = nil for i = col, #line do local char = line:sub(i, i) - if is_opening_bracket(char) then + if SPLIT_BETWEEN[char] ~= nil then first_bracket_i = i break end @@ -527,35 +220,35 @@ do end ---@type integer[] - local comma_indexes = {} -- Populate this array + 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_string = '' - local in_string = false + local icon_to_close_ignore = '' + local in_ignore = false for i = first_bracket_i, #line do local char = line:sub(i,i) - if in_string then - in_string = not (char == icon_to_close_string) + if in_ignore then + in_ignore = not (char == icon_to_close_ignore) goto continue end - if char == '"' or char == "'" then - icon_to_close_string = char - in_string = true + 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 is_opening_bracket( char ) then + if SPLIT_BETWEEN[char] ~= nil then table.insert( closing_bracket_stack, - get_closing_bracket( char ) + SPLIT_BETWEEN[char] ) end @@ -563,8 +256,8 @@ do table.remove(closing_bracket_stack) end - if #closing_bracket_stack == 1 and char == ',' then - table.insert(comma_indexes, i) + if #closing_bracket_stack == 1 and SPLIT_DELIMETERS[char] then + table.insert(split_indexes, i) end if #closing_bracket_stack == 0 then @@ -579,7 +272,7 @@ do print("The first opening bracket found after the cursor was not closed on this line.") return end - if #comma_indexes == 0 then + if #split_indexes == 0 then print('No comma separated items within brackets that were opened and closed after the cursor.') return end @@ -592,22 +285,28 @@ do local middle_lines = {} table.insert( middle_lines, - line:sub(first_bracket_i+1, comma_indexes[1]) + line:sub(first_bracket_i+1, split_indexes[1]) ) - for i = 1, #comma_indexes-1 do + for i = 1, #split_indexes-1 do table.insert( middle_lines, - line:sub(comma_indexes[i], comma_indexes[i+1]) + line:sub(split_indexes[i], split_indexes[i+1]) ) end table.insert( middle_lines, - line:sub(comma_indexes[#comma_indexes], last_bracket_i-1) + 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("^[%s,]*", leading_whitespace .. TAB_WHITESPACE, 1) + 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 @@ -622,21 +321,11 @@ end vim.keymap.set( 'n', - keymap.formatting_split_line, + keymap.split_line, split_line, { silent = true } ) -vim.keymap.set( - {'n', 't', 'i'}, - keymap.toggle_terminal, - function () - vim.cmd [[ ToggleTerm direction=vertical size=80 ]] - end, - { silent = true } -) - -return require('packer').startup(packer_startup) ---@alias installed_themes ---| 'blue' @@ -660,4 +349,3 @@ return require('packer').startup(packer_startup) ---| 'slate' ---| 'torte' ---| 'zellner' ----| 'gruvbox'