" Ada's Vim config — lightweight and close to Neovim setup
" Encoding and basics
scriptencoding utf-8
set nocompatible

" Leader
let mapleader = " "

" UI
set number
set relativenumber
set cursorline
set signcolumn=yes
set termguicolors

" Indentation
set expandtab
set shiftwidth=2
set tabstop=2
set smartindent

" Search
set ignorecase
set smartcase
set incsearch

" Files
set noswapfile
set undofile

" Performance
set updatetime=200
set timeoutlen=400

" Splits
set splitbelow
set splitright

" Clipboard (prefer system clipboard if available)
if has('unnamedplus')
  set clipboard=unnamedplus
endif

" Keymaps
nnoremap <silent> j gj
nnoremap <silent> k gk
nnoremap <silent> <leader>w :w<CR>
nnoremap <silent> <leader>q :q<CR>
nnoremap <silent> <leader>h :nohlsearch<CR>

" Windows
nnoremap <silent> <leader>sv <C-w>v
nnoremap <silent> <leader>sh <C-w>s
nnoremap <silent> <leader>se <C-w>=
nnoremap <silent> <leader>sx :close<CR>

" Buffers
nnoremap <silent> <S-l> :bnext<CR>
nnoremap <silent> <S-h> :bprevious<CR>

" Quickfix
nnoremap <silent> ]q :cnext<CR>
nnoremap <silent> [q :cprev<CR>

" Autocommands
augroup AdaCore
  autocmd!
  " Resize splits equally on terminal resize
  autocmd VimResized * tabdo wincmd =
  " Disable auto comment on new line
  autocmd FileType * setlocal formatoptions-=o formatoptions-=r
augroup END

" ------------------------------
" Plugin manager: vim-plug (auto-bootstrap)
" ------------------------------
if empty(glob('~/.vim/autoload/plug.vim')) && !exists('$VIM_SKIP_PLUG_BOOTSTRAP')
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

call plug#begin('~/.vim/plugged')

" Theme (Nord for Vim)
Plug 'arcticicestudio/nord-vim'

" Fuzzy finder (fzf)
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

" File tree
Plug 'preservim/nerdtree'

" Editing helpers
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'

" Git signs
Plug 'airblade/vim-gitgutter'

" Statusline
Plug 'itchyny/lightline.vim'

" Optional: LSP-like features via coc.nvim (uncomment if needed)
" Plug 'neoclide/coc.nvim', {'branch': 'release'}

call plug#end()

" Colorscheme
try
  colorscheme nord
catch
  colorscheme default
endtry

" Lightline theme to match colors
let g:lightline = { 'colorscheme': 'nord' }

" NERDTree toggle
nnoremap <silent> <leader>e :NERDTreeToggle<CR>

" FZF mappings
nnoremap <silent> <leader>ff :Files<CR>
nnoremap <silent> <leader>fg :Rg<CR>
nnoremap <silent> <leader>fb :Buffers<CR>
nnoremap <silent> <leader>fh :Helptags<CR>

" Better terminal colors for fzf in Vim
let g:fzf_layout = { 'down': '~40%' }

" If coc.nvim is enabled, you may want additional mappings/settings.
" See vim/vimrc comments or vim/README.md for tips.
