" Enable line numbers
set number

" Enable relative line numbers
set relativenumber

" Enable syntax highlighting
syntax on

" Set colorscheme
colorscheme slate

" Enable file type detection and plugins
filetype plugin indent on

" Set the tab width to 4 spaces
set tabstop=4
set shiftwidth=4
set expandtab

" Enable auto-indentation
set autoindent
set smartindent

" Highlight current line
set cursorline

" Show matching parentheses
set showmatch

" Enable line wrapping
set wrap

" Enable mouse support
set mouse=a

" Enable clipboard access
set clipboard=unnamedplus

" Disable swap file
set noswapfile

" Enable incremental search
set incsearch

" Ignore case in search
set ignorecase

" Override ignorecase if search contains capital letters
set smartcase

" Display line and column number of the cursor position
set ruler

" Set the status line at the bottom
set laststatus=2

" Show command in bottom bar
set showcmd

" Set command height
set cmdheight=2

" Set history lines
set history=1000

" Disable backup file
set nobackup

" Enable persistent undo
set undofile

" Set maximum number of undo levels
set undolevels=1000

" Set undo directory
if has("persistent_undo")
    silent !mkdir ~/.vim/undodir > /dev/null 2>&1
    set undodir=~/.vim/undodir
endif

" Set search highlighting
set hlsearch

" Enable visual bell
set visualbell

" Set default file encoding
set encoding=utf-8

" Set the leader key to space
let mapleader = " "

" Map <Leader>w to save the file
nnoremap <Leader>w :w<CR>

" Map <Leader>q to quit
nnoremap <Leader>q :q<CR>

" Map <Leader>x to save and quit
nnoremap <Leader>x :wq<CR>

" Enable folding
set foldmethod=syntax
set foldlevelstart=99

" Enable line wrapping at 80 characters
set textwidth=80
set colorcolumn=80

" Add some basic key mappings
" Map jj to escape insert mode
inoremap jj <Esc>

" Map <Leader>n to toggle line numbers
nnoremap <Leader>n :set number!<CR>

" Map <Leader>r to toggle relative line numbers
nnoremap <Leader>r :set relativenumber!<CR>

" Configure plugins (if you use a plugin manager like vim-plug)
" Example with vim-plug:
" call plug#begin('~/.vim/plugged')
" Plug 'tpope/vim-sensible'
" Plug 'preservim/nerdtree'
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
" Plug 'airblade/vim-gitgutter'
" call plug#end()

" NERDTree key mappings
" nnoremap <C-n> :NERDTreeToggle<CR>

" Enable automatic hard wrapping at textwidth (80 chars)
set formatoptions+=t    " Auto-wrap text using textwidth
set formatoptions+=c    " Auto-wrap comments using textwidth
set formatoptions+=r    " Continue comments when pressing Enter
set formatoptions+=o    " Continue comments when using 'o' or 'O'
set formatoptions+=q    " Allow formatting of comments with 'gq'
set formatoptions+=n    " Recognize numbered lists
set formatoptions+=l    " Don't break lines that were already long

" Enable syntax highlighting
syntax on

" Increase memory limit for complex syntax parsing (Prevents E363)
set maxmempattern=20000