""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => General """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Line numbers set number " Search highlighting set hlsearch " Sets how many lines of history VIM has to remember set history=500 " Enable filetype plugins filetype on filetype plugin on filetype indent on " Set to auto read when a file is changed from the outside set autoread " With a map leader it's possible to do extra key combinations " like w saves the current file let mapleader = "," " Fast saving nmap w :w! " Search dir for tags set tags=./tags,**5/tags,tags;~ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => VIM user interface """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Set 7 lines to the cursor - when moving vertically using j/k set so=7 " Avoid garbled characters in Chinese language windows OS let $LANG='en' set langmenu=en " Turn on the Wild menu set wildmenu " Ignore compiled files set wildignore=*.o,*~,*.pyc if has("win16") || has("win32") set wildignore+=.git\*,.hg\*,.svn\* else set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store endif "Always show current position set ruler " A buffer becomes hidden when it is abandoned set hid " Configure backspace so it acts as it should act set backspace=eol,start,indent set whichwrap+=<,>,h,l " Ignore case when searching set ignorecase " When searching try to be smart about cases set smartcase " Makes search act like search in modern browsers set incsearch set shortmess-=S " For regular expressions turn magic on set magic " Show matching brackets when text indicator is over them set showmatch " How many tenths of a second to blink when matching brackets set mat=2 " No annoying sound on errors set noerrorbells set novisualbell set t_vb= set tm=500 " Set textwidth for markdown au BufRead,BufNewFile *.md setlocal textwidth=80 " Add a bit extra margin to the left set foldcolumn=1 syntax enable " Set utf8 as standard encoding set encoding=utf-8 set t_Co=256 set fillchars+=stl:\ ,stlnc:\ set term=xterm-256color set termencoding=utf-8 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Files, backups and undo """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Protect changes between writes. Default values of " updatecount (200 keystrokes) and updatetime " (4 seconds) are fine set swapfile set directory^=~/tmp/swap// " protect against crash-during-write set writebackup " but do not persist backup after successful write set nobackup " use rename-and-write-new method whenever safe set backupcopy=auto " patch required to honor double slash at end if has("patch-8.1.0251") " consolidate the writebackups -- not a big " deal either way, since they usually get deleted set backupdir^=~/tmp/backup// end """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Text, tab and indent related """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Use spaces instead of tabs set expandtab " Be smart when using tabs ;) set smarttab " 1 tab == 4 spaces set shiftwidth=4 set tabstop=4 " Linebreak on 500 characters set lbr set tw=500 set ai "Auto indent set si "Smart indent set wrap "Wrap lines au BufNewFile,BufRead *.py \ set tabstop=4 | \ set softtabstop=4 | \ set shiftwidth=4 | \ set textwidth=120 | \ set fileformat=unix | """""""""""""""""""""""""""""" " => Visual mode related """""""""""""""""""""""""""""" " Visual mode pressing * or # searches for the current selection " Super useful! From an idea by Michael Naumann vnoremap * :call VisualSelection('', '')/=@/ vnoremap # :call VisualSelection('', '')?=@/ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Moving around, tabs, windows and buffers """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Map to / (search) and Ctrl- to ? (backwards search) map / map ? " Disable highlight when is pressed map :noh " Smart way to move between windows map j map k map h map l " Close the current buffer map bd :Bclose:tabclosegT " Close all the buffers map ba :bufdo bd map l :bnext map k :bprevious " Useful mappings for managing tabs map tn :tabnew map to :tabonly map tc :tabclose map tm :tabmove map t :tabnext " Let 'tl' toggle between this and the last accessed tab let g:lasttab = 1 nmap tl :exe "tabn ".g:lasttab au TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory map te :tabedit =expand("%:p:h")/ " Switch CWD to the directory of the open buffer map cd :cd %:p:h:pwd " Specify the behavior when switching between buffers try set switchbuf=useopen,usetab,newtab set stal=2 catch endtry " Return to last edit position when opening files (You want this!) au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Plugin " Call PlugInstall after adding to this (need to reload vimrc) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" call plug#begin('~/.vim/plugged') Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'tpope/vim-fugitive' Plug 'mhinz/vim-signify' Plug 'sheerun/vim-polyglot' Plug 'joshdick/onedark.vim' Plug 'ctrlpvim/ctrlp.vim' Plug 'tpope/vim-eunuch' Plug 'google/vim-searchindex' Plug 'scrooloose/nerdcommenter' Plug 'kopischke/vim-fetch' Plug 'ntpeters/wim-better-whitespace' Plug 'jceb/vim-orgmode' call plug#end() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Editing mappings """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Remap VIM 0 to first non-blank character map 0 ^ " Move a line of text using ALT+[jk] or Command+[jk] on mac nmap mz:m+`z nmap mz:m-2`z vmap :m'>+`mzgv`yo`z vmap :m'<-2`>my` nmap vmap vmap endif " Delete trailing white space on save, useful for some filetypes ;) fun! CleanExtraSpaces() let save_cursor = getpos(".") let old_query = getreg('/') silent! %s/\s\+$//e call setpos('.', save_cursor) call setreg('/', old_query) endfun if has("autocmd") autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces() endif " shortcuts for 3-way merge map 1 :diffget LOCAL map 2 :diffget BASE map 3 :diffget REMOTE vmap "+yi vmap c"+p imap + set clipboard=unnamed " Aliases for common mistakes cnoreabbrev W w cnoreabbrev E e cnoreabbrev Q q cnoreabbrev WQ wq cnoreabbrev Wq wq """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Spell checking """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Pressing ,ss will toggle and untoggle spell checking map ss :setlocal spell! " Shortcuts using map sn ]s map sp [s map sa zg map s? z= """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Misc """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm " Quickly open a buffer for scribble map q :e ~/buffer " Quickly open a markdown buffer for scribble map x :e ~/buffer.md " Toggle paste mode on and off map pp :setlocal paste! " Jump to end and start of lines with no shift pressing map ' $ map [ ^ " Print full path map m :echo expand('%:p') """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Helper functions """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Returns true if paste mode is enabled function! HasPaste() if &paste return '[PASTE]' endif return '' endfunction " Don't close window, when deleting a buffer command! Bclose call BufcloseCloseIt() function! BufcloseCloseIt() let l:currentBufNum = bufnr("%") let l:alternateBufNum = bufnr("#") if buflisted(l:alternateBufNum) buffer # else bnext endif if bufnr("%") == l:currentBufNum new endif if buflisted(l:currentBufNum) execute("bdelete! ".l:currentBufNum) endif endfunction function! CmdLine(str) call feedkeys(":" . a:str) endfunction function! VisualSelection(direction, extra_filter) range let l:saved_reg = @" execute "normal! vgvy" let l:pattern = escape(@", "\\/.*'$^~[]") let l:pattern = substitute(l:pattern, "\n$", "", "") if a:direction == 'gv' call CmdLine("Ack '" . l:pattern . "' " ) elseif a:direction == 'replace' call CmdLine("%s" . '/'. l:pattern . '/') endif let @/ = l:pattern let @" = l:saved_reg endfunction fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun nnoremap t :call TrimWhitespace() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Plugin config """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Airline Cusomization """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if !exists('g:airline_symbols') let g:airline_symbols = {} endif " Tabline customization let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#buffer_idx_mode = 1 let g:airline#extensions#tabline#formatter = 'unique_tail' let g:airline#extensions#tabline#show_close_button = 0 let g:airline#extensions#tabline#show_tab_type = 0 " Style let g:airline_left_sep = '' let g:airline_left_alt_sep = '' let g:airline_right_sep = '' let g:airline_right_alt_sep = '' let g:airline_symbols.branch = '' let g:airline_symbols.readonly = '' let g:airline_symbols.linenr = 'ΒΆ' let g:airline_symbols.maxlinenr = '' " Remove file encoding if it's default let g:airline#parts#ffenc#skip_expected_string='utf-8[unix]' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Keymapping for plugins """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " CtrlP tag search map :CtrlP noremap "*y noremap "*p " Pytest nmap f :Pytest file nmap c :Pytest class nmap m :Pytest method """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Colorscheme and GUI """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" try set background=dark let g:onedark_termcolors=16 set termguicolors colorscheme onedark let g:airline_theme='onedark' catch echom "Onedark colorscheme not found..." endtry " Make visual selection the same colour as search highlight! link Visual Search set guifont=MesloLGSDZForPowerline-Regular:h13 ## ~~~ Aliases ~~~ # For a full list of active aliases, run `alias`. # Navigation alias ..='cd ..' alias ...='cd ../../../' alias ....='cd ../../../../' alias .....='cd ../../../../' # vim alias vi='vim' alias svi='sudo vi' alias edit='vim' alias bim='vim' # grep alias g='grep -sr' alias gg='grep -isr \!:1 *' alias gx='grep -isr --exclude-dir=\!:! \!:2 *' alias gp="grep --exclude='*[.py[~c]]" # Bash idioms alias mkdir='mkdir -p' alias rm='rm -f' # other alias x=ranger alias pre="bundle exec jekyll serve" alias ls='ls --color=always' alias lf='ls -F -l' alias ctags="`brew --prefix`/bin/ctags" alias c="open /Applications/PCalc.app" alias so='source $HOME/.zshrc' alias edc='vim $HOME/.zshrc' alias ip='public-ip' alias speedtest='speedtest-cli --secure' alias zshconfig='vim ~/.zshrc && rcupdate' alias monthly='$DOTFILES/setup/monthly' alias cdf='teach' alias pins='$SCRIPTS/utils/print_dots.sh python $SCRIPTS/random/pin_tags.py > /dev/null 2> /dev/null' alias articles='$SCRIPTS/random/article_log.py' alias clk='tty-clock -c -C 4' alias feeds='$SCRIPTS/todoist/feed-grabber.py' alias o='ofd' alias make='nocorrect make' alias mkdir='nocorrect mkdir' alias git='nocorrect git' alias nis='npm install --save' alias h='history | grep' alias cp='cp -v' alias p='playing' alias task='$SCRIPTS/todoist/todoist_utils.py' alias neofetch='neofetch --disable de wm' alias home='cd ~' alias diff='colordiff' alias ping='ping -c4' alias f='find . -iname' alias grep='ggrep -ni --colour=always' alias clear='[ $[$RANDOM % 100] = 0 ] && sl; clear || clear' alias c='clear' alias cl='clear && ls' alias h='history' alias tags='ctags -R' alias perf='gperf' alias songs='python $SCRIPTS/spotify/top_songs.py $SPOTIFY_USERNAME -e $SPOTIPY_TOP_SONGS_URI' alias install_plug='curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' alias spt='nocorrect spt' # git alias st='git status --short' alias go='git checkout' alias push='git push' alias add='git add -u' alias com='git commit' alias gd='git diff' alias gg='git grep' alias br='git branch' alias stash='git stash' alias del='git branch -D' alias revert='git checkout --' alias d='git diff' alias gpr='git pull --rebase' alias grm='git rebase master' # python alias flake=flake8 alias autopep8='autopep8 --in-place --aggressive' alias stylemeup='autopep8 --recursive .' alias fix='git ls-files --modified | autopep8'