" VIM ENV --------------------------------------------------------------- {{{ if $USER != "root" set runtimepath^=$XDG_CONFIG_HOME/vim set runtimepath+=$XDG_DATA_HOME/vim set runtimepath+=$XDG_CONFIG_HOME/vim/after set viminfofile=$XDG_DATA_HOME/vim/.viminfo set packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim set packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after let g:netrw_home = $XDG_DATA_HOME."/vim" call mkdir($XDG_DATA_HOME."/vim/spell", 'p') set backupdir=$XDG_CONFIG_HOME/vim/backup | call mkdir(&backupdir, 'p') set directory=$XDG_CONFIG_HOME/vim/swap | call mkdir(&directory, 'p') set undodir=$XDG_DATA_HOME/history/vim_history | call mkdir(&undodir, 'p') set viewdir=$XDG_CONFIG_HOME/vim/view | call mkdir(&viewdir, 'p') else set runtimepath^=/root/.config/vim set runtimepath+=/root/.local/share/vim set runtimepath+=/root/.config/vim/after set viminfofile=/root/.local/share/vim/.viminfo set packpath^=/root/.local/share/vim,/root/.config/vim set packpath+=/root/.config/vim/after,/root/.local/share/vim/after let g:netrw_home = "/root/.local/share/vim" call mkdir("/root/.local/share/vim/spell", 'p') set backupdir=/root/.config/vim/backup | call mkdir(&backupdir, 'p') set directory=/root/.config/vim/swap | call mkdir(&directory, 'p') set undodir=/root/.local/share/history/vim_history | call mkdir(&undodir, 'p') set viewdir=/root/.config/vim/view | call mkdir(&viewdir, 'p') endif " }}} " AUTOCMD ---------------------------------------------------------------- {{{ autocmd VimEnter * silent execute '!echo -ne "\e[2 q"' " }}} " Hex_Toggle_Functions --------------------------------------------------- {{{ function! DoHex() " Get the current buffer name let current_file = expand('%') " New file name let new_file = current_file . '.hex' " Save the current buffer as a hex file execute 'w !xxd > ' . new_file echo "Hex file created and saved as " . new_file endfunction function! UndoHex() " Get the current buffer name let current_file = expand('%') " Name stage 1: Remove the .hex extension if it exists let new_file_stage1 = substitute(current_file, '\.hex$', '', '') " Get the file name without extension let file_name = substitute(new_file_stage1, '\(.*\)\.\(\w\+\)$', '\1', '') " Get the file extension let file_extension = substitute(new_file_stage1, '\(.*\)\.\(\w\+\)$', '\2', '') " Add 'M' before the extension(M = Modded) let new_file = file_name . 'M.' . file_extension " Save the current buffer as a reversed hex file execute 'w !xxd -r > ' . new_file echo "Reversed Hex file created and saved as " . new_file endfunction " Function to toggle between hex and original states function! HexState() " Get user input to choose the operation (0 for DoHex, 1 for UndoHex) let operation = input("Choose operation (0 for DoHex, 1 for UndoHex): ") if operation == 0 " Execute the DoHex function call DoHex() elseif operation == 1 " Execute the UndoHex function call UndoHex() else echo "Invalid choice. Aborting." endif endfunction " }}} " GVIM - GUI VERSION ----------------------------------------------------- {{{ if has('gui_running') " Font if has("macvim") set guifont=Menlo\ Regular:h14 elseif has("win32") set guifont=Consolas\ 14 else set guifont=Consolas\ 18 endif " Hide the toolbar. set guioptions-=T " Hide the right-side scroll bar. set guioptions-=r " Start Lex Tree and put the cursor back in the other window. autocmd VimEnter * :Lexplore | wincmd p endif " }}} " MAPPINGS --------------------------------------------------------------- {{{ " Set the space as the leader key. let mapleader = " " let maplocalleader = "\\" " Diable nnoremap Q " Cmd & Esc nnoremap : inoremap : " Spell-check on\off to o, 'o' for 'orthography': map og :setlocal spell! spelllang=en_us " Type jk to exit insert mode quickly. inoremap jk " Format a paragraph into lines map cf gq " Select all the text nnoremap a ggVG " Opening a file explore map le :Lex " Opening a file from explorer map e :Explore " Opening a terminal window map :ter " Closing the terminal window tnoremap exit " Buffer nnoremap H :bprev nnoremap L :bnext " CTRL+I OR Esc to make the terminal scrollable and I to input mode tnoremap tnoremap " You can split the window in Vim. y - in the y access , x - in the x access map w\- :split map w\| :vsplit " Better move nnoremap 11kzz nnoremap 11jzz nnoremap n nzzzv nnoremap N Nzzzv " Navigate the split view easier by pressing CTRL+j, CTRL+k, CTRL+h, or CTRL+l. nnoremap j nnoremap k nnoremap h nnoremap l " Resize split windows using arrow keys by pressing: " CTRL+UP, CTRL+DOWN, CTRL+LEFT, or CTRL+RIGHT. noremap + noremap - noremap < noremap > " Moving between tabs map t gt " Opening/Creating a file in a new tab - write the tab to open nnoremap bn :tabedit " Saving a file using CTRL+S map :w " Quitting and saving a file using CTRL+S map bd :bd map BD :bd! map wq :wq nnoremap q :q! nnoremap Q :qa! " Surround word with a wanted character nnoremap sw echo "Press a character: " \| let c = nr2char(getchar()) \| exec "normal viwo\ei" . c . "\eea" . c . "\e" \| redraw " Replace all occurrences of a word nnoremap rw :%s/\<\>//g " Toggle between creating a Hex conversion file and reversing the conversion nnoremap hx call HexState() " For copy and past if supports clipbard if has('gui_running') map p "+P xnoremap p "_dP nmap Y "+Y nnoremap y "*y :let @+=@* vnoremap y "*y :let @+=@* nmap D "+D nnoremap d "+d vnoremap d "+d endif " Change nnoremap c "_c " Delete nnoremap x "_x " Seeing the registers nnoremap ' registers " Moving lines in visual mode vnoremap J :m '>+1gv=gv vnoremap K :m '>-2gv=gv " Join nnoremap J mzJ`z " Perform dot commands over visual blocks: vnoremap . :normal . " Source file nnoremap so :so " Compiler nnoremap rr :w:terminal compiler %:resize 10 " Open quickfix/location list" nnoremap oq :copen nnoremap ol :lopen " }}} " SETTINGS --------------------------------------------------------------- {{{ " Cursor shapes let &t_SI = "\[6 q" let &t_SR = "\[4 q" let &t_EI = "\[2 q" " Clipboard set clipboard+=unnamedplus " Disable auto commenting in a new line autocmd Filetype * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " Setting the character encoding of Vim to UTF-8 set encoding=UTF-8 " Enable type file detection. Vim will be able to try to detect the type of file is use. filetype on " Enable spell check set nospell highlight SpellBad ctermfg=204 guifg=#F28FAD gui=undercurl guisp=#F28FAD highlight SpellCap ctermfg=75 guifg=#9D7CD8 gui=undercurl guisp=#9D7CD8 highlight SpellRare ctermfg=81 guifg=#0DB9D7 gui=undercurl guisp=#0DB9D7 highlight SpellLocal ctermfg=142 guifg=#FAB387 gui=undercurl guisp=#FAB387 " Avoids updating the screen before commands are completed set lazyredraw " Smart tab set smarttab " Search down to subfolders set path+=** " Enable plugins and load plugin for the detected file type. filetype plugin on " Load an indent file for the detected file type. filetype indent on " Turn syntax highlighting on. syntax on " Turns off highlighting on the bits of code that are changed, so the line that is changed is highlighted but the actual text that has changed stands out on the line and is readable. if &diff highlight! link DiffText MatchParen endif " Add numbers to the file. set number relativenumber " Mouse functionality set mouse=a " Background color " set bg=light " Color scheme colorscheme desert " Highlight cursor line underneath the cursor horizontally. set cursorline " Disable highlight cursor line underneath the cursor vertically. set nocursorcolumn " Set shift width to 4 spaces.Set tab width to 4 columns. set shiftwidth=4 set tabstop=4 " If the current file type is HTML, set indentation to 2 spaces. autocmd Filetype html setlocal tabstop=2 shiftwidth=2 expandtab " Do not save backup files. set nobackup " Do wrap lines. set wrap " While searching though a file incrementally highlight matching characters as you type. set incsearch set hlsearch " Ignore capital letters during search. set ignorecase " Show partial command you type in the last line of the screen. set showcmd " Show the mode you are on the last line. set showmode " Show matching words during a search. set showmatch " Show title of the file set title " Timeout set timeoutlen=300 " Time (in milliseconds) to wait for a mapping set ttimeoutlen=10 " Time (in milliseconds) to wait for terminal key codes " Esc set noesckeys " Set the commands to save in history default number is 20. set history=1000 " Setting the split window to open as i like (like in a WM - qtile) set splitbelow splitright " Enable auto completion menu after pressing TAB. set wildmenu " There are certain files that we would never want to edit with Vim. " Wild menu will ignore files with these extensions. set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx " If Vim version is equal to or greater than 7.3 enable undo file. " This allows you to undo changes to a file even after saving it. if version >= 703 set undodir=~/.config/vim/backup set undofile set undoreload=10000 endif " File Browsing settings let g:netrw_banner=0 let g:netrw_liststyle=3 let g:netrw_showhide=1 let g:netrw_winsize=20 " Auto Completion - Enable Omni complete features set omnifunc=syntaxcomplete#Complete " Enable Spelling Suggestions for Auto-Completion: set complete+=k set completeopt=menu,menuone,noinsert " Minimalist-Tab Complete inoremap TabComplete() fun! TabComplete() if getline('.')[col('.') - 2] =~ '\K' || pumvisible() return "\" else return "\" endif endfun " Minimalist-Autocomplete inoremap pumvisible() ? "\" : "\" autocmd InsertCharPre * call AutoComplete() fun! AutoComplete() if v:char =~ '\K' \ && getline('.')[col('.') - 4] !~ '\K' \ && getline('.')[col('.') - 3] =~ '\K' \ && getline('.')[col('.') - 2] =~ '\K' " last char \ && getline('.')[col('.') - 1] !~ '\K' call feedkeys("\", 'n') end endfun " Closing compaction in insert mode inoremap [ [] inoremap ( () inoremap { {} inoremap /* /**/ " }}} " STATUS LINE ------------------------------------------------------------ {{{ set laststatus=2 set statusline= set statusline+=%2* set statusline+=%{StatuslineMode()} set statusline+=%{SpellCheckStatus()} set statusline+=%1* set statusline+=%3* set statusline+=< set statusline+=- set statusline+=%f set statusline+=- set statusline+=> set statusline+=%4* set statusline+=%m set statusline+=%= set statusline+=%h set statusline+=%r set statusline+=%4* set statusline+=%c set statusline+=/ set statusline+=%l set statusline+=/ set statusline+=%L set statusline+=%1* set statusline+=| set statusline+=%y set statusline+=%4* set statusline+=%P set statusline+=%3* set statusline+=t: set statusline+=%n " }}} " STATUS FUNCTIONS ------------------------------------------------------- {{{ " Mode function! StatuslineMode() let l:mode=mode() if l:mode==#"n" return "NORMAL" elseif l:mode==#"V" return "VISUAL LINE" elseif l:mode==?"v" return "VISUAL" elseif l:mode==#"i" return "INSERT" elseif l:mode ==# "\" return "V-BLOCK" elseif l:mode==#"R" return "REPLACE" elseif l:mode==?"s" return "SELECT" elseif l:mode==#"t" return "TERMINAL" elseif l:mode==#"c" return "COMMAND" elseif l:mode==#"!" return "SHELL" else return "VIM" endif endfunction " Spell Check Status function! SpellCheckStatus() if &spell return " [SPELL]" else return '' endif endfunction " }}} " VIMSCRIPT -------------------------------------------------------------- {{{ " This will enable code folding. " Use the marker method of folding. augroup filetype_vim autocmd! autocmd FileType vim setlocal foldmethod=marker augroup END " INIT VIM --------------------------------------------------------------- {{{ if filereadable(expand("~/.config/vim/init.vim")) source ~/.config/vim/init.vim endif " }}} " SHORTCUTS -------------------------------------------------------------- {{{ if filereadable(expand("~/.config/vim/shortcuts.vim")) silent! source ~/.config/vim/shortcuts.vim endif if filereadable(expand("~/.config/vim/rootshortcuts.vim")) silent! source ~/.config/vim/rootshortcuts.vim endif " }}} " COLORS ----------------------------------------------------------------- {{{ " Terminal color set t_Co=256 if exists('+termguicolors') set termguicolors endif " Cursor hi CursorLine cterm=NONE ctermbg=236 ctermfg=NONE gui=NONE guibg=Grey30 guifg=NONE " Transparent hi Normal ctermbg=NONE guibg=NONE hi NonText ctermbg=NONE guibg=NONE hi LineNr ctermbg=NONE guibg=NONE hi Folded ctermbg=NONE guibg=NONE hi EndOfBuffer ctermfg=Grey guifg=Grey hi User1 ctermbg=brown ctermfg=white guibg=NONE guifg=white hi User2 ctermbg=lightgreen ctermfg=black guibg=lightgreen guifg=black hi User3 ctermbg=brown ctermfg=lightcyan guibg=NONE guifg=lightblue hi User4 ctermbg=brown ctermfg=green guibg=NONE guifg=lightgreen " }}}