Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
436 lines (358 sloc) 13.9 KB
" Options that should occur early {{{1
" a more efficient leader characters
let mapleader=","
let maplocalleader=";"
" remap comma (i.e., for reversing line find)
nnoremap ,, ,
vnoremap ,, ,
nnoremap ;; ;
vnoremap ;; ;
set nocompatible
syntax enable "enable syntax highlighting
filetype on "enable file type detection
filetype plugin on
filetype indent on
" Backup behaviour {{{1
" prevent backup files from clutering up directories
cd ~/documents
set backup
set backupdir=~/vimfiles/backup
set directory=~/vimfiles/tmp
set autowrite "automatically save when buffer changes
set autowriteall "save all files on exit
set history=400 "have a long history of commands
" autocmd BufLeave,FocusLost silent! wall "consider auto-saving on buffer exit
" Visual Appearance {{{1
" colorscheme = oceandeep
" colorscheme inkpot "Color scheme
colorscheme molokai
set tabstop=4 "set tabs to 4 spaces.
set expandtab "convert tabs to spaces
set shiftwidth=4 "spaces used for auto indent
set hidden " allow buffers to be not displayed but still open
set wildmenu " facilitate autocompletion with tabbed search on command line
set guifont=courier_new:h10:b " Better Font
set ruler "show the cursor position all the time
"set ch=2 "make command line two lines high
set scrolloff=3 "keep the cursor three lines below top
" set colorcolumn=85 "add a vertical line to indicate desired wrap point
"disabled as a general setting because it is annoying on
"many file types
set guioptions-=T "remove toolbar
set guicursor=a:blinkon0 " remove blinking cursor
" Set the status line from Derek Wyatt
set stl=%f\ %m\ %r\ Lin/e:%l/%L[%p%%]\ Col:%c\ Buf:%n\ [%b][0x%B]
set laststatus=2 " always include status line even if only one window
set mousehide " hide mouse when typing
set shellslash " desired by latex-suite
" Assorted Behaviour {{{1
set backspace=indent,eol,start " backspace for dummys
set shortmess=atI " fewer prompts
"edit vimrc and source vimrc
nmap <silent> <Leader>ve :e $HOME/vimfiles/myvimrc<cr>
nmap <silent> <Leader>vs :so $MYVIMRC<cr>
" When vimrc is edited, reload it (currently seems to cause an error, but I like
" the idea:
" autocmd! bufwritepost myvimrc source $HOME/vimfiles/myvimrc<CR>
set virtualedit=all " allows cursor to go anywhere in file
set spl=en_au spell " Activate Australian English Spell Checking
set nospell " Disable spell checking by default
" ensure vimrc file folds properly
au BufEnter *vimrc setlocal foldmethod=marker
"Toggle spelling shortcut key
map <Leader>sp :setlocal spell!<CR>
set showcmd " Show (partial) command in the last line of the screen
set number " Show line numbers
"set hlsearch "show matches highlighted (disabled because I found it distracting)
set nohlsearch
set incsearch " show search matches while typing
set ignorecase " Ignore case when search
set smartcase "except when capital letters used
set textwidth=80 "number of columns before file auto-wraps
" set selection=exclusive "set by mswin
" maximise on start
au GUIEnter * simalt ~x
" toggle hlsearch
nmap <silent> <leader>n :set hlsearch! hlsearch?<CR>
" Make Ctrl+Backspace delete previous word in Insert Mode and command-line mode
imap <C-BS> <C-W>
cmap <C-BS> <C-W>
" Change working directory to that of open file
map <Leader>cd :cd %:p:h<CR>
" Easy Session Save (ss) or Session Load (sl)
" removed 'options' from sessionoptions; makes it easier to add plugin
" restart Vim and restore files, windows, and buffers.
set sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize
map <Leader>ss :mksession! $HOME/vim_session <cr>
map <Leader>sl :source $HOME/vim_session <cr>
" speed up scrolling
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" facilitate find command
map <leader>f :find
" Open Web browser
function! Browser ()
"let line = getline (".")
"let line = matchstr (line, "\%(http://\|www\.\)[^ ,;\t]*")
let line = matchstr(getline("."), "http://.[^ ,;\t]*")
let line = "\"".line."\""
let line = ":silent !start chrome ".line
return line
endfunction
map <Leader>w :exe Browser()<CR>
" from http://stackoverflow.com/questions/3909350/what-are-ways-to-reduce-mode-errors-while-learning-vim/3909391#3909391
" Give greater visual feedback about when in insert mode
" Disabled because flashing is annoying and it sometimes makes text harder to
" read.
" autocmd InsertEnter * set cursorline
" autocmd InsertLeave * set nocursorline
" prevents x from deleting folds (from ZyX on SO)
nnoremap <expr> x ((foldclosed('.')==-1)?('x'):('zx'))
" always add the current file's directory to the path if not already there
autocmd BufRead *
\ let s:tempPath=escape(escape(expand("%:p:h"), ' '), '\ ') |
\ exec "set path-=".s:tempPath |
\ exec "set path+=".s:tempPath
" modified version of mswin.vim
" I'm gradually removing features that otherwise cause a conflict,
source $HOME/vimfiles/mswin.vim
" Built in Diff function {{{
set diffexpr=MyDiff()
function! MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
" Plugins {{{1
" Nerd Tree {{{2
"Toggle the file explorer program Nerd Tree.
map <F2> :NERDTreeToggle<CR>
let NERDTreeShowBookmarks=1 " Show bookmarks on startup
" open Nerd Tree in folder of file in active buffer
map <Leader>nt :NERDTree %:p:h<CR>
" R-Plugin Customisations {{{2
" Source my customised versions of the functions
" I'm sticking to making changes in the main file now
" so ~/vimfiles/anglim_vim-r.vim
let vimrplugin_r_args = "--sdi --no-save --internet2 --quiet"
let vimrplugin_editor_w = 88
let vimrplugin_help_w = 88
" disable unwanted auto conversion
let vimrplugin_underscore = 0 "underscore is used frequently in R code
let vimrplugin_rnowebchunk = 0
" Consider using Standard RGui for a while
let vimrplugin_conqueplugin = 0
" Attempt to make console more responsive
"let vimrplugin_conquevsplit = 1 "activate console vertically
"let vimrplugin_conquesleep = 500
"let ConqueTerm_CWInsert = 1
"let ConqueTerm_Color = 0
"let ConqueTerm_ReadUnfocused = 1
"nmap <F5> :call RScrollTerm()<CR>
" pause time when not using conque
let vimrplugin_sleeptime = 0.1
" custom commands:
" Select rnw R code bleck and send echo
" function! SendRCodeChunk()
" function! SendSexpr()
map <LocalLeader>r2 ?>>=<Enter>jV/^@<Enter>k ;se<Esc>
map <LocalLeader>r3 0/Sexpr{<CR>wvi};se<Esc>
" R code folding
" let r_syntax_folding = 1 " disabled because I prefer my own
function! RLevel()
if getline(v:lnum) =~ '^### '
return ">1"
endif
if getline(v:lnum) =~ '^\S.*<-.*function'
return ">2"
endif
if getline(v:lnum) =~ '^#### '
return ">2"
endif
if getline(v:lnum) =~ '^##### '
return ">3"
endif
return "="
endfunction
au BufEnter *.r setlocal foldexpr=RLevel()
au BufEnter *.r setlocal foldmethod=expr
" ensure that LaTeX Suite is loaded when working with Rnw files
au BufEnter *.Rnw set filetype=tex | set filetype=rnoweb
" Update fold structure on save using LaTeX Suite
au BufWritePre *.Rnw set filetype=tex | call MakeTexFolds(1) | set filetype=rnoweb
" Latex-Suite {{{2
let g:tex_flavor='latex' " ensure that files with tex extension load latex-suite
let g:Tex_DefaultTargetFormat='pdf' " compile to pdf by default
let g:Tex_SmartKeyQuote = 0 "disables annoying quotation mark conversion
let Tex_FoldedSections ="part,chapter,section,%%fakesection,subsection,subsubsection,paragraph,pd"
"toggle fold style
function! ToggleFoldSectionsPD()
if g:Tex_FoldedSections == "part,chapter,section,%%fakesection,subsection,subsubsection,paragraph,pd"
let g:Tex_FoldedSections = "part,chapter,section,%%fakesection,subsection,subsubsection,paragraph"
let currentft = &filetype
set filetype=tex
call MakeTexFolds(1)
exe "set filetype=" . currentft
return
endif
if g:Tex_FoldedSections == "part,chapter,section,%%fakesection,subsection,subsubsection,paragraph"
let g:Tex_FoldedSections = "part,chapter,section,%%fakesection,subsection,subsubsection,paragraph,pd"
let currentft = &filetype
set filetype=tex
call MakeTexFolds(1)
exe "set filetype=" . currentft
return
endif
endfunction
map <leader>pd :call ToggleFoldSectionsPD()<CR>
" for now I'm preferring to manually insert folds using pd instead of auto
" folding the environments below
" let Tex_FoldedEnvironments = "verbatim,comment,eq,gather,align,figure,table,thebibliography,keywords,abstract,titlepage"
let Tex_FoldedEnvironments = "frame"
" let Tex_FoldedMisc = "item,preamble,<<<"
let Tex_FoldedMisc = "preamble"
" ensure latex style files are treated as tex files
au BufEnter *.sty set filetype=tex
" adjust indentation for tex files
au BufEnter *.tex setlocal tabstop=2
au BufEnter *.tex setlocal shiftwidth=2
" update folds on save
au BufWritePre *. set call MakeTexFolds(1)
" consider disabling built in indentation
let g:tex_indent_items = 0
" Beamer {{{2
function! BeamerLevel()
if getline(v:lnum) =~ '^\\section.*$' || getline(v:lnum) =~ '^%# ' ||
\ getline(v:lnum) =~ '\\begin{document}' ||
\ getline(v:lnum) =~ '\\end{document}'
return ">1"
endif
if getline(v:lnum) =~ '^\\subsection.*$' || getline(v:lnum) =~ '^%## '
return ">2"
endif
" think about whether 2 or 3 would be better
if getline(v:lnum) =~ '\\begin{frame}'
return ">2"
endif
return "="
endfunction
function! BeamerFold()
setlocal foldexpr=BeamerLevel()
setlocal foldmethod=expr
endfunction
" FuzzyFinding {{{2
" nmap <Leader>fb :FuzzyFinderBuffer<CR>
" nmap <Leader>ff :FuzzyFinderFile<CR>
" nmap <Leader>ft :FuzzyFinderTag<CR>
" voom customiations {{{2
let g:voom_tree_width = 50 " default is 50 columns wide
" cygwin customisations {{{2
" set shell=C:/cygwin/bin/bash
" set shellcmdflag=--login\ -c
" set shellxquote=\"
set shellcmdflag=-c
set shellquote=
set shellslash " Use the forward slash for expansion.
set shellxquote=\"
set shell=c:/cygwin/bin/bash.exe " Use the bash shell
set shellpipe=2>&1\|\ tee
set shellredir=>%s\ 2>&1
" Markdown customisations {{{2
function! MarkdownLevel(maxlevel)
if a:maxlevel >= 1 && getline(v:lnum) =~ '^# .*$'
return ">1"
endif
if a:maxlevel >= 2 && getline(v:lnum) =~ '^## .*$'
return ">2"
endif
if a:maxlevel >= 3 && getline(v:lnum) =~ '^### .*$'
return ">3"
endif
if a:maxlevel >= 4 && getline(v:lnum) =~ '^#### .*$'
return ">4"
endif
if a:maxlevel >= 5 && getline(v:lnum) =~ '^##### .*$'
return ">5"
endif
if a:maxlevel >= 6 && getline(v:lnum) =~ '^###### .*$'
return ">6"
endif
return "="
endfunction
" for my blog posts 2 levels is good
" I do use more heading levels, but folding of level 3 and 4 is generally
" annoying
au BufEnter *.md setlocal foldexpr=MarkdownLevel(2)
au BufEnter *.md setlocal foldmethod=expr
au BufEnter *.md setlocal autoindent
" Copy HTML of markdown file to system clipboard
function! MarkdownToHTML()
endfunction
nmap <leader>md :%s/^#/###/<cr>:%!perl ~/Markdown.pl<cr>gg"*yGu
" vimoutliner {{{2
" adopt a smaller indentation
au BufEnter *.otl map! <buffer> <S-Tab> <C-D>
" au BufEnter *.otl map! <buffer> <Tab> <C-T>
au BufEnter *.otl map <buffer> <S-Tab> <<
" au BufEnter *.otl map <buffer> <Tab> >>
au BufEnter *.otl setlocal tabstop=2
au BufEnter *.otl setlocal shiftwidth=2
" Enable long headings with various wrapping features
au BufEnter *.otl setlocal wrap
au BufEnter *.otl set showbreak=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
au BufEnter *.otl setlocal linebreak
" macro to enable adding heading below folded heading at same level as fold
au FileType vo_base map <leader>o kjzO^y0zco<Esc>0DPA<Esc>zxA
" remove any blank lines when saving outline
" WARNING: If you don't know what this does, don't use it
au BufWritePre *.otl :silent g/^\s*$/ d
" MRU {{{2
" Saves the buffer if it has unsaved changes and loads MRU
" This is a hack to ensure that when I press ENTER in MRU
" file opens in the current window
map <Leader>m :update<CR>:MRU<CR>
let MRU_Max_Entries = 150
" Inquisit {{{2
" Functions to make it easier to write Inquisit scripts
function! InquisitHelp(topic)
let commandtext = "keyhh -\\\#alink \"" . a:topic . "\" \"c:\\Program Files\\Millisecond Software\\Inquisit 3\\inquisit.chm\""
exe ":!start " . commandtext
return
endfunction
au BufEnter *.exp set ft=inquisit
function! InquisitLevel(elements)
" TODO: add headings: 1 (just allow #) or 2 (allow nested ##)
" elements: 0 or 1
if getline(v:lnum) =~ '^# .*$'
return ">1"
endif
if a:elements && getline(v:lnum) =~ '^<[a-zA-Z].*$'
return ">2"
endif
return "="
endfunction
au BufEnter *.exp setlocal foldexpr=InquisitLevel(1)
au BufEnter *.exp setlocal foldmethod=expr
au BufEnter *.exp setlocal iskeyword=a-z,A-Z,48-57,.
function! RunInquisit()
let cmdstring = "!start inquisit " . '"%:p"'
exe cmdstring
endfunction