From 0baae8a42baa47264f916bb502083dc6a4c53c4c Mon Sep 17 00:00:00 2001 From: Simon Milvert Date: Mon, 8 Jul 2019 18:17:08 +0200 Subject: [PATCH] Added bash and vim settings --- bash/bashrc | 536 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vim/vimrc | 496 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1032 insertions(+) create mode 100644 bash/bashrc create mode 100644 vim/vimrc diff --git a/bash/bashrc b/bash/bashrc new file mode 100644 index 0000000..f61de48 --- /dev/null +++ b/bash/bashrc @@ -0,0 +1,536 @@ +#! /bin/bash +# ~/.bashrc: executed by bash(1) for non-login shells. +# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) +# for examples + +# If not running interactively, don't do anything +case $- in + *i*) ;; +*) return;; +esac + +# don't put duplicate lines or lines starting with space in the history. +# See bash(1) for more options +HISTCONTROL=ignoreboth + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize +shopt -s cdspell +shopt -s cdable_vars +shopt -s checkhash +shopt -u mailwarn +shopt -s sourcepath +shopt -s no_empty_cmd_completion +shopt -s histappend histreedit +shopt -s extglob # useful for programmable completion + +bind "set completion-ignore-case on" +bind "set show-all-if-ambiguous on" + + +# If set, the pattern "**" used in a pathname expansion context will +# match all files and zero or more directories and subdirectories. +#shopt -s globstar + +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +# set a fancy prompt (non-color, unless we know we "want" color) +case "$TERM" in + xterm*|rxvt*) color_prompt=yes;; +esac +export PATH=/opt/tools/arm-unknown-linux-androideabi/bin:$PATH +export PATH=/opt/tools/x86_64-unknown-linux-gnu/bin:$PATH +export PATH=/opt/gcc-arm-none-eabi-4_9-2014q4/bin:$PATH +export JAVA_HOME=/usr/lib/jvm/java-8-oracle/ +export PATH="$HOME/.cabal/bin:$PATH" +# uncomment for a colored prompt, if the terminal has the capability; turned +# off by default to not distract the user: the focus in a terminal window +# should be on the output of commands, not on the prompt +force_color_prompt=yes + +if [ -n "$force_color_prompt" ]; then + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + color_prompt=yes + else + color_prompt=no + fi +fi + + + +# Normal Colors +Black='\e[0;30m' # Black +Red='\e[0;31m' # Red +Green='\e[0;32m' # Green +Yellow='\e[0;33m' # Yellow +Blue='\e[0;34m' # Blue +Purple='\e[0;35m' # Purple +Cyan='\e[0;36m' # Cyan +White='\e[0;37m' # White + +# Bold +BBlack='\e[1;30m' # Black +BRed='\e[1;31m' # Red +BGreen='\e[1;32m' # Green +BYellow='\e[1;33m' # Yellow +BBlue='\e[1;34m' # Blue +BPurple='\e[1;35m' # Purple +BCyan='\e[1;36m' # Cyan +BWhite='\e[1;37m' # White + +# Background +On_Black='\e[40m' # Black +On_Red='\e[41m' # Red +On_Green='\e[42m' # Green +On_Yellow='\e[43m' # Yellow +On_Blue='\e[44m' # Blue +On_Purple='\e[45m' # Purple +On_Cyan='\e[46m' # Cyan +On_White='\e[47m' # White + +NC="\e[m" # Color Reset + +COLOR_RED="\033[0;31m" +COLOR_YELLOW="\033[0;33m" +COLOR_GREEN="\033[0;32m" +COLOR_OCHRE="\033[38;5;95m" +COLOR_BLUE="\033[0;34m" +COLOR_WHITE="\033[0;37m" +COLOR_RESET="\033[0m" + +ALERT=${BWhite}${On_Red} # Bold White on red background + + +# Test connection type: +if [ -n "${SSH_CONNECTION}" ]; then + CNX=${Green} # Connected on remote machine, via ssh (good). +elif [[ "${DISPLAY%%:0*}" != "" ]]; then + CNX=${ALERT} # Connected on remote machine, not via ssh (bad). +else + CNX=${BCyan} # Connected on local machine. +fi + +# Test user type: +if [[ ${USER} == "root" ]]; then + SU=${Red} # User is root. +elif [[ ${USER} != $(logname) ]]; then + SU=${BRed} # User is not login user. +else + SU=${BCyan} # User is normal (well ... most of us are). +fi + + + +NCPU=$(grep -c 'processor' /proc/cpuinfo) # Number of CPUs +SLOAD=$(( 100*${NCPU} )) # Small load +MLOAD=$(( 200*${NCPU} )) # Medium load +XLOAD=$(( 400*${NCPU} )) # Xlarge load + +# Returns system load as percentage, i.e., '40' rather than '0.40)'. +function load() +{ + local SYSLOAD=$(cut -d " " -f1 /proc/loadavg | tr -d '.') + # System load of the current host. + echo $((10#$SYSLOAD)) # Convert to decimal. +} + +# Returns a color indicating system load. +function load_color() +{ + local SYSLOAD=$(load) + if [ ${SYSLOAD} -gt ${XLOAD} ]; then + echo -en ${ALERT} + elif [ ${SYSLOAD} -gt ${MLOAD} ]; then + echo -en ${Red} + elif [ ${SYSLOAD} -gt ${SLOAD} ]; then + echo -en ${BRed} + else + echo -en ${Green} + fi +} + +# Returns a color according to free disk space in $PWD. +function disk_color() +{ + if [ ! -w "${PWD}" ] ; then + echo -en ${Red} + # No 'write' privilege in the current directory. + elif [ -s "${PWD}" ] ; then + local used=$(command df -P "$PWD" | + awk 'END {print $5} {sub(/%/,"")}') + if [ ${used} -gt 95 ]; then + echo -en ${ALERT} # Disk almost full (>95%). + elif [ ${used} -gt 90 ]; then + echo -en ${BRed} # Free disk space almost gone. + else + echo -en ${Green} # Free disk space is ok. + fi + else + echo -en ${Cyan} + # Current directory is size '0' (like /proc, /sys etc). + fi +} + +# Returns a color according to running/suspended jobs. +function job_color() +{ + if [ $(jobs -s | wc -l) -gt "0" ]; then + echo -en ${BRed} + elif [ $(jobs -r | wc -l) -gt "0" ] ; then + echo -en ${BCyan} + fi +} + + +function git_color { +local git_status="$(git status 2> /dev/null)" + +if [[ ! $git_status =~ "working directory clean" ]]; then + echo -e $COLOR_GREEN +elif [[ $git_status =~ "Your branch is ahead of" ]]; then + echo -e $COLOR_YELLOW +elif [[ $git_status =~ "nothing to commit" ]]; then + echo -e $COLOR_GREEN +else + echo -e $COLOR_GREEN +fi +} +function git_branch { +local git_status="$(git status 2> /dev/null)" +local on_branch="On branch ([^${IFS}]*)" +local on_commit="HEAD detached at ([^${IFS}]*)" + +if [[ $git_status =~ $on_branch ]]; then + local branch=${BASH_REMATCH[1]} + echo "($branch)" +elif [[ $git_status =~ $on_commit ]]; then + local commit=${BASH_REMATCH[1]} + echo "($commit)" +else + echo "" +fi +} + +## https://github.com/twolfson/sexy-bash-prompt +if tput setaf 1 &> /dev/null; then + # Reset the shell from our `if` check + tput sgr0 &> /dev/null + # If you would like to customize your colors, use + # # Attribution: http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/ + # for i in $(seq 0 $(tput colors)); do + # echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)" + # done + # Save common color actions + prompt_bold="$(tput bold)" + prompt_reset="$(tput sgr0)" + # If the terminal supports at least 256 colors, write out our 256 color based set + if [[ "$(tput colors)" -ge 256 ]] &> /dev/null; then + prompt_user_color="$prompt_bold$(tput setaf 27)" # BOLD BLUE + prompt_preposition_color="$prompt_bold$(tput setaf 7)" # BOLD WHITE + prompt_device_color="$prompt_bold$(tput setaf 39)" # BOLD CYAN + prompt_dir_color="$prompt_bold$(tput setaf 76)" # BOLD GREEN + prompt_git_status_color="$prompt_bold$(tput setaf 154)" # BOLD YELLOW + prompt_git_progress_color="$prompt_bold$(tput setaf 9)" # BOLD RED + else + # Otherwise, use colors from our set of 8 + prompt_user_color="$prompt_bold$(tput setaf 4)" # BOLD BLUE + prompt_preposition_color="$prompt_bold$(tput setaf 7)" # BOLD WHITE + prompt_device_color="$prompt_bold$(tput setaf 6)" # BOLD CYAN + prompt_dir_color="$prompt_bold$(tput setaf 2)" # BOLD GREEN + prompt_git_status_color="$prompt_bold$(tput setaf 3)" # BOLD YELLOW + prompt_git_progress_color="$prompt_bold$(tput setaf 1)" # BOLD RED + fi + prompt_symbol_color="$prompt_bold" # BOLD +else + # Otherwise, use ANSI escape sequences for coloring + # If you would like to customize your colors, use + # DEV: 30-39 lines up 0-9 from `tput` + # for i in $(seq 0 109); do + # echo -n -e "\033[1;${i}mText$(tput sgr0) " + # echo "\033[1;${i}m" + # done + prompt_reset="\033[m" + prompt_user_color="\033[1;34m" # BLUE + prompt_preposition_color="\033[1;37m" # WHITE + prompt_device_color="\033[1;36m" # CYAN + prompt_dir_color="\033[1;32m" # GREEN + prompt_git_status_color="\033[1;33m" # YELLOW + prompt_git_progress_color="\033[1;31m" # RED + prompt_symbol_color="" # NORMAL +fi +# Apply any color overrides that have been set in the environment +if [[ -n "$PROMPT_USER_COLOR" ]]; then prompt_user_color="$PROMPT_USER_COLOR"; fi +if [[ -n "$PROMPT_PREPOSITION_COLOR" ]]; then prompt_preposition_color="$PROMPT_PREPOSITION_COLOR"; fi +if [[ -n "$PROMPT_DEVICE_COLOR" ]]; then prompt_device_color="$PROMPT_DEVICE_COLOR"; fi +if [[ -n "$PROMPT_DIR_COLOR" ]]; then prompt_dir_color="$PROMPT_DIR_COLOR"; fi +if [[ -n "$PROMPT_GIT_STATUS_COLOR" ]]; then prompt_git_status_color="$PROMPT_GIT_STATUS_COLOR"; fi +if [[ -n "$PROMPT_GIT_PROGRESS_COLOR" ]]; then prompt_git_progress_color="$PROMPT_GIT_PROGRESS_COLOR"; fi +if [[ -n "$PROMPT_SYMBOL_COLOR" ]]; then prompt_symbol_color="$PROMPT_SYMBOL_COLOR"; fi +# Set up symbols +prompt_synced_symbol="" +prompt_dirty_synced_symbol="*" +prompt_unpushed_symbol="△" +prompt_dirty_unpushed_symbol="▲" +prompt_unpulled_symbol="▽" +prompt_dirty_unpulled_symbol="▼" +prompt_unpushed_unpulled_symbol="⬡" +prompt_dirty_unpushed_unpulled_symbol="⬢" +# Apply symbol overrides that have been set in the environment +# DEV: Working unicode symbols can be determined via the following gist +# **WARNING: The following gist has 64k lines and may freeze your browser** +# https://gist.github.com/twolfson/9cc7968eb6ee8b9ad877 +if [[ -n "$PROMPT_SYNCED_SYMBOL" ]]; then prompt_synced_symbol="$PROMPT_SYNCED_SYMBOL"; fi +if [[ -n "$PROMPT_DIRTY_SYNCED_SYMBOL" ]]; then prompt_dirty_synced_symbol="$PROMPT_DIRTY_SYNCED_SYMBOL"; fi +if [[ -n "$PROMPT_UNPUSHED_SYMBOL" ]]; then prompt_unpushed_symbol="$PROMPT_UNPUSHED_SYMBOL"; fi +if [[ -n "$PROMPT_DIRTY_UNPUSHED_SYMBOL" ]]; then prompt_dirty_unpushed_symbol="$PROMPT_DIRTY_UNPUSHED_SYMBOL"; fi +if [[ -n "$PROMPT_UNPULLED_SYMBOL" ]]; then prompt_unpulled_symbol="$PROMPT_UNPULLED_SYMBOL"; fi +if [[ -n "$PROMPT_DIRTY_UNPULLED_SYMBOL" ]]; then prompt_dirty_unpulled_symbol="$PROMPT_DIRTY_UNPULLED_SYMBOL"; fi +if [[ -n "$PROMPT_UNPUSHED_UNPULLED_SYMBOL" ]]; then prompt_unpushed_unpulled_symbol="$PROMPT_UNPUSHED_UNPULLED_SYMBOL"; fi +if [[ -n "$PROMPT_DIRTY_UNPUSHED_UNPULLED_SYMBOL" ]]; then prompt_dirty_unpushed_unpulled_symbol="$PROMPT_DIRTY_UNPUSHED_UNPULLED_SYMBOL"; fi +function prompt_get_git_branch() { +# On branches, this will return the branch name +# On non-branches, (no branch) +ref="$(git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///')" +if [[ "$ref" != "" ]]; then + echo "$ref" +else + echo "(no branch)" +fi +} +function prompt_get_git_progress() { +# Detect in-progress actions (e.g. merge, rebase) +# https://github.com/git/git/blob/v1.9-rc2/wt-status.c#L1199-L1241 +git_dir="$(git rev-parse --git-dir)" +# git merge +if [[ -f "$git_dir/MERGE_HEAD" ]]; then + echo " [merge]" +elif [[ -d "$git_dir/rebase-apply" ]]; then + # git am + if [[ -f "$git_dir/rebase-apply/applying" ]]; then + echo " [am]" + # git rebase + else + echo " [rebase]" + fi +elif [[ -d "$git_dir/rebase-merge" ]]; then + # git rebase --interactive/--merge + echo " [rebase]" +elif [[ -f "$git_dir/CHERRY_PICK_HEAD" ]]; then + # git cherry-pick + echo " [cherry-pick]" +fi +if [[ -f "$git_dir/BISECT_LOG" ]]; then + # git bisect + echo " [bisect]" +fi +if [[ -f "$git_dir/REVERT_HEAD" ]]; then + # git revert --no-commit + echo " [revert]" +fi +} +prompt_is_branch1_behind_branch2 () { + # $ git log origin/master..master -1 + # commit 4a633f715caf26f6e9495198f89bba20f3402a32 + # Author: Todd Wolfson + # Date: Sun Jul 7 22:12:17 2013 -0700 + # + # Unsynced commit + # Find the first log (if any) that is in branch1 but not branch2 + first_log="$(git log $1..$2 -1 2> /dev/null)" + # Exit with 0 if there is a first log, 1 if there is not + [[ -n "$first_log" ]] +} +prompt_branch_exists () { + # List remote branches | # Find our branch and exit with 0 or 1 if found/not found + git branch --remote 2> /dev/null | grep --quiet "$1" +} +prompt_parse_git_ahead () { + # Grab the local and remote branch + branch="$(prompt_get_git_branch)" + remote_branch="origin/$branch" + # $ git log origin/master..master + # commit 4a633f715caf26f6e9495198f89bba20f3402a32 + # Author: Todd Wolfson + # Date: Sun Jul 7 22:12:17 2013 -0700 + # + # Unsynced commit + # If the remote branch is behind the local branch + # or it has not been merged into origin (remote branch doesn't exist) + if (prompt_is_branch1_behind_branch2 "$remote_branch" "$branch" || + ! prompt_branch_exists "$remote_branch"); then + # echo our character + echo 1 +fi +} +prompt_parse_git_behind () { + # Grab the branch + branch="$(prompt_get_git_branch)" + remote_branch="origin/$branch" + # $ git log master..origin/master + # commit 4a633f715caf26f6e9495198f89bba20f3402a32 + # Author: Todd Wolfson + # Date: Sun Jul 7 22:12:17 2013 -0700 + # + # Unsynced commit + # If the local branch is behind the remote branch + if prompt_is_branch1_behind_branch2 "$branch" "$remote_branch"; then + # echo our character + echo 1 + fi +} +function prompt_parse_git_dirty() { +# If the git status has *any* changes (e.g. dirty), echo our character +if [[ -n "$(git status --porcelain 2> /dev/null)" ]]; then + echo 1 +fi +} +function prompt_is_on_git() { + git rev-parse 2> /dev/null +} +function prompt_get_git_status() { +# Grab the git dirty and git behind +dirty_branch="$(prompt_parse_git_dirty)" +branch_ahead="$(prompt_parse_git_ahead)" +branch_behind="$(prompt_parse_git_behind)" +# Iterate through all the cases and if it matches, then echo +if [[ "$dirty_branch" == 1 && "$branch_ahead" == 1 && "$branch_behind" == 1 ]]; then + echo "$prompt_dirty_unpushed_unpulled_symbol" +elif [[ "$branch_ahead" == 1 && "$branch_behind" == 1 ]]; then + echo "$prompt_unpushed_unpulled_symbol" +elif [[ "$dirty_branch" == 1 && "$branch_ahead" == 1 ]]; then + echo "$prompt_dirty_unpushed_symbol" +elif [[ "$branch_ahead" == 1 ]]; then + echo "$prompt_unpushed_symbol" +elif [[ "$dirty_branch" == 1 && "$branch_behind" == 1 ]]; then + echo "$prompt_dirty_unpulled_symbol" +elif [[ "$branch_behind" == 1 ]]; then + echo "$prompt_unpulled_symbol" +elif [[ "$dirty_branch" == 1 ]]; then + echo "$prompt_dirty_synced_symbol" +else # clean + echo "$prompt_synced_symbol" +fi +} +prompt_get_git_info () { + # Grab the branch + branch="$(prompt_get_git_branch)" + # If there are any branches + if [[ "$branch" != "" ]]; then + # Echo the branch + output="$branch" + # Add on the git status + output="$output$(prompt_get_git_status)" + # Echo our output + echo "$output" + fi +} +# Symbol displayed at the line of every prompt +function prompt_get_prompt_symbol() { +# If we are root, display `#`. Otherwise, `$` +if [[ "$UID" == 0 ]]; then + echo "#" +else + echo "\$" +fi +} +# Adds some text in the terminal frame (if applicable). + +NON_VISABLE_HOST=(simon-alten ares simon-laptop) + +#Now we construct the prompt. +PROMPT_COMMAND="history -a" +case ${TERM} in + *term* | rxvt* | linux) + PS1="\[\$(load_color)\][\A\[${NC}\] " + # Time of day (with load info): + PS1="\[\$(load_color)\][\A\[${NC}\] " + # User@Host (with connection type info): + PS1=${PS1}"\[${SU}\]\u\[${NC}\]" + if [[ ! ${NON_VISABLE_HOST[*]} =~ $HOSTNAME ]]; then + PS1=${PS1}"\[${Purple}\] ($HOSTNAME)\[${NC}\]" + fi + # Git status + PS1=${PS1}"\$(prompt_is_on_git && \ + echo -n \" \[$prompt_git_status_color\]\$(prompt_get_git_info)\" && \ + echo -n \"\[$prompt_git_progress_color\]\$(prompt_get_git_progress)\" && \ + echo -n \"\[$prompt_preposition_color\]\")\[$prompt_reset\] " + # PWD (with 'disk space' info): + PS1=${PS1}"\[\$(disk_color)\]\W]\[${NC}\]" + # Prompt (with 'job' info): + PS1=${PS1}"\[\$(job_color)\] >\[${NC}\] " + # Set title of current xterm: + PS1=${PS1}"\[\e]0;[\u@\h] \w\a\]" + ;; + *) + PS1="(\A \u@\h \W) > " # --> PS1="(\A \u@\h \w) > " + # --> Shows full pathname of current dir. + ;; +esac + +export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n' +export HISTIGNORE="&:bg:fg:ll:h" +export HISTTIMEFORMAT="$(echo -e ${BCyan})[%d/%m %H:%M:%S]$(echo -e ${NC}) " +export HISTCONTROL=ignoredups +export HOSTFILE=$HOME/.hosts # Put a list of remote hosts in ~/.hosts + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + alias ls='ls --color=auto' + #alias dir='dir --color=auto' + #alias vdir='vdir --color=auto' + + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' +fi + +# some more ls aliases +alias ll='ls -alF' +alias la='ls -A' +alias l='ls -CF' + +# Add an "alert" alias for long running commands. Use like so: +# sleep 10; alert +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' + +# Alias definitions. +# You may want to put all your additions into a separate file like +# ~/.bash_aliases, instead of adding them here directly. +# See /usr/share/doc/bash-doc/examples in the bash-doc package. + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +# enable programmable completion features (you don't need to enable +# this, if it's already enabled in /etc/bash.bashrc and /etc/profile +# sources /etc/bash.bashrc). +if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi +fi + +export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting +PATH=$PATH:/usr/local/rvm/bin # Add RVM to PATH for scripting +export WORKON_HOME=~/.Envs diff --git a/vim/vimrc b/vim/vimrc new file mode 100644 index 0000000..3c974f1 --- /dev/null +++ b/vim/vimrc @@ -0,0 +1,496 @@ +" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just +" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime +" you can find below. If you wish to change any of those settings, you should +" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten +" everytime an upgrade of the vim packages is performed. It is recommended to +" make changes after sourcing debian.vim since it alters the value of the +" 'compatible' option. + +" This line should not be removed as it ensures that various options are +" properly set to work with the Vim-related packages available in Debian. +runtime! debian.vim + +" Uncomment the next line to make Vim more Vi-compatible +" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous +" options, so any other options should be set AFTER setting 'compatible'. +"set compatible + +" Vim5 and later versions support syntax highlighting. Uncommenting the next +" line enables syntax highlighting by default. +if has("syntax") + syntax on +endif + +" If using a dark background within the editing area and syntax highlighting +" turn on this option as well +set background=dark + +" Uncomment the following to have Vim jump to the last position when +" reopening a file +if has("autocmd") + au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif +endif + + +" Uncomment the following to have Vim load indentation rules and plugins +" according to the detected filetype. +filetype plugin indent on + +" The following are commented out as they cause vim to behave a lot +" differently from regular Vi. They are highly recommended though. +set showcmd " Show (partial) command in status line. +set showmatch " Show matching brackets. +set ignorecase " Do case insensitive matching +set smartcase " Do smart case matching +set incsearch " Incremental search +set autowrite " Automatically save before commands like :next and :make +set hidden " Hide buffers when they are abandoned +set mouse=a " Enable mouse usage (all modes) +set autoread +set number + +set fileencodings=utf-8 +set encoding=utf-8 +" Fast saving +nmap w :w! + + +" Configure backspace so it acts as it should act +set backspace=eol,start,indent +set whichwrap+=<,>,h,l + + +" Show matching brackets when text indicator is over them +set showmatch + +" Enable syntax highlighting +syntax enable + +"Highlight all search results +set hlsearch + +" For paste text +set pastetoggle= + +" Wrap lines +set wrap +" And treat log lones as break lines +map j gj +map k gk + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Files, backups and undo +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Turn backup off, since most stuff is in SVN, git et.c anyway... +set nobackup +set nowb +set noswapfile +" Set to auto read when a file is changed from the outside +set autoread + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Text, tab and indent related +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Use spaces instead of tabs +set expandtab + +" Be smart when using tabs ;) +set smarttab +set nofoldenable + +" 1 tab == 4 spaces +set shiftwidth=2 +set tabstop=2 +set softtabstop=2 +" Use 4 in python + +"""""""""""""""""""""""""""""""" +" => Map +"""""""""""""""""""""""" +"Disable arrows" +map +map +map +map + +"" Map space to \ +let mapleader = "\" + +"move between splits" +nnoremap +nnoremap +nnoremap +nnoremap + +" Switch to alternate file +map :bnext +map :bprevious + +" This replaces :tabnew which I used to bind to this mapping +nmap T :enew +" +" " Move to the next buffer +nmap l :bnext +" +" " Move to the previous buffer +nmap h :bprevious +" +" " Close the current buffer and move to the previous one +" " This replicates the idea of closing a tab +nmap bq :bp bd # +" +" " Show all open buffers and their status +nmap bl :ls + + +"Copy with mouse visual" +":noremap "+y" +"" OPen file +nnoremap o :CtrlP + +"" Savefile +nnoremap w :w + +"" Duplicate line +nnoremap t :t. +"" quit +nnoremap q :q +"" Save and quit +nnoremap wq :wq + + +map I# +nmap "+gP +imap i +vmap "+y + +" Find trailing whitspace +match ErrorMsg '\s\+$' + +"Remove trailing spaces with \rt +nmap rt :%s/\s\+$// + +" CTRL-T and CTRL-D indent and unindent blocks +inoremap +nnoremap +vnoremap > +vnoremap + + +" To save, ctrl-s. +nmap :w +imap :wa + +" Remove ctrl q" +nnoremap Q ZZ + + +" source $MYVIMRC reloads the saved $MYVIMRC +nmap s :source $MYVIMRC +" opens $MYVIMRC for editing, or use :tabedit $MYVIMRC +nmap v :e $MYVIMRC + +set clipboard=unnamedplus + +" +"""""""""""""""""""""""""""""""" +" => NeoBUndle +"""""""""""""""""""""""" + +"NeoBundle Scripts----------------------------- +if has('vim_starting') + set nocompatible " Be iMproved + + " Required: + set runtimepath+=~/.vim/bundle/neobundle.vim/ +endif + +" Required: +call neobundle#begin(expand('~/.vim/bundle')) + +" Let NeoBundle manage NeoBundle +" Required: +NeoBundleFetch 'Shougo/neobundle.vim' + +" My Bundles here: +NeoBundle 'terryma/vim-expand-region' +vmap v (expand_region_expand) +vmap (expand_region_shrink) + +NeoBundle 'Shougo/neosnippet.vim' +NeoBundle 'Shougo/neosnippet-snippets' +NeoBundle 'tpope/vim-git' +NeoBundle 'tpope/vim-fugitive' +NeoBundle 'kien/ctrlp.vim' +NeoBundle 'flazz/vim-colorschemes' +NeoBundleLazy 'nathanaelkane/vim-indent-guides' " color indentation +NeoBundle 'scrooloose/nerdtree' +"NeoBundle 'Valloric/YouCompleteMe', { +"" \ 'build' : { +"" \ 'mac' : './install.sh --clang-completer --system-libclang --omnisharp-completer', +"" \ 'unix' : './install.sh --clang-completer --system-libclang --omnisharp-completer', +"" \ 'windows' : './install.sh --clang-completer --system-libclang --omnisharp-completer', +"" \ 'cygwin' : './install.sh --clang-completer --system-libclang --omnisharp-completer' +"" \ } +"" \ } +"NeoBundle 'Valloric/YouCompleteMe', { +" \ 'build' : { +" \ 'mac' : './install.sh', +" \ }, +" \ } +" Syntax checker +NeoBundle 'scrooloose/syntastic' +NeoBundle 'vim-ruby/vim-ruby' "Ruby +NeoBundle 'tpope/vim-endwise' "Add endif, end and other stuff +""NeoBundleLazy 'masudaK/vim-python' +NeoBundle 'klen/python-mode' + +" Show gitdiff +NeoBundle 'airblade/vim-gitgutter' +" Disable plugins for LargeFile +NeoBundle 'vim-scripts/LargeFile' +NeoBundle 'vim-scripts/DoxygenToolkit.vim' "Generate doxygen +NeoBundle 'davidhalter/jedi-vim' "Generate doxygen +NeoBundle 'ervandew/supertab' "SuperTab +NeoBundle 'sukima/xmledit.git' "xmledit +NeoBundle 'yuroyoro/vim-autoclose' +NeoBundle 'tpope/vim-endwise' +NeoBundle 'scrooloose/nerdcommenter' "Comment out lines or blocks +NeoBundle 'nathanaelkane/vim-indent-guides' "Shows indents +NeoBundle 'nelstrom/vim-visual-star-search' "Search for visual with * +NeoBundle 'vim-airline/vim-airline' "For the status line +NeoBundle 'vim-airline/vim-airline-themes' "For the status line +NeoBundle 'bling/vim-bufferline' +"NeoBundle 'fholgado/minibufexpl.vim' +NeoBundle 'altercation/vim-colors-solarized' +NeoBundle 'ujihisa/unite-colorscheme' +NeoBundle 'docunext/closetag.vim.git' +NeoBundle 'skammer/vim-css-color' +NeoBundle 'StanAngeloff/php.vim' +NeoBundle 'mattn/emmet-vim/' +NeoBundle 'vim-scripts/keepcase.vim' +" Javascript +NeoBundle 'othree/yajs.vim' +NeoBundle 'othree/javascript-libraries-syntax.vim' +NeoBundle 'bigfish/vim-js-context-coloring' +NeoBundle 'vim-scripts/SyntaxComplete' +" Arduino +NeoBundle 'sudar/vim-arduino-syntax' +""NeoBundle 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'} " For the line in the bottom +" You can specify revision/branch/tag. +NeoBundle 'Shougo/vimshell', { 'rev' : '3787e5' } + +" Ctags" +NeoBundle 'xolox/vim-easytags' +NeoBundle 'majutsushi/tagbar' +NeoBundle 'xolox/vim-misc' + +" Required: +call neobundle#end() + +" Required: +filetype plugin indent on + +" If there are uninstalled bundles found on startup, +" this will conveniently prompt you to install them. +NeoBundleCheck +"End NeoBundle Scripts------------------------- + +"let g:pydiction_location = '~/.vim/bundle/pydiction/complete-dict' +nnoremap :exec '!python' shellescape(@%, 1) + +"""""""""""""""""""""""""""""""" +" => Javascript +"""""""""""""""""""""""" +let g:used_javascript_libs = 'angularjs,angularui,underscore' + + +"""""""""""""""""""""""""""""""" +" => Easytags +"""""""""""""""""""""""" +set tags=./tags;,tags; +let g:easytags_file = '~/.vim/tags' +let g:easytags_dynamic_files = 0 +let g:easytags_always_enabled = 0 + + + +"""""""""""""""""""""""""""""""" +" => Tagbar +"""""""""""""""""""""""" +nmap :TagbarToggle + + +"""""""""""""""""""""""""""""""" +" => GitGutter +"""""""""""""""""""""""" +""" IF SLOW """ +"let g:gitgutter_realtime = 0 +"let g:gitgutter_eager = 0 + +"""""""""""""""""""""""""""""""" +" => Emmet +"""""""""""""""""""""""" +let g:user_emmet_install_global = 0 +autocmd FileType html,css EmmetInstall + +"""""""""""""""""""""""""""""""" +" => php.vim +"""""""""""""""""""""""" +function! PhpSyntaxOverride() + hi! def link phpDocTags phpDefine + hi! def link phpDocParam phpType +endfunction + +augroup phpSyntaxOverride + autocmd! + autocmd FileType php call PhpSyntaxOverride() +augroup END + +"""""""""""""""""""""""""""""""" +" => closetag +"""""""""""""""""""""""" +autocmd FileType html,htmldjango,jinjahtml,eruby,mako let b:closetag_html_style=1 +autocmd FileType html,htmldjango,jinjahtml,eruby,mako source ~/.vim/bundle/closetag.vim/plugin/closetag.vim + + + + +"""""""""""""""""""""""""""""""" +" => xmledit +"""""""""""""""""""""""" +autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags noci + +"""""""""""""""""""""""""""""""" +" => vim-airline +"""""""""""""""""""""""" +let g:airline_theme='wombat' +let g:airline#extensions#tabline#enabled = 1 +" Show just the filename +let g:airline#extensions#tabline#fnamemod = ':t' +let g:airline#extensions#tabline#left_sep = ' ' +let g:airline#extensions#tabline#left_alt_sep = '|' + +let g:airline#extensions#syntastic#enabled = 1 + + +"""""""""""""""""""""""""""""""" +" => vim-indent_guides +"""""""""""""""""""""""" +colorscheme railscasts +set t_Co=256 +let g:indent_guides_enable_on_vim_startup = 1 +let g:indent_guides_guide_size = 1 +let g:indent_guides_start_level = 2 + + +"""""""""""""""""""""""""""""""" +" => ctrl-p +"""""""""""""""""""""""" +let g:ctrlp_map = '' +let g:ctrlp_cmd = 'CtrlPMixed' +let g:ctrlp_working_path_mode = 'c' +noremap :CtrlP /yourdir/ +set wildignore+=*/tmp/*,*.so,*.swp,*.zip + +" Try to ignore virtualenv, maybe to much :) +let g:ctrlp_custom_ignore = { + \ 'dir': '\v[\/](lib|htmlcov|bin|include|local|share|test|unittest)|(\.(git|hg|svn))$', + \ 'file': '\v\.(exe|so|dll)$', + \ 'link': 'some_bad_symbolic_links', + \ } + +"""""""""""""""""""""""""""""""" +" => LatexBox +"""""""""""""""""""""""" +"let g:LatexBox_latexmk_options = "-pvc -pdfps" + +"""""""""""""""""""""""""""""""" +" => Vim-Ruby +"""""""""""""""""""""""" +imap end-cc +autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete +autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1 +autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1 +autocmd FileType ruby,eruby let g:rubycomplete_rails = 1 + +"""""""""""""""""""""""""""""""" +" => Jedi-vim +"""""""""""""""""""""""" +let g:jedi#goto_assignments_command = "g" +let g:jedi#goto_definitions_command = "d" +let g:jedi#documentation_command = "K" +let g:jedi#usages_command = "n" +let g:jedi#completions_command = "" +let g:jedi#rename_command = "r" +let g:jedi#show_call_signatures = "1" +let g:jedi#popup_on_dot = 0 + +"""""""""""""""""""""""""""""""" +" => Syntatstic +"""""""""""""""""""""""" +"E111 = Indention is not a mulitple of four +let g:syntastic_sh_checkers = ['shellcheck', 'sh'] +let g:syntastic_python_checkers = ['flake8'] +let g:syntastic_python_flake8_args = '--ignore="E501,E302,E261,E701,E241,E126,E127,E128,W801,E111,E206"' +let g:syntastic_always_populate_loc_list = 1 +let g:syntastic_auto_loc_list = 1 + +"""""""""""""""""""""""""""""""" +" => NERDTree +"""""""""""""""""""""""" +"Autostart Nerdtree +"autocmd vimenter * NERDTree +autocmd StdinReadPre * let s:std_in=1 +autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif +map :NERDTree + +"""""""""""""""""""""""""""""""" +" => YouComplteMe +"""""""""""""""""""""""" +let g:ycm_autoclose_preview_window_after_completion=1 +let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/arduino/.ycm_extra_conf.py' +nnoremap g :YcmCompleter GoToDefinitionElseDeclaration + + +"""""""""""""""""""""""""""""""" +" => easymotion +"""""""""""""""""""""""" +let g:EasyMotion_do_mapping = 0 " Disable default mappings + +" Bi-directional find motion +" Jump to anywhere you want with minimal keystrokes, with just one key binding. +" `s{char}{label}` +nmap s (easymotion-s) +" or +" `s{char}{char}{label}` +" Need one more keystroke, but on average, it may be more comfortable. +nmap s (easymotion-s2) + +" Turn on case sensitive feature +let g:EasyMotion_smartcase = 1 + +" JK motions: Line motions +map j (easymotion-j) +map k (easymotion-k) + +"""""""""""""""""""""""""""""" +" => Status line +"""""""""""""""""""""""""""""" +" Always show the status line +set laststatus=2 + +" Format the status line +"set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l + +if has('gui_running') + set guioptions-=T " no toolbar + colorscheme elflord +endif + + +" Source a global configuration file if available +if filereadable("/etc/vim/vimrc.local") + source /etc/vim/vimrc.local +endif +