" URL: http://vim.wikia.com/wiki/Example_vimrc
" Authors: http://vim.wikia.com/wiki/Vim_on_Freenode
" Description: A minimal, but feature rich, example .vimrc. If you are a
"              newbie, basing your first .vimrc on this file is a good choice.
"              If you're a more advanced user, building your own .vimrc based
"              on this file is still a good idea.
"              Edited by Stephen Cook 03-02-2016
"
"
"------------------------------------------------------------
" Pathogen (auto-use files stored in bundle\ )
execute pathogen#infect()
"------------------------------------------------------------
" Features {{{1
"
" These options and commands enable some very useful features in Vim, that
" no user should have to live without.


" Set 'nocompatible' to ward off unexpected things that your distro might
" have made, as well as sanely reset options when re-sourcing .vimrc
 set nocompatible

" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
filetype indent plugin on

" Enable syntax highlighting
syntax on

" GB English highlighting when set spell is on
set spelllang=en_gb

"------------------------------------------------------------
"" Must have options {{{1
"
"" These are highly recommended options.

" Vim with default settings does not allow easy switching between multiple
" files in the same editor window. Users can use multiple split windows or
" multiple tab pages to edit multiple files, but it is still best to enable an
" option to allow easier switching between files.
"
" One such option is the 'hidden' option, which allows you to re-use the
" same window and switch from an unsaved buffer without saving it first. Also
" allows you to keep an undo history for multiple files when re-using the same
" window in this way. Note that using persistent undo also lets you undo in
" multiple files even in the same window, but is less efficient and is actually
" designed for keeping undo history after closing Vim entirely. Vim will
" complain if you try to quit without saving, and swap files will keep you safe
" if your computer crashes.
" set hidden

" Note that not everyone likes working this way (with the hidden option).
" Alternatives include using tabs or split windows instead of re-using the
" same window as mentioned above, and/or either of the following options:
" set confirm
" set autowriteall

" Better command-line completion
set wildmenu

" Show partial commands in the last line of the screen
set showcmd

" Highlight searches (use <C-L> to temporarily turn off highlighting; see
" the mapping of <C-L> below)
set hlsearch

" Modelines have historically been a source of security vulnerabilities. As
" such, it may be a good idea to disable them and use the securemodelines
" script, <http://www.vim.org/scripts/script.php?script_id=1876>.
set nomodeline


"------------------------------------------------------------
" Usability options {{{1
"
" These are options that users frequently set in their .vimrc. Some of them
" change Vim's behaviour in ways which deviate from the true Vi way, but
" which are considered to add usability. Which, if any, of these options to
" use is very much a personal preference, but they are harmless.

" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase

" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start

" When opening a new line and no filetype-specific indenting is enabled,
" keep the same indent as the line you're currently on. Useful for READMEs,
" etc.
set autoindent

" Makes search act like search in modern browsers
set incsearch

" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline

" Display the cursor position on the last line of the screen or in the
" status line of a window
set ruler

" Always display the status line, even if only one window is displayed
set laststatus=2
"set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l

" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm

" Use visual bell instead of beeping when doing something wrong
set visualbell

" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
" is unset, this does nothing.
set t_vb=

" Enable use of the mouse for all modes
"set mouse=a

" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
set cmdheight=2

" Display line numbers on the left
set number

" Quickly time out on keycodes, but never time out on mappings
set notimeout ttimeout ttimeoutlen=200

" Use <F9> to toggle between 'paste' and 'nopaste'
set pastetoggle=<F9>

"------------------------------------------------------------
"" Indentation options {{{1
"
"" Indentation settings according to personal preference.

" Indentation settings for using 2 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
set shiftwidth=2
set softtabstop=2
set expandtab

" Indentation settings for using hard tabs for indent. Display tabs as
" two characters wide.
"set shiftwidth=2
"set tabstop=2

"------------------------------------------------------------
" Mappings {{{1
"
" Useful mappings

" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
" which is the default
"map Y y$

" Map <C-L> (redraw screen) to also turn off search highlighting until the
" next search
nnoremap <C-L> :nohlsearch<CR><C-L>
" In diff mode have also found useful
"   nnoremap <C-L> :nohlsearch<CR>:diffupdate<CR><C-L>

" This allows us to type // in visual mode to search for the highlighted text
vnoremap // y/<C-R>"<CR>

"------------------------------------------------------------
" My additions
"
" From http://www.vim.org/scripts/script.php?script_id=2280
colorscheme blackboard
"colorscheme emacs
"colorscheme evening

" Window splits open below or right of current window
set splitbelow
set splitright

" Highlight trailing whitespace
match Todo '\s\+$'


" For future, might want to make use of linebreak and wrap. Can get rid of
" 'unwanted' linebreaks with the command :j

" Scroll just before hitting last line
if !&scrolloff
  set scrolloff=1
endif
if !&sidescrolloff
  set sidescrolloff=5
endif
set display+=lastline

" Read file if non-vim changes are detected
set autoread

if &history < 1000
  set history=1000
endif

" <C-U> kills the line. <C-G>u breaks the undo sequence
inoremap <C-U> <C-G>u<C-U>

"------------------------------------------------------------
" Mappings
nmap <F12> :call Changecol()<CR>
nmap <F10> :call Changecol()<CR>

" Sometimes <C-]> doesn't work navigating help links
let mapleader = "\\"
let maplocalleader = "\\"
nmap <LocalLeader>] <C-]>

" And CTRL-W tries to close windows if we're in Chrome SSH
nmap <LocalLeader>w <C-w>
nmap <LocalLeader>6 <C-^>
" Oh god, lets see what this is like
inoremap jk <esc>

nmap <LocalLeader>i i_<Esc>r
nmap <LocalLeader>a a_<Esc>r

" Accept that we sometimes accidentally use capitals
command Q q
command W w
command WQ wq
command Wq wq


"------------------------------------------------------------
" Playing with functions
function Changecol()
        " Function to switch between colorschemes emacs and blackboard
        if g:colors_name =~ "emacs"
                colorscheme blackboard
        elseif g:colors_name =~ "blackboard"
                colorscheme emacs
        else
                echo "Colorscheme not emacs or blackboard"
        endif
endfunction

" Returns true if paste mode is enabled
function! HasPaste()
    if &paste
        return 'PASTE MODE  '
    en
    return ''
endfunction
"------------------------------------------------------------
" Filetype stuffs
" Assume .f are f90, not f75, and .tex in latex
let fortran_free_source=1
let fortran_do_enddo=1
let g:tex_flavor='latex'

" Not sure. Maybe this should live in fortran.vim
set suffixesadd+=.f

"------------------------------------------------------------
" Plugins used
" - Pathogen
" - matchit.txt   Extended "%" matching
" - snipMate.txt  Plugin for using TextMate-style snippets in Vim
" - VimOrganizer.txt     for Vim versions with folding and tabs
" - ctrlp.txt       Fuzzy file, buffer, mru, tag, ... finder. v1.79
" - NERD_tree.txt   A tree explorer plugin that owns your momma!
" - fugitive.txt  A Git wrapper so awesome, it should be illegal
" - surround.txt  Plugin for deleting, changing, and adding "surroundings"
" - some matlab files (not in bundle)
"   == Not really using ==
" - NrrwRgn.txt   A Narrow Region Plugin (similar to Emacs)
" - utl_usr.txt Plugin for executing URLs in plain text files
"   == Not using ==
" - ~~vim-latex~~ (not using, seems heavy and the make picks up too many
"     warnings)
" - ~~vim-matlab-fold~~ Not using, didn't quite fold the right places, can
"     just use syntax folding

runtime ftplugin/man.vim

let g:snips_author="Stephen P. Cook"


au! BufRead,BufWrite,BufWritePost,BufNewFile *.org
au BufEnter *.org            call org#SetOrgFileType()

autocmd BufNewFile,BufReadPost *.md set filetype=markdown

" Deletes fugitive blob, tree and commit buffers
autocmd BufReadPost fugitive://* set bufhidden=delete

" Include git branch info in statusline
set statusline=%<%n\ %f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
" If this causes issues when fugitive isn't there, consider
"   %{exists('g:loaded_fugitive')?fugitive#statusline():''}

" On LCPU I've installed a more recent version of git. Want that one
let g:fugitive_git_executable='~/bin/git'

" Opens folds at current line on opening .tex files
autocmd BufRead *.tex, if foldlevel('.')>0 | execute "normal zv zz" | endif

" These should allow expected movement over wrapped lines (but messes up some
" movement commands, such as gqj
"noremap  <buffer> <silent> k gk
"noremap  <buffer> <silent> j gj
"noremap  <buffer> <silent> 0 g0
"noremap  <buffer> <silent> $ g$

command Bib badd ~/dos/biblio/all.bib

set iskeyword+=:,_