From ea2ea8dfa5718766865feaecda8162cec40e6ca3 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 5 Sep 2025 05:43:27 +0200 Subject: New vim config --- linux/home/.vim/vimrc | 904 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 654 insertions(+), 250 deletions(-) (limited to 'linux/home/.vim/vimrc') diff --git a/linux/home/.vim/vimrc b/linux/home/.vim/vimrc index ce034e9..5b0f444 100644 --- a/linux/home/.vim/vimrc +++ b/linux/home/.vim/vimrc @@ -1,296 +1,700 @@ -"=============================================================================== -" Mappings/Keybindings/Commands -"=============================================================================== - -let mapleader = ";" " map leader to Semi colon - -inoremap jk " Use to escape - -" Easier split navigations, just ctrl-j instead of ctrl-w then j -nnoremap -nnoremap -nnoremap -nnoremap - -" Recent files (MRU) -nnoremap m :browse old -" Search files by name -"nnoremap p :find **/** -" browse files from same dir as current file -nnoremap e :e %:p:h - -" Combine buffers list with buffer name -"nnoremap b :buffers:buffer - -" Jump to a buffer -nnoremap b :ls t:b - -" Map buffer next, prev and delete to -map n :bn -map p :bp -map d :bd - -" tab navigation -noremap h :tabprevious -noremap l :tabnext -noremap k :tabfirst -noremap j :tablast -noremap n :tabnew -noremap e :tabedit -noremap c :tabclose -noremap m :tabm - -" Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in -" visual mode to select text to swap with -:vnoremap `.``gvP``P - -" To resize in different steps, you can create maps that will adjust the window -" size differently. For example to increase the window size by a factor of 1.5 -" and decrease the window size by 0.67, you can map this: -"nnoremap + :exe "resize " . (winheight(0) * 3/2) -"nnoremap - :exe "resize " . (winheight(0) * 2/3) -nnoremap + :resize +5 -nnoremap - :resize -5 -nnoremap > :vertical resize +5 -nnoremap < :vertical resize -5 - -" Toggle set number -"nnoremap $ :NumbersToggle -"nnoremap % :NumbersOnOff - -" Copy and Paste with and -"vmap y:call system("xclip -i -selection clipboard", getreg("\"")):call system("xclip -i", getreg("\"")) -"nmap :call setreg("\"",system("xclip -o -selection clipboard"))p -nnoremap p (v:register == '"' && &clipboard =~ 'unnamed' ? '"*p' : '"' . v:register . 'p') - -" Use command :Vb for Visual Block or since is used for Copy -command! Vb normal! - -" Map to save/edit a root permission/read-only file, only works in -" traditional vim and not neovim -cmap w!! %!sudo tee > /dev/null - -nnoremap x :silent !chmod +x % - -"nnoremap <[-p> m`op`` -" Paste on next line -"nnoremap <]-p> m`Op`` - -"inoremap " -"set keywordprg=:help -"runtime ftplugin/man.vim - - -"=============================================================================== -" Settings -"=============================================================================== - -" Neovim requires xclip, check if normal vim has +clipboard by -" <:echo has('clipboard')> from within Vim (if the output is 1, good to -" go otherwise 0 then need a build that has it -" Next two commands make vim use X11 clipboard -set clipboard+=unnamedplus -let g:clipbrdDefaultReg = '+' - -"let g:loaded_clipboard_provider = 1 -" <:e %:h/filename> will create a new file named filename in the same -" directory as the currently open file, and write it. -set autochdir " or use this to use <:e> to create a file in current directory -set splitright " make vsplit put the new buffer on the right of the current buffer -set splitbelow " make split put the new buffer below the current buffer -" :Bclose script (delete a buffer without closing the window) sourced as a -" plugin in ~/.config/nvim/plugin/bclose.vim | keymap: bd -"let bclose_multiple = 1 -"set syntax -" Compute syntax highlighting from beginning of file. (By default, vim only -" looks 200 lines back, which can make it highlight code incorrectly in some -" long files.) -autocmd BufEnter * :syntax sync fromstart -" Don't syntax highlight markdown because it's often wrong -autocmd! FileType mkd setlocal syn=off +" ============================================================================ +" Vim Configuration +" Maintainer: srdusr +" ============================================================================ + +" ============================================================================ +" Core Settings +" ============================================================================ +set nocompatible +set encoding=utf-8 +set fileencoding=utf-8 +scriptencoding utf-8 +set termguicolors +set mouse=a +set clipboard=unnamedplus +set hidden +set updatetime=300 +set timeoutlen=500 +set ttimeoutlen=10 + +" Performance set ttyfast set lazyredraw -" Set lazyredraw to false -"let &lazyredraw = 0 -set timeout timeoutlen=1000 ttimeoutlen=100 " fix slow O inserts -set scrolloff=8 sidescrolloff=8 -set tabstop=4 softtabstop=4 shiftwidth=4 expandtab -set autoindent -set smartindent -" Also load indent files, to automatically do language-dependent indenting. -filetype plugin indent on -set exrc +set ttyscroll=3 + +" ============================================================================ +" Display and UI Settings +" ============================================================================ +set number set relativenumber -set hidden -set noerrorbells +set cursorline +set signcolumn=no +set showcmd +set showmode +set showmatch +set matchtime=2 +set laststatus=2 +set cmdheight=1 +set scrolloff=8 +set sidescrolloff=8 +set sidescroll=1 +set display=lastline set nowrap +set linebreak +set showbreak=↪\ + +" Window behavior +set splitright +set splitbelow +set winminwidth=1 +set winwidth=5 + +" ============================================================================ +" Formatting and Indentation Settings +" ============================================================================ +set autoindent +set smartindent +set expandtab +set tabstop=2 +set shiftwidth=2 +set softtabstop=2 +set shiftround +set textwidth=80 +set formatoptions+=j +" set colorcolumn=+1 + +" File-specific formatting +setlocal tabstop=4 +setlocal shiftwidth=4 +setlocal softtabstop=4 +setlocal foldmethod=marker + +" ============================================================================ +" Search and Matching Settings +" ============================================================================ +set hlsearch +set incsearch set ignorecase set smartcase -set noswapfile -set nobackup -set incsearch -"set cursorline set showmatch -set showcmd -set incsearch -set hlsearch -set laststatus=2 -let g:python3_host_prog = '/usr/bin/python3' -"let g:loaded_python3_provider = 1 -let g:sh_noisk=1 -set modeline -set modelines=3 " modelines (comments that set vim options on a per-file basis) -set foldmethod=manual -set nofoldenable " turn folding off -" Insert only one space when joining lines that contain sentence-terminating -" punctuation like `.`. -set nojoinspaces -set autoread " if a file is changed outside of vim, automatically reload it without asking -set diffopt=vertical " diffs are shown side-by-side not above/below -set signcolumn=no " always show the sign column -set textwidth=80 -set mouse=a +" set inccommand=split + +" ============================================================================ +" File Handling and Backup Settings +" ============================================================================ +set autoread +set autowrite +set autochdir +set confirm +set fileformats=unix,dos,mac + +" Backup and undo configuration +set backup +set writebackup +set backupcopy=yes +set undofile +set noswapfile +set backupdir=~/.cache/vim/backup// +set directory=~/.cache/vim/swap// +set undodir=~/.cache/vim/undo// +set undolevels=10000 +set undoreload=10000 + +" Create necessary directories +let s:config_dir = expand('~/.vim') +let s:cache_dir = expand('~/.cache/vim') +let s:dirs = [ + \ s:cache_dir . '/backup', + \ s:cache_dir . '/swap', + \ s:cache_dir . '/undo', + \ s:cache_dir . '/shada', + \ s:config_dir . '/sessions', + \ ] + +for s:dir in s:dirs + if !isdirectory(s:dir) + call mkdir(s:dir, 'p', 0700) + endif +endfor + +" ============================================================================ +" Completion and Command Line Settings +" ============================================================================ +set omnifunc=syntaxcomplete#Complete +set complete=.,w,b,u,t,i,kspell +set completeopt=menu,menuone,noselect + +" Wildmenu configuration +set wildmenu +set wildmode=longest:full,full +set wildignorecase +set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__ +set wildignore+=.git,.hg,.svn +set wildignore+=*.swp,*.swo +set wildignore+=*.DS_Store +set wildignore+=*.class + +" ============================================================================ +" Leader Keys +" ============================================================================ +let mapleader = ";" +let maplocalleader = "\\" + +" ============================================================================ +" Navigation and Movement Mappings +" ============================================================================ + +" Tmux/Vim Navigation Function +function! SmartMove(direction, tmux_flag) + let curwin = win_getid() + execute 'wincmd ' . a:direction + if win_getid() == curwin + call system('tmux select-pane ' . a:tmux_flag) + endif +endfunction + +" Window navigation +nnoremap :call SmartMove('h', '-L') +nnoremap :call SmartMove('j', '-D') +nnoremap :call SmartMove('k', '-U') +nnoremap :call SmartMove('l', '-R') + +" Split window horizontally +nnoremap - :split + +" Split window vertically +nnoremap \ :vsplit + +" Close the current window +nnoremap c c + +" Buffer navigation +nnoremap bn :bnext +nnoremap bp :bprevious +nnoremap bd :bdelete +nnoremap ba :%bdelete +nnoremap bl :ls:b + +" Quickfix and location list +nnoremap ]q :cnextzz +nnoremap [q :cprevzz +nnoremap ]l :lnextzz +nnoremap [l :lprevzz + +" ============================================================================ +" File and Buffer Management Mappings +" ============================================================================ +nnoremap w :w +nnoremap q :q +nnoremap wq :wq +nnoremap Q :qa! + +" File operations +nnoremap f :Lex +noremap o :Explore +nnoremap rf :browse old + +" Utility mappings +nnoremap r :registers +nnoremap m :redir @+:silent messages:redir END +nnoremap hx :call HexState() +nnoremap h :help + +" Format disable +cnoremap F! :noautocmd w + +" ============================================================================ +" Window and Terminal Mappings +" ============================================================================ + +" Window resizing +nnoremap :resize -2 +noremap :resize +2 +noremap :vertical resize -2 +noremap :vertical resize +2 + +" Terminal mode +nnoremap :terminal +tnoremap :q! +tnoremap +tnoremap h +tnoremap j +tnoremap k +tnoremap l + +" ============================================================================ +" Text Editing and Visual Mode Mappings +" ============================================================================ + +" Insert mode shortcuts +inoremap jk + +" Visual mode operations +vnoremap J :m '>+1gv=gv +vnoremap K :m '>-2gv=gv +vnoremap < >gv + +" Text formatting +nnoremap Q gqap + +" Auto-closing pairs +inoremap [ [] +inoremap ( () +inoremap { {} +inoremap /* /**/ + +" ============================================================================ +" Tab and Completion Functions +" ============================================================================ + +" Smart Tab Function +function! SmartIndentTab() + let line = getline('.') + let col = col('.') - 1 + + if col == 0 || line[col - 1] =~ '^\s*$' + return "\" + else + return "\" + endif +endfunction + +" Tab mappings +silent! iunmap +inoremap SmartIndentTab() +inoremap pumvisible() ? "\" : "\" + +" Auto-completion function +function! AutoComplete() + let skip_filetypes = ['netrw', 'help', 'startify', 'qf', 'man', 'gitcommit'] + + if index(skip_filetypes, &filetype) >= 0 + return + endif + + let col = col('.') + if col < 4 + return + endif + + let line = getline('.') + let prev3 = line[col - 4] + let prev2 = line[col - 3] + let prev1 = line[col - 2] + let curr = v:char + + if curr =~ '\k' && prev3 !~ '\k' && prev2 =~ '\k' && prev1 =~ '\k' + call feedkeys("\", 'n') + endif +endfunction + +" ============================================================================ +" Spell Checking +" ============================================================================ +noremap :setlocal spell! +setlocal nospell + +function! SpellCheckStatus() + return &spell ? ' [SPELL]' : '' +endfunction -" FILE BROWSING: -let g:netrw_banner=0 " disable annoying banner -let g:netrw_browse_split=4 " open in prior window -let g:netrw_altv=1 " open splits to the right -let g:netrw_liststyle=3 " tree view +" ============================================================================ +" File Explorer Configuration +" ============================================================================ +let g:netrw_banner=0 +let g:netrw_browse_split=4 +let g:netrw_altv=1 +let g:netrw_liststyle=3 let g:netrw_fastbrowse = 0 -autocmd FileType netrw setl bufhidden=wipe +let g:netrw_winsize=20 -" Faster vimgrep/grep via ripgrep +" ============================================================================ +" Search Tools Configuration +" ============================================================================ if executable("rg") - set grepprg=rg\ --vimgrep\ --no-heading - set grepformat=%f:%l:%c:%m,%f:%l:%m + set grepprg=rg\ --vimgrep\ --no-heading + set grepformat=%f:%l:%c:%m,%f:%l:%m endif +" ============================================================================ +" Clipboard Configuration +" ============================================================================ + +" OS Detection +let s:uname = substitute(system('uname'), '\n', '', '') +let g:is_mac = has('mac') +let g:is_linux = s:uname ==# 'Linux' +let g:is_windows = has('win32') || has('win64') || s:uname =~? 'Windows' +let g:is_wsl = has('wsl') || (g:is_linux && !empty($WSL_DISTRO_NAME)) +let g:is_termux = has('termux') || (!empty($PREFIX) && $PREFIX =~# 'com.termux') +let g:is_wayland = !empty($WAYLAND_DISPLAY) +let g:is_x11 = !empty($DISPLAY) && empty($WAYLAND_DISPLAY) + +" Clipboard configuration +if has('unnamedplus') + set clipboard=unnamed,unnamedplus +else + set clipboard=unnamed +endif -"=============================================================================== -" Colorscheme -"=============================================================================== +if has('clipboard') + " Linux: Wayland/X11 providers + if g:is_wayland && executable('wl-copy') && executable('wl-paste') + let g:clipboard = { + \ 'name': 'wl-clipboard', + \ 'copy': { + \ '+': ['wl-copy', '--trim-newline'], + \ '*': ['wl-copy', '--trim-newline', '--primary'], + \ }, + \ 'paste': { + \ '+': ['wl-paste', '--no-newline'], + \ '*': ['wl-paste', '--no-newline', '--primary'], + \ }, + \ 'cache_enabled': 1, + \ } + elseif g:is_x11 && executable('xclip') + let g:clipboard = { + \ 'name': 'xclip', + \ 'copy': { + \ '+': ['xclip', '-selection', 'clipboard'], + \ '*': ['xclip', '-selection', 'primary'], + \ }, + \ 'paste': { + \ '+': ['xclip', '-selection', 'clipboard', '-o'], + \ '*': ['xclip', '-selection', 'primary', '-o'], + \ }, + \ 'cache_enabled': 1, + \ } + elseif g:is_x11 && executable('xsel') + let g:clipboard = { + \ 'name': 'xsel', + \ 'copy': { + \ '+': ['xsel', '--clipboard', '--input'], + \ '*': ['xsel', '--primary', '--input'], + \ }, + \ 'paste': { + \ '+': ['xsel', '--clipboard', '--output'], + \ '*': ['xsel', '--primary', '--output'], + \ }, + \ 'cache_enabled': 1, + \ } + " macOS: pbcopy/pbpaste + elseif g:is_mac && executable('pbcopy') && executable('pbpaste') + let g:clipboard = { + \ 'name': 'macOS-clipboard', + \ 'copy': { '+': ['pbcopy'], '*': ['pbcopy'] }, + \ 'paste': { '+': ['pbpaste'], '*': ['pbpaste'] }, + \ 'cache_enabled': 1, + \ } + " WSL: prefer win32yank, fallback to clip.exe + PowerShell + elseif g:is_wsl && executable('win32yank.exe') + let g:clipboard = { + \ 'name': 'win32yank-wsl', + \ 'copy': { '+': ['win32yank.exe', '-i', '--crlf'], + \ '*': ['win32yank.exe', '-i', '--crlf'] }, + \ 'paste': { '+': ['win32yank.exe', '-o', '--lf'], + \ '*': ['win32yank.exe', '-o', '--lf'] }, + \ 'cache_enabled': 1, + \ } + elseif g:is_wsl && executable('clip.exe') && executable('powershell.exe') + let g:clipboard = { + \ 'name': 'wsl-clip', + \ 'copy': { + \ '+': ['clip.exe'], + \ '*': ['clip.exe'], + \ }, + \ 'paste': { + \ '+': ['powershell.exe', '-NoProfile', '-Command', + \ '[Console]::Out.Write((Get-Clipboard -Raw) -replace "`r","")'], + \ '*': ['powershell.exe', '-NoProfile', '-Command', + \ '[Console]::Out.Write((Get-Clipboard -Raw) -replace "`r","")'], + \ }, + \ 'cache_enabled': 0, + \ } + " Native Windows + elseif g:is_windows && !g:is_wsl && executable('win32yank.exe') + let g:clipboard = { + \ 'name': 'win32yank', + \ 'copy': { '+': ['win32yank.exe', '-i', '--crlf'], + \ '*': ['win32yank.exe', '-i', '--crlf'] }, + \ 'paste': { '+': ['win32yank.exe', '-o', '--lf'], + \ '*': ['win32yank.exe', '-o', '--lf'] }, + \ 'cache_enabled': 1, + \ } + elseif g:is_windows && !g:is_wsl && executable('powershell.exe') + let g:clipboard = { + \ 'name': 'powershell-clipboard', + \ 'copy': { + \ '+': ['powershell.exe', '-NoProfile', '-Command', + \ 'Set-Clipboard ([Console]::In.ReadToEnd())'], + \ '*': ['powershell.exe', '-NoProfile', '-Command', + \ 'Set-Clipboard ([Console]::In.ReadToEnd())'], + \ }, + \ 'paste': { + \ '+': ['powershell.exe', '-NoProfile', '-Command', + \ '[Console]::Out.Write((Get-Clipboard -Raw) -replace "`r","")'], + \ '*': ['powershell.exe', '-NoProfile', '-Command', + \ '[Console]::Out.Write((Get-Clipboard -Raw) -replace "`r","")'], + \ }, + \ 'cache_enabled': 0, + \ } + endif +endif -" enable syntax, plugins (for netrw) and indentation +" ============================================================================ +" Colorscheme and Appearance +" ============================================================================ syntax enable - -"set shell=zsh set termguicolors set guicursor= let &t_SI = "\e[6 q" let &t_EI = "\e[2 q" - -"colorscheme desert -"colorscheme city-lights set background=dark -highlight Normal guibg=NONE ctermbg=NONE -highlight EndOfBuffer ctermfg=NONE ctermbg=NONE +" Window title +let progname = substitute($VIM, '.*[/\\]', '', '') +set title titlestring=%{progname}\ %f\ +%l\ #%{tabpagenr()}.%{winnr()} +if &term =~ '^screen' && !has('vim') + exe "set t_ts=\e]2; t_fs=\7" +endif -"------------------------------------------------------------------------------- - +colorscheme colorscheme -"=============================================================================== -" Functions/Scripts -"=============================================================================== +" ============================================================================ +" Custom Functions +" ============================================================================ -" Enable mouse scrollback -"--------------------------------------- -set mouse=a -tnoremap -tnoremap +" Clear Terminal Buffer function! ClearTerminal() - set scrollback=1 - let &g:scrollback=1 - echo &scrollback - call feedkeys("\i") - call feedkeys("clear\") - call feedkeys("\\") - call feedkeys("\i") - sleep 100m - let &scrollback=s:scroll_value + if &buftype == 'terminal' + let s:scroll_value = &scrollback + set scrollback=1 + call feedkeys("\\i") + call feedkeys("clear\") + call timer_start(100, {-> execute('let &scrollback=' . s:scroll_value)}) + endif endfunction -"------------------------------------------------------------------------------- - -" :Rename {newname} -"--------------------------------------- +" Rename Current File function! RenameFile() let old_name = expand('%') - let new_name = input('New file name: ', expand('%'), 'file') + let new_name = input('New file name: ', old_name, 'file') if new_name != '' && new_name != old_name - exec ':saveas ' . new_name - exec ':silent !rm ' . old_name - redraw! + try + execute 'saveas ' . fnameescape(new_name) + if filereadable(old_name) && !filereadable(new_name) + call delete(old_name) + endif + redraw! + catch /^Vim\%(\w\+\).*/ + echohl ErrorMsg | echo 'Error renaming file: ' . v:exception | echohl None + endtry + endif +endfunction + +" Format with cursor preservation +function! PreserveCursorFormat() + let l:pos = getpos(".") + silent! normal! gg=G + call setpos('.', l:pos) +endfunction + +" File/URL opener +function! OpenFileOrUrl(path) abort + if !exists('g:os_name') + echohl WarningMsg | echom 'OS detection not available' | echohl None + return + endif + + let cmd = '' + if g:os_name ==# 'mac' + let cmd = 'open ' . shellescape(a:path) + elseif g:os_name ==# 'linux' + let cmd = 'xdg-open ' . shellescape(a:path) . ' >/dev/null 2>&1 &' + elseif g:os_name ==# 'wsl' + let cmd = 'wslview ' . shellescape(a:path) . ' >/dev/null 2>&1 &' + elseif g:os_name ==# 'windows' + let cmd = 'start "" ' . shellescape(a:path) + elseif g:os_name ==# 'termux' + let cmd = 'am start -a android.intent.action.VIEW -d ' . shellescape(a:path) + else + echohl WarningMsg | echom 'No file opener for OS: ' . g:os_name | echohl None + return + endif + + call system(cmd) + if v:shell_error + echohl ErrorMsg | echom 'Failed to open: ' . a:path | echohl None + endif +endfunction + +" ============================================================================ +" Hex Editing Functions +" ============================================================================ + +" Convert to hex +function! DoHex() abort + let current_file = expand('%:p') + if empty(current_file) + echohl ErrorMsg | echo 'No file name' | echohl None + return endif + + let new_file = current_file . '.hex' + try + execute 'w !xxd > ' . fnameescape(new_file) + echohl Directory | echo 'Hex file created: ' . new_file | echohl None + catch /^Vim\%(\w\+\):/ + echohl ErrorMsg | echo 'Error creating hex file: ' . v:exception | echohl None + endtry endfunction -map r :call RenameFile() - -"------------------------------------------------------------------------------- - -" Return to the same line when we reopen a file -"--------------------------------------- - augroup line_return - au! - au BufReadPost * - \ if line("'\"") > 0 && line("'\"") <= line("$") | - \ execute 'normal! g`"zvzz' | - \ endif - augroup END - -"------------------------------------------------------------------------------- -" -" Function to update tmux status and .vi-mode file -"--------------------------------------- -function! UpdateTmuxStatus() abort - " Check if the current buffer has a man filetype - if &filetype ==# 'man' - return - endif - - " Determine the mode name based on the mode value - let mode = mode() - let mode_name = '' - if mode ==# 'n' - let mode_name = '-- NORMAL --' - elseif mode ==# 'i' || mode ==# 'ic' - let mode_name = '-- INSERT --' - else - let mode_name = '-- NORMAL --' - endif - - " Write the mode name to the file - call writefile([mode_name], expand('$HOME') . '/.vi-mode') +" Convert from hex +function! UndoHex() abort + let current_file = expand('%:p') + if empty(current_file) + echohl ErrorMsg | echo 'No file name' | echohl None + return + endif + + let new_file = substitute(current_file, '\.hex$', '', '') + if new_file ==# current_file + echohl WarningMsg | echo 'Not a .hex file' | echohl None + return + endif + + try + execute '%!xxd -r' + execute 'w ' . fnameescape(new_file) + echohl Directory | echo 'Binary file restored: ' . new_file | echohl None + catch /^Vim\%(\w\+\):/ + echohl ErrorMsg | echo 'Error converting hex file: ' . v:exception | echohl None + endtry endfunction -" Function to refresh tmux status -function! s:UpdateTmux() abort - call system('tmux refresh-client -S') +" Hex state switcher +function! HexState() abort + let choices = [ + \ '1. Convert to hex', + \ '2. Convert from hex', + \ '3. Cancel' + \ ] + + let choice = inputlist(choices) + if choice == 1 + call DoHex() + elseif choice == 2 + call UndoHex() + else + echo 'Operation cancelled.' + endif endfunction -" Set up autocommands for tmux status update -if !empty($TMUX) && system('command -v tmux >/dev/null 2>&1') == 0 -augroup TmuxStatus - autocmd! - autocmd ModeChanged * call UpdateTmuxStatus() | call s:UpdateTmux() +" ============================================================================ +" Commands +" ============================================================================ +command! -nargs=0 OpenFile call OpenFileOrUrl(expand('%:p')) + +" ============================================================================ +" Auto Commands +" ============================================================================ + +" Return to last position +augroup line_return + au! + au BufReadPost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ execute 'normal! g`"zvzz' | + \ endif augroup END -endif -"------------------------------------------------------------------------------- +" Auto-completion +augroup AutoCompleteWordStart + autocmd! + autocmd InsertCharPre * call AutoComplete() +augroup END +" Relative numbers in insert mode +autocmd InsertEnter * set norelativenumber +autocmd InsertLeave * set relativenumber -"=============================================================================== -" Statusline Configuration -"=============================================================================== +" Netrw cleanup +autocmd FileType netrw setl bufhidden=wipe -" Autoload statusline -"--------------------------------------- -" Load statusline script -if filereadable(expand("~/.vim/autoload/statusline.vim")) - source ~/.vim/autoload/statusline.vim +" Reload config +augroup ReloadVimrc + autocmd! + autocmd BufWritePost $MYVIMRC nested source $MYVIMRC | + \ doautocmd ColorScheme | + \ call autoload#statusline#ActivateStatusline() | + \ echon "Reloaded .vimrc" | + \ redraw! +augroup END + +" Auto format +augroup FormatOnSave + autocmd! + autocmd BufWritePre * call PreserveCursorFormat() +augroup END + +" ============================================================================ +" Statusline Configuration +" ============================================================================ +let s:statusline_file = expand('~/.vim/autoload/statusline.vim') +if filereadable(s:statusline_file) + execute 'source ' . fnameescape(s:statusline_file) + + augroup StatuslineConfig + autocmd! + autocmd VimEnter * call autoload#statusline#ActivateStatusline() + autocmd ColorScheme * call autoload#statusline#UpdateStslineColors() + autocmd VimEnter * redrawstatus! + augroup END + + set laststatus=2 + set statusline=%!StatusLine() + + augroup StatuslineOverride + autocmd! + autocmd FileType help,gitcommit,netrw setlocal statusline=%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P + augroup END endif -" Call the statusline activation function -call autoload#statusline#ActivateStatusline() +" ============================================================================ +" GUI Configuration +" ============================================================================ +if has('gui_running') + color slate + + if has('mac') + set guifont=Menlo\ Regular:h14 + elseif has('win32') + set guifont=Consolas:h12 + else + set guifont=Monospace\ 11 + endif + + set guioptions-=T + set guioptions-=r + set guioptions-=L + set guioptions-=m + + autocmd VimEnter * :Lexplore | wincmd p +endif + +" ============================================================================ +" Final Setup +" ============================================================================ +syntax on +filetype plugin indent on +setlocal keywordprg=:help +setlocal iskeyword+=: + +" Load matchit for better % matching +if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# '' + runtime! macros/matchit.vim +endif -"------------------------------------------------------------------------------- +" ============================================================================ -- cgit v1.2.3