" Vim
" Gabe's vimrc files http://web.cs.uni-bonn.de/~zach/vim
" Version 1.2 (needs vim version >= 6.0)
" Please send correction & suggestions to me: zach@cs.uni-bonn.de
"
" Customization:
"   You'll probably want to change 'let &path' and 'let &tags';
"

"  for debugging :)
"echo 'executing my vimrc'
"set verbose+=2						" show which vimrc files are exec'd


"     Use vim defaults, not vi (much better! do this first)
set nocompatible

"
"     Options understood by all vi's (identical to ~/.exrc)
"

set autowrite showmode tabstop=4 shiftwidth=4 autoindent
set nowriteany
set exrc					" make vi(m) execute the ./.exrc (./.vimrc)

"
"     Variables
"     do a :help 'variable' for an explanation of vi variables
"
set modeline				" make vim execute 'modelines'
set nobackup writebackup  	" make backup, delete afterwards
set notitle icon
set helpheight=0
set incsearch				" incremental search
set nohlsearch				" don't highlight search pattern
set suffixes+=.bak,~,.o,.info,.aux,.dvi,.bbl,.log,.blg,.so,.ps,.gz
set scrolloff=2				" cursors stays 2 lines below/above top/bottom
set showcmd					" shows what you've typed in command mode
if has("unix")
	set shell=/bin/bash\ -p	" most of my scripts are bash
endif
set visualbell				" don't beep, instead flash
set cpoptions=ABFst
set sidescroll=1
set updatecount=50 updatetime=3600000		" saves power on notebooks
set ttyfast lazyredraw
"set paste					" many other useful options are turned off by this
set cmdheight=2				" prevents most "type return" messages
set mouse=nvc				" in insert mode, cursor stays during highlighting
set mousemodel=popup		" activate popup menu with right mouse-button
set backspace=indent,eol,start		" allow backspacing over start of insert
set whichwrap=b,s,h,l,<,>,~,[,]	" allow line wrap for certain cursor motions
set timeoutlen=200
set wildmode=list:full		" list all matches and complete each full match
set wildignore=*.o,*.old,*.cpy	" ignore files in filename completion
set mousetime=300			" maximum time in msec to recognize a double-click
set infercase				" only relevant if ignorecase is set
set smartcase				" /Smart/ is case-sensitive no matter what 'ic' is
set clipboard=autoselect 	" try to become owner of wm's clipboard
set directory=/usr/tmp		" put swap files only there, in case of LAN dropout
set updatetime=3600000
set updatecount=50 			" make frequent swap file updates
set noruler					" some Linux distros set this in the system vimrc
set formatoptions+=n2		" in plain text, gq recognizes numbered lists 
set nofoldenable			" switch off folding by default (startup time!)

" PC-specific settings
if has("win32")
	set directory=c:/tmp
	set clipboard+=unnamed	" on PCs, we can utilize the clipboard
endif
" Laptop-specific settings
if hostname() == "PC PC377"
	set updatecount=300		" laptop; save power
endif


"
"   Set path of other resource files, depending on whether
"   we are on a unix box, or on a windoze thingy.
"   (Is there a more elegant way?)
"

let g:rcpath = expand("<sfile>:p:h")
if has("unix")
	let g:rcpath = g:rcpath . "/.vim/"
else
	let g:rcpath = g:rcpath . "\\"
endif


"
"              Settings for vt100
"

if $REMOTEHOST =~ 'isdn.*' || $TERM == "vt100"
	" make vim a bit more responsive when on slow terminal
	" and set some keyboard mappings (IMHO, those shouldn't be necessary)
	set noincsearch nottyfast
	set ttyscroll=5
	set timeoutlen=200 scrolljump=2

	"  Keymaps for vt100
	map <ESC>[A <up>
	map <ESC>[B <down>
	map <ESC>[D <left>
	map <ESC>[C <right>
	map! <ESC>[A <up>
	map! <ESC>[B <down>
	map! <ESC>[D <left>
	map! <ESC>[C <right>

	" map function keys on <Fx>
	if $REMOTEHOST =~ 'isdn.*'
		" telnet from Laptop
		map [11~ <F1>
		map! [11~ <F1>
		map [12~ <F2>
		map! [12~ <F2>
		map [13~ <F3>
		map! [13~ <F3>
		map [14~ <F4>
		map! [14~ <F4>
		map [15~ <F5>
		map! [15~ <F5>
	else
		" login from Ampex terminal
		map <Esc>[7~ <F1>
		map! <Esc>[7~ <F1>
		map <Esc>[8~ <F2>
		map! <Esc>[8~ <F2>
		map <Esc>[9~ <F3>
		map! <Esc>[9~ <F3>
		map <Esc>[10~ <F4>
		map! <Esc>[10~ <F4>
		map <Esc>[11~ <F5>
		map! <Esc>[11~ <F5>
	endif
	map <Esc>[17~ <F6>
	map! <Esc>[17~ <F6>
	map <Esc>[18~ <F7>
	map! <Esc>[18~ <F7>
	map <Esc>[19~ <F8>
	map! <Esc>[19~ <F8>
	map <Esc>[20~ <F9>
	map! <Esc>[20~ <F9>
	map <Esc>[21~ <F10>
	map! <Esc>[21~ <F10>
	map <Esc>[23~ <F11>
	map! <Esc>[23~ <F11>
	map <Esc>[24~ <F12>
	map! <Esc>[24~ <F12>
	map <Esc>[25~ <F13>
	map! <Esc>[25~ <F13>
	map <Esc>[26~ <F14>
	map! <Esc>[26~ <F14>
	map <Esc>[28~ <F15>
	map! <Esc>[28~ <F15>
	map <Esc>[29~ <F16>
	map! <Esc>[29~ <F16>
endif


"
"   General utility keymaps
"

"   for word completion
imap <Insert> <C-P>
imap <Del> <C-N>

"   function keys
"   (remember that in my xterm's F1,F2,F5,F6 are mapped to "ls", "ll", etc.)
nmap <F1> :ls<CR>
imap <F1> <ESC>:ls<CR>
vmap <F1> v:ls<CR>
nmap <F2> :ls<CR>:e#
imap <F2> <ESC>:ls<CR>:e#
vmap <F2> v:ls<CR>:e#
nmap <F9> :w<CR>
imap <F9> <ESC>:w<CR>i
vmap <F9> v:w<CR>
nmap <F4> :set ignorecase!<CR>:set ignorecase?<CR>

"    1-key jumps to top/bottom
if &term =~ "xterm"
	nmap <Esc>OX 1G
	nmap <Esc>OY G
else
	" works for xwsh, at least; and gvim, of course
	nmap <Home> 1G
	nmap <End> G
endif
nmap <Insert> i <esc>

"   Format paragraphs (nobody needs the orig. Q command ;-)
nnoremap Q gqap
vnoremap Q gq

"   Put string marked by visual mode as default for search commands / and ?
"   Warning: extending the marked text by searching doesn't work any more.
vnoremap / y/<C-R>=escape(substitute(@","\n.*",'',''),'/\?*.$^~][')<CR>
vnoremap ? y?<C-R>=escape(substitute(@","\n.*",'',''),'/\?*.$^~][')<CR>
"   Explanation:
" substitute(@",..) - remove lines after first, if >1 line highlighted
" escape(..)        - put '\' before all characters meaningful in regexp's
" y                 - yank current selection (in register ")
" ctrl-r = .. <cr>  - put expression after / as earch string
" credits go to Stefan Roemer and Peppe (Preben Guldberg).

"   Remove whitespace from lines containing nothing else (grr to all nedit users)
nmap <F10> :%s/\s\+$//<CR>``

"   On german PC's ctrl-] doesn't work, because ] can be reached only with AltGr
if has("win32")
	nmap <C-K> <C-]>
endif



"
"    File types
" See also ~/.vim/filetype.vim
"

filetype on
filetype plugin on



"
"     Customization of plugins
"

let spell_auto_type=""



"
"    Syntax highlighting
"

if &term == "iris-ansi"
	" from http://pigseye.kennesaw.edu/~dharriso/vim/vimrc.html
	set t_Co=8
	set t_ZH=[3m   	" Italics ON
	set t_ZR=[23m  	" Italics OFF
	set t_us=[4m   	" Underline ON
	set t_ue=[24m  	" Underline OFF
	set t_md=[1m   	" Bold ON
	set t_me=[0m   	" Normal mode (No bold, italics, etc.)
	set t_mr=[7m   	" Reverse video ON
	set t_AB=[4%p1%dm " Set the background
	set t_AF=[3%p1%dm " Set the foreground
elseif &term == "xterm"
	"  from :help color
	set t_Co=16
	if has("terminfo")
	  set t_Sf=[3%p1%dm	" <esc>! (ctrl-v <esc>)
	  set t_Sb=[4%p1%dm
	else
	  set t_Sf=[3%dm
	  set t_Sb=[4%dm
	endif
endif

syntax on

if hlexists("Type")
	hi Type cterm=bold
	hi Statement cterm=bold
endif

if ! has("unix")
	" we're on a laptop probably; for faster highlighting, decrease sync lines
	syn sync maxlines=50
	syn sync minlines=10
endif



"
"       Menus in console vim
"
"  press F11 to bring up menus in console-vim

if ! has("gui_running")
	set wildmenu wildcharm=<C-Z>
	nmap <F11> :runtime menu.vim<CR>:emenu <C-Z>
endif



"      Font menu

amenu F&ont.&5x7			:set guifont=5x7<CR><C-L>
amenu F&ont.&6x10			:set guifont=6x10<CR><C-L>
amenu F&ont.6x13			:set guifont=6x13<CR><C-L>
amenu F&ont.&7x13			:set guifont=7x13<CR><C-L>
amenu F&ont.&8x13			:set guifont=8x13<CR><C-L>
amenu F&ont.&9x15			:set guifont=9x15<CR><C-L>
amenu F&ont.&10x20			:set guifont=10x20<CR><C-L>
amenu F&ont.&12x24			:set guifont=12x24<CR><C-L>
amenu F&ont.&heabfix		:set guifont=-*-haebfix-medium-r-normal-*-15-*-*-*-*-*-*-*<CR><C-L>
amenu F&ont.&lucida			:set guifont=-*-lucidatypewriter-medium-r-*-*-14-*-*-*-*-*-*-*<CR><C-L>



"
"      Misc menu
"

amenu Misc.Remove\ &trailing\ white-space<Tab>F10	:%s/\s\+$//<CR>``
amenu Misc.&Save\ Viminfo							:set viminfo='7,n./viminfo<CR>:wv<CR>:set viminfo=<CR>
amenu Misc.Toggle\ case\ for\ searching<Tab>F4		:set ignorecase!<CR>:set ignorecase?<CR>
amenu Misc.Toggle\ highlight\ search\ results		:set hlsearch!<CR>:set hlsearch?<CR>
amenu Misc.Spell\ Check\ Menu						:runtime my/spellcheck.vim<CR>
amenu Misc.All\ Chars\ Menu							:runtime my/char_menu.vim<CR>




