kickstart.nvim/init.lua             =>           .dotfiles/.config/nvim/init.lua
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
44: P.S. You can delete this when you're done too. It's your config now :) 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

vim.cmd([[set guifont=CaskaydiaCove\ NF\ Mono:h26]])
-- [[ Install `lazy.nvim` plugin manager ]]
--    https://github.com/folke/lazy.nvim
--    `:help lazy.nvim.txt` for more info

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
61: if not vim.loop.fs_stat(lazypath) then 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
end
vim.opt.rtp:prepend(lazypath)

local function grabColor(name, at)
  local tmp = vim.api.nvim_get_hl(0, {name = name})
  return string.format('#%x', tmp[at])
end

local bgColor = "NONE"
local tern = function (cond, t, f)
  if cond then return t else return f end
end

-- helper function for ToggleColor
local winSetHighlights = function(colorSet, accentBgColor)
  vim.api.nvim_set_hl(0, 'Normal', { bg = colorSet })
  vim.api.nvim_set_hl(0, 'NormalFloat', { bg = colorSet })
  vim.api.nvim_set_hl(0, 'Cursor', { reverse = true })
  vim.api.nvim_set_hl(0, 'CursorLineNr',{ fg = grabColor('DraculaYellow', 'fg')})
  vim.api.nvim_set_hl(0, 'CursorLine',{ bg = tern(bgColor == "NONE", "NONE", accentBgColor) })
  vim.api.nvim_set_hl(0, 'ColorColumn',{ bg = tern(bgColor == "NONE", "NONE", accentBgColor) })
  vim.api.nvim_set_hl(0, 'TabLine',{ bg = colorSet, fg = grabColor('DraculaPurple', 'fg')})
  vim.api.nvim_set_hl(0, 'TabLineFill',{ bg = colorSet })
  vim.api.nvim_set_hl(0, 'WinSeparator',{ bg = colorSet })
  vim.api.nvim_set_hl(0, 'Folded',{ fg = grabColor('DraculaBoundary', 'fg'), bg = tern(bgColor == "NONE", "NONE", accentBgColor) })
end

-- helper function for ToggleColor
local setupLualine = function (colorSet)
  local conditionalColors = {
    interactive = { bg = grabColor('DraculaBgLight', 'bg') },
    visual = { bg = grabColor('DraculaYellow', 'fg'), fg = colorSet },
    insert = { bg = grabColor('DraculaPurple', 'fg') },
    terminal = { bg = grabColor('DraculaGreen', 'fg'), fg = colorSet },
    command = { bg = grabColor('DraculaPink', 'fg') },
    replace = { bg = "#ad2424" },
    normal = { bg = tern(bgColor == "NONE", 'white', grabColor('DraculaBgLight', 'bg')) },
  }

  local function lualine_segment_colors(cols)
    local textCol = tern(cols.fg == nil, "white", cols.fg)
    if bgColor == "NONE" then
      return {
        a = { fg = cols.bg, bg = colorSet, gui = "bold" },
        b = { fg = cols.bg, bg = colorSet },
        c = { bg = colorSet },
        x = { bg = colorSet },
        y = { fg = cols.bg, bg = colorSet },
        z = { fg = cols.bg, bg = colorSet }
      }
    else
      return {
        a = { fg = textCol, bg = cols.bg, gui = "bold" },
        b = { fg = "white", bg = grabColor('DraculaBgLighter', 'bg') },
        c = { bg = grabColor('DraculaBgDark', 'bg') },
        x = { bg = grabColor('DraculaBgDark', 'bg') },
        y = { fg = "white", bg = grabColor('DraculaBgLighter', 'bg') },
        z = { fg = textCol, bg = cols.bg }
      }
    end
  end

  local lualine_theme = {}

  for k, v in pairs(conditionalColors) do
    lualine_theme[k] = lualine_segment_colors(v)
  end
  require('lualine').setup {
    options = {
      theme = lualine_theme
    }
  }
end

local _solidBgColor = nil
local solidBgColor = function ()
  if _solidBgColor == nil then
    local ok, mod = pcall(require, 'vimbgcol')
    if not ok then _solidBgColor = grabColor('draculabgdarker', 'bg')
    else _solidBgColor = mod end
  end

  return _solidBgColor
end
-- Toggles wether or not nvim has transparent background
local ToggleColor = function ()
  local lighterCol = "NONE"
  if bgColor == "NONE" then

    bgColor = solidBgColor()
    local _, _, r, g, b = string.find(bgColor, '^#(%x%x)(%x%x)(%x%x)')
    r, g, b =
      math.floor(tonumber(r, 16) * 0.75),
      math.floor(tonumber(g, 16) * 0.75),
      math.floor(tonumber(b, 16) * 0.75)
    lighterCol = [[#]] .. string.format('%02x', r) .. string.format('%02x', g) .. string.format('%02x', b)
  else bgColor = "NONE" end
  winSetHighlights(bgColor, lighterCol)
  setupLualine(bgColor)
end
-- [[ Configure plugins ]]
-- NOTE: Here is where you install your plugins.
--  You can configure plugins using the `config` key.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
174: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  -- Detect tabstop and shiftwidth automatically
  'tpope/vim-sleuth',

  -- database explorer like PGADmin, but native to NVIM
  'tpope/vim-dadbod',

  -- UI tool for dadbod
  'kristijanhusak/vim-dadbod-ui',

  -- completion tool for dadbod
  'kristijanhusak/vim-dadbod-completion',

  -- Vim be good game. Practise getting good at the basic vim movements
  'ThePrimeagen/vim-be-good',

  -- vim tmux window move intregration
  {
    "christoomey/vim-tmux-navigator",
    cmd = {
      "TmuxNavigateLeft",
      "TmuxNavigateDown",
      "TmuxNavigateUp",
      "TmuxNavigateRight",
      "TmuxNavigatePrevious",
    },
    keys = {
      { "<c-h>", "<cmd><C-U>TmuxNavigateLeft<cr>" },
      { "<c-j>", "<cmd><C-U>TmuxNavigateDown<cr>" },
      { "<c-k>", "<cmd><C-U>TmuxNavigateUp<cr>" },
      { "<c-l>", "<cmd><C-U>TmuxNavigateRight<cr>" },
      { "<c-\\>", "<cmd><C-U>TmuxNavigatePrevious<cr>" },
    },
  },
  -- NOTE: This is where your plugins related to LSP can be installed.
  --  The configuration is done below. Search for lspconfig to find it below.
  {

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
251: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    },
  },

  -- Debugger plugin for neovim
  {
    'rcarriga/nvim-dap-ui',
    dependencies = {
      'mfussenegger/nvim-dap',
    },
  },

  -- shows little variable values inline in buffer as the debugger is running
  'theHamsta/nvim-dap-virtual-text',

  -- vim commands in the middle of the screen
  {
    'VonHeikemen/fine-cmdline.nvim',
    dependencies = {
      'MunifTanjim/nui.nvim',
    }
  },
  -- Ollama intregration into nvim
  'David-Kunz/gen.nvim',

  -- Useful plugin to show you pending keybinds.
  -- the empty opts is necessary
  { 'folke/which-key.nvim', opts = {} },
  {
    -- Adds git related signs to the gutter, as well as utilities for managing changes

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
281: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    opts = {
      -- See `:help gitsigns.txt`
      signs = {
        add = { text = '+' },
        change = { text = '~' },
        add = { text = '' },
        change = { text = '' },
        delete = { text = '_' },
        topdelete = { text = '‾' },
        changedelete = { text = '~' },

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
295: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
          opts.buffer = bufnr
          vim.keymap.set(mode, l, r, opts)
        end

        -- Navigation
        map({ 'n', 'v' }, ']c', function()
          if vim.wo.diff then
            return ']c'
          end
          vim.schedule(function()
            gs.next_hunk()
          end)
          return '<Ignore>'
        end, { expr = true, desc = 'Jump to next hunk' })

        map({ 'n', 'v' }, '[c', function()
          if vim.wo.diff then
            return '[c'
          end
          vim.schedule(function()
            gs.prev_hunk()
          end)
          return '<Ignore>'
        end, { expr = true, desc = 'Jump to previous hunk' })

        -- Actions
        -- visual mode
        map('v', '<leader>hs', function()
        map('v', '<leader>ga', function()
          gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' }
        end, { desc = 'stage git hunk' })
        map('v', '<leader>hr', function()
        end, { desc = '[G]it [A]dd/stage hunk' })
        map('v', '<leader>gr', function()
          gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' }
        end, { desc = 'reset git hunk' })
        end, { desc = '[G]it [R]eset hunk' })
        -- normal mode
        map('n', '<leader>hs', gs.stage_hunk, { desc = 'git stage hunk' })
        map('n', '<leader>hr', gs.reset_hunk, { desc = 'git reset hunk' })
        map('n', '<leader>hS', gs.stage_buffer, { desc = 'git Stage buffer' })
        map('n', '<leader>hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' })
        map('n', '<leader>hR', gs.reset_buffer, { desc = 'git Reset buffer' })
        map('n', '<leader>hp', gs.preview_hunk, { desc = 'preview git hunk' })
        map('n', '<leader>hb', function()
          gs.blame_line { full = false }
        end, { desc = 'git blame line' })
        map('n', '<leader>hd', gs.diffthis, { desc = 'git diff against index' })
        map('n', '<leader>hD', function()
          gs.diffthis '~'
        end, { desc = 'git diff against last commit' })

        map('n', '<leader>k', gs.prev_hunk, { buffer = bufnr, desc = 'Go to previous Hunk' })
        map('n', '<leader>j', gs.next_hunk, { buffer = bufnr, desc = 'Go to next Hunk' })
        map('n', '<leader>ga', gs.stage_hunk, { buffer = bufnr, desc = '[G]it [A]dd/stage hunk' })
        map('n', '<leader>gA', gs.stage_buffer, { buffer = bufnr, desc = '[G]it add [A]ll hunks in buffer' })
        map('n', '<leader>gu', gs.undo_stage_hunk, { buffer = bufnr, desc = '[G]it [U]ndo hunk' })
        map('n', '<leader>gr', gs.reset_hunk, { buffer = bufnr, desc = '[G]it [R]eset hunk' })
        map('n', '<leader>go', gs.preview_hunk_inline, { buffer = bufnr, desc = '[G]it [O]pen preview of hunk' })
        map('n', '<leader>gc', [[:Git commit<CR>]], { buffer = bufnr, desc = '[G]it [C]ommit' })
        map('n', '<leader>gp', [[:Git push<CR>]], { buffer = bufnr, desc = '[G]it [P]ush' })
        -- Toggles
        map('n', '<leader>tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' })
        map('n', '<leader>td', gs.toggle_deleted, { desc = 'toggle git show deleted' })

        -- Text object
        map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', { desc = 'select git hunk' })
        map('n', '<leader>gt', gs.toggle_current_line_blame, { buffer = bufnr, desc = '[G]it [T]oggle line blame' })
      end,
    },
  },

  -- gives background colors to strings like "#6C7C2D" or "color: darkcyan"
  'brenoprata10/nvim-highlight-colors',

  {
    -- Theme inspired by Atom
    'navarasu/onedark.nvim',
    priority = 1000,
    -- setting the theme
     'dracula/vim',
     priority = 1000,
    lazy = false,
    config = function()
      require('onedark').setup {
        -- Set a style preset. 'dark' is default.
        style = 'dark', -- dark, darker, cool, deep, warm, warmer, light
      }
      require('onedark').load()
    end,
       vim.cmd.colorscheme 'dracula'
       winSetHighlights(bgColor)
     end,
  },

  {

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
341: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
      options = {
        icons_enabled = false,
        theme = 'auto',
        component_separators = '|',
        component_separators = '',
        section_separators = '',
      },
      sections = {
        lualine_a = {'filename'},
        lualine_b = {'filetype'},
        lualine_c = {'diagnostics'},
        lualine_x = {'diff'},
        lualine_y = {'branch'},
        lualine_z = {'fileformat', 'encoding'}
      },
      inactive_sections = {
        lualine_a = {'filename'},
        lualine_b = {},
        lualine_c = {},
        lualine_x = {},
        lualine_y = {},
        lualine_z = {'filetype'}
      }
    },
  },


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
373: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  },

  -- "gc" to comment visual regions/lines
  { 'numToStr/Comment.nvim', opts = {} },
  { 'numToStr/Comment.nvim', opts = {
      opleader = { line = '<leader>com', block = '<leader>bcom' },
  } },

  -- Fuzzy Finder (files, lsp, etc)
  -- Remeber to install ripgrep in administer terminal `choco install ripgrep`
  {
    'nvim-telescope/telescope.nvim',
    branch = '0.1.x',
    dependencies = {
      'nvim-lua/plenary.nvim',
      'BurntSushi/ripgrep',
      'debugloop/telescope-undo.nvim',
      -- Fuzzy Finder Algorithm which requires local dependencies to be built.
      -- Only load if `make` is available. Make sure you have the system
      -- requirements installed.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
399: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
        end,
      },
    },
    config = function()
      require("telescope").load_extension("undo")
      vim.keymap.set("n", "<leader>u", [[:Telescope undo<CR>]])
    end,
  },
  -- tag completion for html tags or react components starting with <something
  {
    'windwp/nvim-ts-autotag',
    ft = {
      'javascript',
      'javascriptreact',
      'typescript',
      'typescriptreact',
    },
    config= function ()
      require('nvim-ts-autotag').setup()
    end
  },

  {

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
423: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    'nvim-treesitter/nvim-treesitter',
    dependencies = {
      'nvim-treesitter/nvim-treesitter-textobjects',
      'nvim-treesitter/nvim-treesitter-context',
    },
    build = ':TSUpdate',
    compilers = { "clang" },
  },

  -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
435: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  -- require 'kickstart.plugins.autoformat',
  -- require 'kickstart.plugins.debug',

  -- plugin for reliably closing other buffers than current
  "Asheq/close-buffers.vim",

  -- code runner for inline feedback for interpreted languages like js, python and lua
  {
    -- '0x100101/lab.nvim' fork
    'Edvid/lab.nvim',
    build = 'cd js && npm ci',
    dependencies =  {
      'nvim-lua/plenary.nvim',
    },
  }

  -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
  --    You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
  --    up-to-date with whatever is in the kickstart repo.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
462: require('lazy').setup({ 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-- NOTE: You can change these options as you wish!

-- Set highlight on search
vim.o.hlsearch = false
vim.o.hlsearch = true

vim.keymap.set('n', '<leader>h', function ()
  vim.o.hlsearch = not vim.o.hlsearch
end, { silent = true })

-- Make line numbers default
vim.wo.number = true

-- Make line numbers relative
vim.wo.relativenumber = true

-- Make cursor away from very top and very bottom of screen
vim.wo.scrolloff = 6

-- Enable mouse mode
vim.o.mouse = 'a'


━━━━━━━━━━━━━━━━━━━━━━━━━━━━
498: vim.o.smartcase = true 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-- Keep signcolumn on by default
vim.wo.signcolumn = 'yes'

-- Decrease update time
vim.o.updatetime = 250
vim.o.timeoutlen = 300
vim.o.timeoutlen = 1200

-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
507: vim.o.completeopt = 'menuone,noselect' 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-- NOTE: You should make sure your terminal supports this
vim.o.termguicolors = true

-- nvim-cmp setup for sql stuff
vim.cmd([[autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })]])


-- [[ Basic Keymaps ]]

-- Keymaps for better default experience

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
524: vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = tr 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
vim.keymap.set('n', '<leader>do', vim.diagnostic.open_float, { desc = '[D]iagnostics [O]pen float' })
vim.keymap.set('n', '<leader>dd', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })

-- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()`

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
551: require('telescope').setup { 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  },
}

require('ibl').setup {
  indent = { char = "┆" },
}
-- Enable telescope fzf native, if installed
pcall(require('telescope').load_extension, 'fzf')


━━━━━━━━━
593: end 
━━━━━━━━━

vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})



-- local lualine_theme = require('lualine.themes.auto')
setupLualine()

require('lab').setup { }
-- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader>o', require('telescope.builtin').oldfiles, { desc = '[O]pen recently opened files' })
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader>/', function()
vim.keymap.set('n', '<leader>ss', function()
  -- You can pass additional configuration to telescope to change theme, layout, etc.
  require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
    winblend = 10,
    previewer = false,
  })
end, { desc = '[/] Fuzzily search in current buffer' })
end, { desc = '[S]earch in thi[s] buffer' })

local function telescope_live_grep_open_files()
  require('telescope.builtin').live_grep {

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
616: local function telescope_live_grep_open_files() 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    prompt_title = 'Live Grep in Open Files',
  }
end
vim.keymap.set('n', '<leader>s/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' })
vim.keymap.set('n', '<leader>ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' })
vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' })
vim.keymap.set('n', '<leader>sG', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' })
vim.keymap.set('n', '<leader>sT', require('telescope.builtin').builtin, { desc = '[S]earch  [T]elescope built ins' })
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').git_files, { desc = '[S]earch [G]it Files' })
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' })
vim.keymap.set('n', '<leader>sC', require('telescope.builtin').live_grep, { desc = '[S]earch [C]ontents' })
vim.keymap.set('n', '<leader>sc', ':LiveGrepGitRoot<cr>', { desc = '[S]earch [c]ontents in Git Root' })
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
-- vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
vim.keymap.set('n', '<leader>sx', require('telescope.builtin').commands, { desc = '[S]earch commands/e[X]ecutables' })

vim.keymap.set('n', '<leader>sa', require('telescope.builtin').git_status, { desc = '[S]earch [A]ll git changes' })
vim.keymap.set('n', '<leader>sr' , [[:%s///g<Left><Left><Left>]], { desc = '[S]earch & global [R]eplace' })
vim.keymap.set('v', '<leader>sr', [[:s///g<Left><Left><Left>]], { desc = '[S]earch & this [L]line [R]eplace' })

require('nvim-highlight-colors').turnOn()

-- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter`

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
640: vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
vim.defer_fn(function()
  require('nvim-treesitter.configs').setup {
    -- Add languages to be installed here that you want installed for treesitter
    ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' },
    ensure_installed = { 'c', 'cpp', 'c_sharp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' },

    -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
    auto_install = false,
    auto_install = true,
    -- Install languages synchronously (only applied to `ensure_installed`)
    sync_install = false,
    -- List of parsers to ignore installing

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
697: vim.defer_fn(function() 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
      },
      swap = {
        enable = true,
        swap_next = {
          ['<leader>a'] = '@parameter.inner',
        },
        swap_previous = {
          ['<leader>A'] = '@parameter.inner',
        },
        -- swap_next = {
        --   ['<leader>a'] = '@parameter.inner',
        -- },
        -- swap_previous = {
        --   ['<leader>A'] = '@parameter.inner',
        -- },
      },
    },
    context = {
      min_window_height = 3
    },
  }
end, 0)

-- Diagnostic keymaps
vim.keymap.set('n', '<leader>dk', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
vim.keymap.set('n', '<leader>dj', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })

-- Debugger keymaps
require('dapui').setup()

require('fine-cmdline').setup({
  popup = {
    position = {
      row = '50%',
    },
    size = { width = '40%' },
  }
})

-- keybind for fine-cmdline
vim.api.nvim_set_keymap('n', 'æ', '<cmd>FineCmdline<CR>', {noremap = true})
vim.api.nvim_set_keymap('v', 'æ', '<cmd>FineCmdline\'<,\'><CR>', {noremap = true})



require('gen').setup({
  model = "mistral",
  display_mode = "split",
  show_prompt = true,
  show_model = true,
  no_auto_close = false,
  init = function(options) pcall(io.popen, "ollama serve > /dev/null 2>&1 &") end,
  command = "curl --silent --no-buffer -X POST http://localhost:11434/api/generate -d $body",
})

-- gen.nvim keybind
vim.keymap.set({'n', 'v'}, '<leader>Gch', [[:Gen Chat<CR>]], {desc = [[using [Gen] [ch]at with AI]]})
vim.keymap.set('v', '<leader>Gcc', [[:Gen Change_Code<CR>]], {desc = [[using [Gen], [C]hange [C]ode with AI]]})

vim.keymap.set('n', '<leader>dt', require('dapui').toggle, { desc = '[D]ebugger [T]oggle' })
vim.keymap.set('n', '<leader>db', [[:DapToggleBreakpoint<CR>]], { desc = '[D]ebugger toggle [B]reakpoint' })

-- [[ Configure LSP ]]
--  This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
781: local on_attach = function(_, bufnr) 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  -- See `:help K` for why this keymap
  nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
  nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
  nmap('<leader>K', vim.lsp.buf.signature_help, 'Signature Documentation')

  -- Lesser used LSP functionality
  nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')

━━━━━━━━━
799: end 
━━━━━━━━━

-- document existing key chains
require('which-key').register {
  ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
  ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
  ['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
  ['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
  ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
  ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
  ['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
  ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
  -- ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
  -- ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
  -- ['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
  -- ['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
  -- ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
  -- ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
  -- ['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
  -- ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
}
-- register which-key VISUAL mode
-- required for visual <leader>hs (hunk stage) to work
require('which-key').register({
  ['<leader>'] = { name = 'VISUAL <leader>' },
  ['<leader>h'] = { 'Git [H]unk' },
  -- ['<leader>h'] = { 'Git [H]unk' },
}, { mode = 'v' })

-- mason-lspconfig requires that these setup functions are called in this order

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
829: require('mason-lspconfig').setup() 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
--  If you want to override the default filetypes that your language server will attach to you can
--  define the property 'filetypes' to the map in question.
local servers = {
  -- clangd = {},
  -- gopls = {},
  -- pyright = {},
  -- rust_analyzer = {},
  -- tsserver = {},
  -- html = { filetypes = { 'html', 'twig', 'hbs'} },
  clangd = {},
  gopls = {},
  pyright = {},
  rust_analyzer = {},
  tsserver = {},
  html = { filetypes = { 'html', 'twig', 'hbs'} },
  eslint = {},

  lua_ls = {
    Lua = {
      workspace = { checkThirdParty = false },
      telemetry = { enable = false },
      -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings
      -- diagnostics = { disable = { 'missing-fields' } },
      diagnostics = {
        globals = { 'vim' },
        -- disable = { 'missing-fields' },
      },
    },
  },
}

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
875: mason_lspconfig.setup_handlers { 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  end,
}

-- Mason doesn't work well with gdscript, so we will setup manually
local dap = require('dap')
dap.adapters.godot = {
  type = 'server',
  host = '192.0.0.1',
  port = 6007,
}
dap.configurations.gdscript = {
  {
    type = 'godot',
    request = 'launch',
    name = 'Launch scene',
    project = '${workspaceFolder}',
    launch_scene = true,
  }
}
require('lspconfig').gdscript.setup{}

-- [[ Configure nvim-cmp ]]
-- See `:help cmp`
local cmp = require 'cmp'

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
900: local luasnip = require 'luasnip' 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
require('luasnip.loaders.from_vscode').lazy_load()
luasnip.config.setup {}

-- choose your icon chars
local icons = {
  Class = '38;2;248;248;242m,
  Color = '',
  Constant = '',
  Constructor = '',
  Enum = '',
  EnumMember = '',
  Event = '',
  Field = '',
  File = '',
  Folder = '󰉋',
  Function = '󰡱',
  Interface = '',
  Keyword = '',
  Method = "",
  Module = 'mod',
  Operator = '',
  Property = '',
  Reference = 'ref',
  Snippet = '38;2;248;248;242m,
  Struct = '󰘦',
  Text = 'abc',
  TypeParameter = '',
  Unit = '󰑭',
  Value = '',
  Variable = '',
}

cmp.setup {
  snippet = {
    expand = function(args)

━━━━━━━━━━━━━━━━━
938: cmp.setup { 
━━━━━━━━━━━━━━━━━
  completion = {
    completeopt = 'menu,menuone,noinsert',
  },
  formatting = {
    format = function(entry, vim_item)
      if vim_item.kind == 'Color' and entry.completion_item.documentation then
        local _, _, r, g, b = string.find(entry.completion_item.documentation, '^rgb%((%d+), (%d+), (%d+)')
        if r then
          local color = string.format('%02x', r) .. string.format('%02x', g) ..string.format('%02x', b)
          local group = 'Tw_' .. color
          if vim.fn.hlID(group) < 1 then
            vim.api.nvim_set_hl(0, group, {fg = '#' .. color})
          end
          vim_item.kind = '⬤'
          vim_item.kind_hl_group = group
          return vim_item
        end
      end
      -- vim_item.kind = icons[vim_item.kind] and (icons[vim_item.kind] .. vim_item.kind) or vim_item.kind
      -- or just show the icon
      vim_item.kind = icons[vim_item.kind] and icons[vim_item.kind] or vim_item.kind
      return vim_item
    end,
  },
  mapping = cmp.mapping.preset.insert {
    ['<C-n>'] = cmp.mapping.select_next_item(),
    ['<C-p>'] = cmp.mapping.select_prev_item(),
    ['<C-b>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-Space>'] = cmp.mapping.complete {},
    ['<C-Space>'] = cmp.mapping.complete (),
    ['<C-c>'] = cmp.mapping.abort(),
    ['<CR>'] = cmp.mapping.confirm {
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,

━━━━━━━━━━━━━━━━━
993: cmp.setup { 
━━━━━━━━━━━━━━━━━
    { name = 'nvim_lsp' },
    { name = 'luasnip' },
    { name = 'path' },
    { name = 'lab.quick_data', keyword_length = 4 },
  },
}

vim.opt.showmode = false

vim.cmd([[set cursorline]])

vim.cmd([[au BufRead,BufNewFile * set sw=0]])
vim.cmd([[au BufRead,BufNewFile * set ts=2]])
vim.cmd([[au BufRead,BufNewFile * set expandtab]])
vim.cmd([[au BufRead,BufNewFile */COMMIT_EDITMSG set cc=70]])


ToggleColor()
vim.api.nvim_create_user_command("ToggleTransparency", function()
  ToggleColor()
end, {})

vim.keymap.set('n', '<leader>xx', [[:source ~/.config/nvim/init.lua<CR>]], { desc = 'source/E[X]ecute init'})
vim.keymap.set('n', '<leader>xt', [[:source %<CR>]], { desc = 'source/E[X]ecute [T]his'})

-- Toggle between always having the cursor centered and not doing so
local fixedLines = false

local function toggleFixedLines()
  if fixedLines then
    vim.opt.scrolloff = 0
  else vim.opt.scrolloff = 9999
  end
  fixedLines = not fixedLines
end

vim.keymap.set('n', '<leader>l', toggleFixedLines, {desc = 'fixed [L]ines'})

-- paste without destroying what you have in register
vim.keymap.set('v', '<leader>p', [["_dP]], {noremap = true, desc = [[[P]aste without loosing clipboard]]})

-- new file here and explore here keybinds
vim.keymap.set('n', '<leader>n', [[:FineCmdline edit %:p:h/<CR>]], {desc = [[edit/create [N]ew file here]]})
vim.keymap.set('n', '<leader>e', [[:Explore<CR>]], {desc = [[[E]xplore from here]]})

-- better keybinds for netrw
vim.api.nvim_create_autocmd('filetype', {
  pattern = 'netrw',
  desc = 'Better keybinds for netrw',
  callback = function()
    local bind = function(new, old)
      vim.keymap.set('n', new, old, {remap = true, buffer = true})
    end

    -- edit new file
    bind('<leader>n', '%')

    -- rename file
    bind('r', 'R')

  end
})

vim.keymap.set({'n', 'i', 'v', 'o', 'c'}, '<A-s>', ToggleColor)

vim.api.nvim_set_hl(0, "TreesitterContextLineNumber", {fg=[[#9CB8FF]]})

vim.keymap.set('n', '<leader>who', [[:G blame<CR>]])
vim.keymap.set('n', '<leader>cl', [[:Bd other<CR>]])
vim.keymap.set('n', '<leader>col', [[:FineCmdline set cc=<CR>]], { desc = 'Color in [COL]umn at given number'} )

vim.keymap.set('n', '<leader>run', [[:Lab code run<CR>]], { desc = '[RUN] lab code runner'} )
vim.keymap.set('n', '<leader>stop', [[:Lab code stop<CR>]], { desc = '[STOP] lab code runner'} )

vim.keymap.set('t', '<Esc>', [[<C-\><C-n>]])
vim.keymap.set('n', '<leader>f', [[/]])
vim.keymap.set('x', '<leader>q', [[@]])

vim.keymap.set('n', 'gp', '`[v`]', { desc = "Reselect last pasted"})

vim.keymap.set('n', 'J', [[mzJ`z]])

vim.keymap.set('n', '<A-j>', [[:m +1<CR>==]])
vim.keymap.set('n', '<A-k>', [[:m -2<CR>==]])
vim.keymap.set('v', '<A-k>', [[:m '<-2<CR>gv=gv]])
vim.keymap.set('v', '<A-j>', [[:m '>+1<CR>gv=gv]])


vim.keymap.set('n', '<A-d>', [[:bn<CR>]])
vim.keymap.set('n', '<A-a>', [[:bN<CR>]])
vim.keymap.set('n', '<A-1>', [[:bf<CR>]])
vim.keymap.set('n', '<A-2>', [[:bf<CR>:bn<CR>]])
vim.keymap.set('n', '<A-3>', [[:bf<CR>:2bn<CR>]])
vim.keymap.set('n', '<A-q>', [[:bf<CR>:3bn<CR>]])
vim.keymap.set('n', '<A-w>', [[:bf<CR>:4bn<CR>]])
vim.keymap.set('n', '<A-e>', [[:bf<CR>:5bn<CR>]])
vim.keymap.set({'n', 'v', 'o', 'c'}, '<C-z>', '<Nop>')

vim.opt.wrap = true
vim.opt.linebreak = true

vim.opt.list = true
vim.opt.listchars:append({trail = '•', eol = '↵', tab = '» '})

-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et