
" =====================================================
" Custom Commands Übersicht
" -----------------------------------------------------
" LEADER ist Space
" last modified: 13.12.2025
"
" Note:
" :so ~/.vimrc - vimrc neu laden
" F12 - Dokumentation .vimrc/personal/doc/mykeys.txt für persöhnliche Keymaps! 
" :PlugUpdate  - Plugins aktualisieren
" sudo apt install xclip  # um copy mode für x11 (nicht wayland) 
" sudo apt install ripgrep
" =====================================================

call plug#begin()
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets' 
Plug 'altercation/vim-colors-solarized'
Plug 'kshenoy/vim-signature'
Plug 'preservim/nerdtree'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'jamessan/vim-gnupg'

Plug 'vim-syntastic/syntastic'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
   

call plug#end()

set runtimepath^=~/.vim/personal

"
" mykeys Help – AUTO TAGS + TOGGLE
" 

" Helptags automatisch erzeugen
augroup MyKeysHelp
    autocmd!
    autocmd VimEnter * silent! helptags ~/.vim/personal/doc
augroup END

augroup CheatSheetSyntax
    autocmd!
    autocmd BufEnter */cheatsheet.txt setlocal syntax=myini
augroup END


" F12 Toggle für mykeys

function! ToggleMyHelp()
    if &buftype ==# 'help'
        helpclose
    else
        help myhelp
    endif
endfunction

nnoremap <F12> :call ToggleMyHelp()<CR>

" 
" UltiSnips Konfiguration
" 

" Eigene + Plugin-Snippets (getrennt)

" BEISPIELE Deaktivieren vim/plugged/vim-snippets --> vim-snippets-off umbennen!
let g:UltiSnipsSnippetDirectories = ['personal/UltiSnips', 'plugged/vim-snippets/UltiSnips' ]

" Trigger
let g:UltiSnipsExpandTrigger        = "<tab>"
let g:UltiSnipsJumpForwardTrigger   = "<tab>"
let g:UltiSnipsJumpBackwardTrigger  = "<s-tab>"
"
function! ToggleUserSnippetsDir()
    let base = expand('~/.vim/')
    let on   = base . 'UltiSnips'
    let off  = base . 'UltiSnips.OFF'

    if isdirectory(on)
        call rename(on, off)
        echo "Eigene Snippets: OFF"
    elseif isdirectory(off)
        call rename(off, on)
        echo "Eigene Snippets: ON"
    else
        echo "Snippet-Ordner NICHT gefunden"
    endif
endfunction

nnoremap <F7> :call ToggleUserSnippetsDir()<CR>

"
" set Options
"
set number
set relativenumber
set mouse=a
set ruler
set cursorline

set nocompatible   
syntax on  
filetype on  
filetype plugin on  
filetype plugin indent on  

set autoindent
set expandtab
set hidden  
set number
set encoding=utf-8

set incsearch
set ignorecase
set smartcase
set hlsearch


set history=3000
set scrolloff=0   " damit zz,zt,zb quickfix usw exact ist!
set wildmenu
set foldcolumn=1
set undofile
set undodir=~/.vim/vimundo/
set undolevels=3000
set viminfo='3000,:3000,/3000,<1000,s1000

" ESC soll sofort reagieren
set ttimeout
set ttimeoutlen=10

" Mappings sollen zuverlässig sein
set timeout
set timeoutlen=600


" mouse xterm nach sgr
set ttymouse=sgr

"
" syntastic
"
let g:syntastic_asm_dialect = 'intel'
let g:syntastic_quiet_messages = { 'regex': 'SC2148\|SC1234\|SC6789' }
let g:syntastic_python_flake8_args = "--ignore=E501,E225 --max-complexity 10"
let g:syntastic_python_pylint_exe = 'python3 -m pylint'
let g:syntastic_python_pylint_args = "--disable=C0303,C0304,C0305,C0114,C0115,C0116"



let g:syntastic_python_checkers = []
"
" assembler sprache syntax
"
 au BufNewFile,BufRead *.s,*.S set filetype=arm " arm = armv6/7

 let g:syntastic_always_populate_loc_list = 1
 let g:syntastic_auto_loc_list = 1
 let g:syntastic_check_on_open = 1
 let g:syntastic_check_on_wq = 0

 let g:solarized_term_italics = 1
"
" color
"
 let g:solarized_termcolors=256
 set background=dark
 colorscheme solarized

" statusline
let g:syntastic_stl_format = ''

highlight StatusLine ctermfg=white ctermbg=darkgray
highlight StatusLineNC ctermfg=gray ctermbg=darkgray 

let g:go_disable_autoinstall = 0

" aktiviere buffer tabline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'

let g:airline#extensions#lsp#enabled = 0

"
" BUFFER HANDLING
"

" , F4 = letzter Buffer (CTRL-^)

"
" SET LEADER KEY
"
let mapleader = " "

" Buffer
nnoremap <leader><F4> <C-^>
" nächster Buffer (Ring vorwärts)
nnoremap <F4> :bn<CR>




" ---- LSP Mappings hier einfügen ----
nnoremap <silent> <leader>ld :LspDefinition<CR>
nnoremap <silent> <leader>lh :LspHover<CR>
nnoremap <silent> <leader>lr :LspReferences<CR>
nnoremap <silent> <leader>ln :LspRename<CR>
nnoremap <silent> <leader>la :LspCodeAction<CR>

"
" FOLDING
"

" Folding-Navigation zusätzlich über Leader
nnoremap <leader>j zj
nnoremap <leader>k zk

augroup SaveView
    autocmd!
    autocmd BufWinLeave * if expand('%') != '' | mkview | endif
    autocmd BufWinEnter * if expand('%') != '' | silent! loadview | endif
augroup END

"
" simple highlight for simple file types
" 
autocmd BufRead,BufNewFile *.ini set filetype=myini
autocmd BufRead,BufNewFile *.conf set filetype=myini
autocmd BufRead,BufNewFile *.txt set filetype=myini


"
" ripgrep als Backend für :grep
"
set grepprg=rg\ --vimgrep\ --smart-case
set grepformat=%f:%l:%c:%m


" Grep: Standard, löscht nur altes Highlight vor neuer Suche
command! -nargs=+ Grep execute 'nohlsearch' | silent grep! <args> | redraw!

augroup QuickfixAutoOpen
    autocmd!
    autocmd QuickFixCmdPost [^l]* nested cwindow |  redraw!
augroup END

" Quickfix Navigation (Up/Down)
nnoremap <leader>d :cnext<CR>
nnoremap <leader>u :cprevious<CR>

" Qfc QuickFixClear
command! Qfc cexpr [] | cclose

" NERDTREE f2 toogle
noremap <F2> :NERDTreeToggle<CR>

" zentraler path 
set path+=~/platon/documents/notes/**

" ctrl+L um highlight search aus!!
nnoremap <C-L> :nohlsearch<CR><C-L>

"  Wls - zeigt liste mit Fensternummern an
"  mit WSwap können dann beliege Fenster getausch werden
command! Wls call s:wls()
function! s:wls()
  for i in range(1, winnr('$'))
    execute i . "wincmd w"
    echom printf("[%d] %s", i, expand('%:t'))
  endfor
endfunction

" -----------------------------------------------
" WSwap – tauscht die Buffer zweier Fenster
" Nutzung: :WSwap 1 3
" -----------------------------------------------
command! -nargs=+ WSwap call s:wswap(<f-args>)

function! s:wswap(w1, w2)
  " Fenster 1 → Buffer merken
  execute a:w1 . "wincmd w"
  let b1 = bufnr('%')

  " Fenster 2 → Buffer merken
  execute a:w2 . "wincmd w"
  let b2 = bufnr('%')

  " Fenster 1 bekommt Buffer 2
  execute a:w1 . "wincmd w"
  execute "buffer " . b2

  " Fenster 2 bekommt Buffer 1
  execute a:w2 . "wincmd w"
  execute "buffer " . b1
endfunction

"
" Toggle durch drei Line-Number-Modi:
"

" none → absolute → relative → none → ...
function! ToggleNumberModes()
    if !&number && !&relativenumber
        " Modus 2: absolute Nummern
        set number
        set norelativenumber
    elseif &number && !&relativenumber
        " Modus 3: relative Nummern
        set number
        set relativenumber
    else
        " Modus 1: keine Nummern
        set nonumber
        set norelativenumber
    endif
endfunction

nnoremap <F3> :call ToggleNumberModes()<CR>

"
" utils.vim im signature plugin um richtiges mapping zu erzeugen!
"
autocmd VimEnter * call signature#utils#Maps('create')
nnoremap <leader><F5> :marks abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<CR>
nnoremap <F5> :call signature#mark#Goto("next", "line", "pos")<CR>

"
" vimdiff vor/zürück
"
nnoremap <F6> ]c
nnoremap <leader><F6> [c

"
"  copy verhalten
"
set clipboard=unnamedplus

" Solarized-konforme CursorLine-Farben
" run command in bash to see color palette
"for i in {0..255}; do
"  printf "\x1b[48;5;%sm %3d \x1b[0m" "$i" "$i"
"  (( (i + 1) % 16 == 0 )) && echo
"done


function! s:UpdateCursorLine(mode)
    if a:mode ==# 'insert'
        highlight CursorLine ctermbg=240  ctermfg=15
    else
        highlight CursorLine ctermbg=236 ctermfg=NONE
    endif
endfunction

augroup CursorLineMode
    autocmd!
    autocmd ColorScheme * call s:UpdateCursorLine('normal')
    autocmd InsertEnter * call s:UpdateCursorLine('insert')
    autocmd InsertLeave * call s:UpdateCursorLine('normal')
augroup END


"
" Markdown - plugin 
"

let g:vim_markdown_conceal = 0
let g:vim_markdown_conceal_code_blocks = 0
function! SetMarkdownColors()
    " 1. Header (H1-H6)
    highlight htmlH1 ctermfg=202 cterm=bold
    highlight htmlH2 ctermfg=172 cterm=bold
    highlight htmlH3 ctermfg=173
    highlight htmlH4 ctermfg=151
    highlight htmlH5 ctermfg=110
    highlight htmlH6 ctermfg=103

    " 2. Listen & Aufzählung (Wieder hinzugefügt - Grün 151)
    highlight mkdListItem ctermfg=166
    highlight mkdList     ctermfg=166

    " 3. Code & Strings (Blau 110 & Gelb 222)
    highlight mkdCode       ctermfg=110
    highlight mkdInlineCode ctermfg=110
    highlight String        ctermfg=222

    " 4. Text-Stile (DEINE ORIGINAL-FARBEN)
    highlight htmlBold       ctermfg=70 cterm=bold
    highlight htmlItalic     ctermfg=71 cterm=italic
    highlight htmlBoldItalic ctermfg=72 cterm=bold,italic
    
    highlight link mkdBold       htmlBold
    highlight link mkdItalic     htmlItalic
    highlight link mkdBoldItalic htmlBoldItalic

    " 5. Callouts (Blau 110)
    highlight mkdBlockquote ctermfg=110
    highlight link mailQuoted1 mkdBlockquote

    " 6. DEIN HIGHLIGHT == text == 
    syntax match MarkdownCustomHighlight /==[^=]\+==/ containedin=ALL
    highlight MarkdownCustomHighlight ctermbg=230 ctermfg=101

    " 7. Checkboxen & Strike-Rest
    highlight mkdStrike ctermfg=244
    syntax match MarkdownTaskDone /\[x\].\+/
    highlight MarkdownTaskDone ctermfg=244
endfunction

" Trigger sauber setzen
augroup MarkdownColors
    autocmd!
    autocmd FileType markdown call SetMarkdownColors()
augroup END

" Sofort-Aktivierung
if &ft == 'markdown' | call SetMarkdownColors() | endif

"
"
"

