" Jeznet config (Based on Debian)
" ==============================================================================
" Source: https://gist.github.com/mrjk/1d146a701b201e77279ea4e7c5d075a5
" Last update: 2025/07/23
"
" This file is heavily inspirated from Debian
" /usr/share/vim/vim91/defaults.vim . It is a sane global vim
" config for every users that doesn't have a vimrc.
"
" Main vimrc config paths:
"   debian: /etc/vim/vimrc.local
"   rhel: /etc/vimrc.local
"
" Installation at the end of system vimrc:
"   " Source a global configuration file if available
"   if filereadable("/etc/vim/vimrc.local")
"     source /etc/vim/vimrc.local
"   endif
"
" Debian vim files:
"   /usr/share/vim/vim90/defaults.vim
"   /usr/share/vim/vim90/debian.vim


" General
" ---------------------------------------

" Disable vim configs auto-loading
let g:skip_defaults_vim = 1

set nocompatible        " Enable full vim instead of vi
set ttimeout            " Enable time out for key codes
set ttimeoutlen=100     " Wait up to 100ms after Esc for special key
set scrolloff=5         " Ensure before/after lines after context
set autowrite           " Automatically save before commands like :next and :make
set incsearch           " Incremental search

" Edition settings
set backspace=indent,eol,start   " Allow smart backspace
set history=200                  " keep 200 lines of command line history
set nrformats-=octal             " Disable incremnt for octal values


" Display
" ---------------------------------------

" Display options
set showcmd             " Show (partial) command in status line
set showmatch           " Show matching brackets
set wildmenu            " display completion matches in a status line
set ttymouse=           " Disable mouse tty
set mouse=              " Disable mouse for good

" Color support
syntax on
set background=dark

" Set numbering
set nu                  " Enable line numbering
set numberwidth=1       " Line numbering min width

" Vim sane tabs
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab


" Advanced
" ---------------------------------------

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
" Revert with ":iunmap <C-U>".
inoremap <C-U> <C-G>u<C-U>

" Only do this part when Vim was compiled with the +eval feature.
if 1
  " Enable indentation rules per files
  filetype plugin indent on
endif


" Autostart
" ---------------------------------------

if 1
  " Put these in an autocmd group, so that you can revert them with:
  " ":augroup vimStartup | exe 'au!' | augroup END"
  augroup vimStartup
    au!

    " When editing a file, always jump to the last known cursor position.
    " Don't do it when the position is invalid, when inside an event handler
    " (happens when dropping a file on gvim) and for a commit message (it's
    " likely a different one than last time).
    autocmd BufReadPost *
      \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
      \ |   exe "normal! g`\""
      \ | endif

  augroup END
endif


" Helpers
" ---------------------------------------

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
" Revert with: ":delcommand DiffOrig".
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
      \ | wincmd p | diffthis
endif


