added tab support for split line

This commit is contained in:
Ivar Fatland
2024-04-03 21:37:50 +02:00
parent f838291e30
commit 523cf1f7de
+53 -33
View File
@@ -2,10 +2,12 @@ local keymap = {
leader_key = ';', leader_key = ';',
-- Normal mode -------------------------------------------------------------------------------------- -- Normal mode --------------------------------------------------------------------------------------
telescope_search_for_files_in_working_directory = '<Space>d', telescope_search_for_files_in_working_directory = '<space>d',
telescope_search_for_previously_opened_files = '<Space><Space>', telescope_search_for_previously_opened_files = '<space><space>',
telescope_live_grep = '<Space>g', telescope_live_grep = '<space>g',
telescope_search_help_pages = '<Space>h', telescope_search_help_pages = '<space>h',
telescope_search_current_buffer = '<space>j',
telescope_search_buffers = '<space>o',
lsp_rename_symbol = '<leader>rn', lsp_rename_symbol = '<leader>rn',
lsp_code_action = '<leader>ca', lsp_code_action = '<leader>ca',
@@ -50,26 +52,26 @@ local keymap = {
} }
local TAB_WIDTH = 4 local TAB_WIDTH = 4
local EXPAND_TAB = false
---@type installed_themes ---@type installed_themes
local colorscheme = 'slate' --local colorscheme = 'slate'
local colorscheme = 'gruvbox'
vim.o.termguicolors = true
vim.cmd('colorscheme ' .. colorscheme)
vim.cmd [[ autocmd VimEnter * NoMatchParen ]] vim.cmd [[ autocmd VimEnter * NoMatchParen ]]
vim.g.mapleader = keymap.leader_key vim.g.mapleader = keymap.leader_key
vim.g.maplocalleader = keymap.leader_key vim.g.maplocalleader = keymap.leader_key
vim.opt.tabstop = TAB_WIDTH -- Character width of a tab vim.opt.tabstop = TAB_WIDTH-- Character width of a tab
vim.opt.shiftwidth = 0 -- Will always be eual to the tabstop vim.opt.shiftwidth = 0-- Will always be eual to the tabstop
vim.opt.rnu = true -- Shows relative line numbers vim.opt.rnu = true-- Shows relative line numbers
vim.opt.nu = true -- Shows current line number vim.opt.nu = true-- Shows current line number
vim.opt.wrap = false -- Don't wrap the line. Let it go offscreen. vim.opt.wrap = false-- Don't wrap the line. Let it go offscreen.
vim.opt.shiftround = true vim.opt.shiftround = true
vim.opt.expandtab = true vim.opt.expandtab = EXPAND_TAB
vim.opt.hlsearch = false -- Don't highlight searches vim.opt.hlsearch = false-- Don't highlight searches
vim.opt.incsearch = true -- Highlight matching patterns as the you are typing it. 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.scrolloff = 8-- Always keep 8 lines of code between the cursor and the top/bottom of the screen.
vim.api.nvim_set_option("clipboard", "unnamedplus") vim.api.nvim_set_option("clipboard", "unnamedplus")
vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_left, '<cmd>wincmd h<CR>', {silent = true}) vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_left, '<cmd>wincmd h<CR>', {silent = true})
vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_down, '<cmd>wincmd j<CR>', {silent = true}) vim.api.nvim_set_keymap('n', keymap.navigation_move_to_panel_down, '<cmd>wincmd j<CR>', {silent = true})
@@ -109,21 +111,21 @@ local packer_bootstrap = ensure_packer()
local function packer_startup(use) local function packer_startup(use)
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
use 'nvim-tree/nvim-tree.lua' -- File explorer. 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-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-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 'nvim-treesitter/nvim-treesitter'-- Provides syntax highlighting for many lanugages.
use 'hrsh7th/nvim-cmp' -- Autocompletion framework use 'hrsh7th/nvim-cmp'-- Autocompletion framework
use 'hrsh7th/cmp-nvim-lsp' -- Autocompletion lsp integration use 'hrsh7th/cmp-nvim-lsp'-- Autocompletion lsp integration
use 'folke/neodev.nvim' -- lsp integration with the nvim lua API use 'folke/neodev.nvim'-- lsp integration with the nvim lua API
use 'dcampos/nvim-snippy' -- Snippet engine Handles the actual use 'dcampos/nvim-snippy'-- Snippet engine Handles the actual
-- pasting of lsp suggestions. As well as custom snippets -- pasting of lsp suggestions. As well as custom snippets
-- (Custom snippets are awesome) -- (Custom snippets are awesome)
use 'dcampos/cmp-snippy' -- nvim-cmp integration use 'dcampos/cmp-snippy'-- nvim-cmp integration
use {-- LSP use {-- LSP
'williamboman/mason.nvim', 'williamboman/mason.nvim',
@@ -146,13 +148,18 @@ local function packer_startup(use)
use 'mfussenegger/nvim-dap-python' -- follow instructions or start venv before starting nvim. use 'mfussenegger/nvim-dap-python' -- follow instructions or start venv before starting nvim.
use 'theHamsta/nvim-dap-virtual-text' use 'theHamsta/nvim-dap-virtual-text'
use "ellisonleao/gruvbox.nvim"
if packer_bootstrap then --Comes after packages if packer_bootstrap then --Comes after packages
require('packer').sync() require('packer').sync()
end 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_netrw = 1-- Disables some built in plugin
vim.g.loaded_netrwPlugin = 1 -- Disables some built in plugin vim.g.loaded_netrwPlugin = 1--Disables some built in plugin
require'nvim-tree'.setup() require'nvim-tree'.setup()
vim.keymap.set('n', keymap.navigation_toggle_file_explorer, '<cmd>NvimTreeFindFileToggle<CR>', {silent = true}) vim.keymap.set('n', keymap.navigation_toggle_file_explorer, '<cmd>NvimTreeFindFileToggle<CR>', {silent = true})
@@ -218,7 +225,6 @@ local function packer_startup(use)
ensure_installed = { ensure_installed = {
'clangd', 'clangd',
'kotlin_language_server', 'kotlin_language_server',
'csharp_ls',
'ltex', 'ltex',
'lua_ls', 'lua_ls',
'marksman', 'marksman',
@@ -234,20 +240,27 @@ local function packer_startup(use)
capabilities = capabilities capabilities = capabilities
} }
end, end,
--Lua.workspace.checkThirdParty
lua_ls = function() lua_ls = function()
require("neodev").setup{} -- load the neovim api require("neodev").setup{} -- load the neovim api
require("lspconfig").lua_ls.setup { require("lspconfig").lua_ls.setup {
capabilities = capabilities, capabilities = capabilities,
settings = { settings = {
Lua = { Lua = {
runtime = { version = 'LuaJIT' }, runtime = {
workspace = { checkThirdParty = true }, version = 'LuaJIT',
},
workspace = {
checkThirdParty = true,
},
} }
} }
} }
end, end,
} }
-- * `Lua.runtime.special`: set the property `love.filesystem.load` to `"loadfile"`;
-- * `Lua.workspace.library`: add element `"${3rd}/love2d/library"` ;
require("lspconfig").gdscript.setup{ require("lspconfig").gdscript.setup{
capabilities = capabilities capabilities = capabilities
} }
@@ -268,6 +281,8 @@ local function packer_startup(use)
vim.keymap.set('n', keymap.telescope_search_for_previously_opened_files, builtin.oldfiles, {}) vim.keymap.set('n', keymap.telescope_search_for_previously_opened_files, builtin.oldfiles, {})
vim.keymap.set('n', keymap.telescope_live_grep, builtin.live_grep, {}) vim.keymap.set('n', keymap.telescope_live_grep, builtin.live_grep, {})
vim.keymap.set('n', keymap.telescope_search_help_pages, builtin.help_tags, {}) vim.keymap.set('n', keymap.telescope_search_help_pages, builtin.help_tags, {})
vim.keymap.set('n', keymap.telescope_search_current_buffer, builtin.current_buffer_fuzzy_find, {})
vim.keymap.set('n', keymap.telescope_search_buffers, builtin.buffers, {})
local dap = require'dap' local dap = require'dap'
@@ -413,15 +428,19 @@ end
---Then formats all comma separated items within that bracket scope, and splits the line into multiple. ---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 ---The function is aware for strings starting with ' or ", and keeps track of how deeply nested it is
---in the brackets. ---in the brackets.
---The function will properly indent all the lines, but only uses spaces to do so. ---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. ---It is currently tied to this init.lua file by a couple of variables. Might become a separate package at some point.
---@type function ---@type function
local split_line local split_line
do do
local TAB_WHITESPACE = '' local TAB_WHITESPACE = ' '
if EXPAND_TAB then
print("expandtab is ACTIVE")
TAB_WHITESPACE = ''
for _ = 1, TAB_WIDTH do for _ = 1, TAB_WIDTH do
TAB_WHITESPACE = TAB_WHITESPACE .. ' ' TAB_WHITESPACE = TAB_WHITESPACE .. ' '
end end
end
local get_closing_bracket = function(char) local get_closing_bracket = function(char)
if char == '(' then return ')' end if char == '(' then return ')' end
@@ -582,3 +601,4 @@ return require('packer').startup(packer_startup)
---| 'slate' ---| 'slate'
---| 'torte' ---| 'torte'
---| 'zellner' ---| 'zellner'
---| 'gruvbox'