" Vim Configuration - Generated by Ansible
" Modern, practical vim setup for development and debugging

" Basic Settings
set nocompatible              " Disable vi compatibility
filetype plugin indent on     " Enable file type detection
syntax on                     " Enable syntax highlighting

" UI Settings
set number                    " Show line numbers
set relativenumber            " Show relative line numbers
set ruler                     " Show cursor position
set showcmd                   " Show command in bottom bar
set wildmenu                  " Visual autocomplete for command menu
set showmatch                 " Highlight matching brackets
set cursorline                " Highlight current line
set laststatus=2              " Always show status line
set colorcolumn=80,120        " Show column markers

" Search Settings
set incsearch                 " Search as characters are entered
set hlsearch                  " Highlight search results
set ignorecase                " Case insensitive search
set smartcase                 " Case sensitive when uppercase present

" Indentation
set autoindent                " Auto-indent new lines
set smartindent               " Smart indent
set expandtab                 " Use spaces instead of tabs
set tabstop=2                 " Number of visual spaces per TAB
set shiftwidth=2              " Number of spaces for auto-indent
set softtabstop=2             " Number of spaces in tab when editing

" Performance
set lazyredraw                " Don't redraw while executing macros
set ttyfast                   " Fast terminal connection

" Backups and Undo
set nobackup                  " No backup files
set nowritebackup             " No backup while editing
set noswapfile                " No swap files
set undofile                  " Persistent undo
set undodir=~/.vim/undo       " Undo directory
set undolevels=1000           " Maximum number of undos
set undoreload=10000          " Maximum lines to save for undo

" File Handling
set encoding=utf-8            " Use UTF-8 encoding
set fileencoding=utf-8        " File encoding
set autoread                  " Auto-reload changed files
set hidden                    " Allow hidden buffers

" Navigation
set scrolloff=8               " Keep 8 lines above/below cursor
set sidescrolloff=8           " Keep 8 columns left/right of cursor
set mouse=a                   " Enable mouse support

" Folding
set foldmethod=indent         " Fold based on indentation
set foldlevel=99              " Open all folds by default

" Status Line
set statusline=%F             " Full file path
set statusline+=%m            " Modified flag
set statusline+=%r            " Read-only flag
set statusline+=%h            " Help buffer flag
set statusline+=%w            " Preview window flag
set statusline+=%=            " Right align
set statusline+=%y            " File type
set statusline+=\ [%{&ff}]    " File format
set statusline+=\ [%{strlen(&fenc)?&fenc:'none'}]  " File encoding
set statusline+=\ %l:%c       " Line:Column
set statusline+=\ %p%%        " Percentage through file

" Key Mappings
let mapleader = ","           " Set leader key to comma

" Quick save
nnoremap <leader>w :w<CR>

" Quick quit
nnoremap <leader>q :q<CR>

" Clear search highlighting
nnoremap <leader><space> :nohlsearch<CR>

" Split navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" Tab navigation
nnoremap <leader>tn :tabnew<CR>
nnoremap <leader>tc :tabclose<CR>
nnoremap <leader>1 1gt
nnoremap <leader>2 2gt
nnoremap <leader>3 3gt
nnoremap <leader>4 4gt
nnoremap <leader>5 5gt

" Buffer navigation
nnoremap <leader>bn :bnext<CR>
nnoremap <leader>bp :bprevious<CR>
nnoremap <leader>bd :bdelete<CR>

" Paste toggle
set pastetoggle=<F2>

" File Type Specific
autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType javascript,typescript,json setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType yaml,yml setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType go setlocal tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab
autocmd FileType markdown setlocal wrap linebreak nolist

" Auto-create undo directory
if !isdirectory($HOME."/.vim/undo")
    call mkdir($HOME."/.vim/undo", "p", 0700)
endif

" Colors
set background=dark
if &term =~ "xterm" || &term =~ "screen"
    set t_Co=256
endif

" Highlight trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/

" Remember cursor position
autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif
