local opt = vim.opt
local g = vim.g

-- Allgemeine Einstellungen
opt.number = true
opt.cursorline = true
opt.shortmess:append("I")
opt.wildmenu = true
opt.splitright = true
opt.splitbelow = true
opt.signcolumn = "yes"
opt.termguicolors = true
opt.showcmd = false

-- Texte umbrechen
opt.wrap = false
opt.linebreak = true
opt.breakindent = true

-- Rechtschreibprüfung
opt.spelllang = { "de", "en" }
opt.spell = false

-- Optionen für ^n-Vervollständigung
opt.complete = { ".", "w", "b", "u", "t", "i" }

-- bessere Suche
opt.hlsearch = true
opt.incsearch = true
opt.ignorecase = true
opt.smartcase = true

-- Sonderzeichen anzeigen
opt.list = true
opt.listchars = {
  tab = "> ",
  trail = "-",
  extends = ">",
  precedes = "<",
  nbsp = "+",
}
opt.showbreak = "↪ "

-- Erlaube % für Winkelklammern
opt.matchpairs:append("<:>")

-- automatisches Einlesen geänderter Dateien
opt.autoread = true

-- Suche rekursiv
opt.path:append("**")

-- Tabs
opt.expandtab = false
opt.tabstop = 4
opt.shiftwidth = 4
opt.softtabstop = 0

-- Einrückungen
opt.smartindent = true
opt.autoindent = true
opt.cindent = true

-- Faltungen
opt.foldlevel = 1000
opt.foldcolumn = "0"

-- Autovervollständigung
opt.completeopt = { "longest", "menuone", "noselect", "popup" }

-- externe Programme
opt.makeprg = "gmake"
opt.autowrite = true

-- Guifont
opt.guifont = "JetBrains Mono Semibold:h12"

-- Swap files und Undo
opt.swapfile = false
opt.undofile = true
opt.undolevels = 10000
opt.undoreload = 10000

-- Statusline
opt.laststatus = 3
opt.statusline = "%!v:lua.require('config.statusline').statusline()"

-- Clipboard
opt.clipboard = "unnamedplus"

-- Provider deaktivieren
g.loaded_ruby_provider = 0
g.loaded_perl_provider = 0
g.loaded_luarocks_provider = 0
g.python3_host_prog = os.getenv("HOME") .. "/.local/venv/nvim/bin/python"

-- netrw deaktivieren
g.loaded_netrw = 1
g.loaded_netrwPlugin = 1

g.mapleader = ","
g.maplocalleader = "\\"

vim.diagnostic.config({
  virtual_text = true,
  signs = true,
  underline = true,
  update_in_insert = false,
  severity_sort = true,
  float = { border = "rounded" },
})

vim.lsp.util.open_floating_preview = (function(orig)
  return function(contents, syntax, opts, ...)
    opts = opts or {}
    opts.border = opts.border or "rounded"
    return orig(contents, syntax, opts, ...)
  end
end)(vim.lsp.util.open_floating_preview)
