From d2894162a1e6d1315a91d0e48677a6eb47ccaf7d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 4 Dec 2018 15:04:10 +1300 Subject: Use "stub .vimrc" method to dodge vim-tiny --- Makefile | 3 +- vim/vimrc | 224 +++++++++++++++++++++++++---------------------------- vim/vimrc.stub.vim | 4 + 3 files changed, 113 insertions(+), 118 deletions(-) create mode 100644 vim/vimrc.stub.vim diff --git a/Makefile b/Makefile index 882982c6..2629ec55 100644 --- a/Makefile +++ b/Makefile @@ -517,7 +517,7 @@ install-urxvt: urxvt/ext/select VIM = vim VIMDIR = $(HOME)/.vim -VIMRC = $(HOME)/.vimrc +VIMRC = $(HOME)/.vim/vimrc install-vim: install-vim-after \ install-vim-autoload \ @@ -582,6 +582,7 @@ install-vim-compiler: cp -p -- vim/compiler/*.vim $(VIMDIR)/compiler install-vim-config: install-vim-cache + cp -p -- vim/vimrc.stub.vim $(HOME)/.vimrc cp -p -- vim/vimrc $(VIMRC) if [ -e /etc/debian_version ] ; then \ cp -p -- vim/system/debian.vim $(VIMDIR)/system.vim ; \ diff --git a/vim/vimrc b/vim/vimrc index 0e489226..f5ffec73 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1,20 +1,5 @@ " Tom Ryder (tejr)'s vimrc: -" -" This file is designed to load on any build of Vim version 7.0 or newer, -" including tiny builds without +eval. - -" Require at least Vim 7.0 (released 2006-05-08); otherwise, self-suppress as -" much of this config as possible -if v:version < 700 - if has('win32') || has('win64') - set runtimepath-=~/vimfiles - set runtimepath-=~/vimfiles/after - else - set runtimepath-=~/.vim - set runtimepath-=~/.vim/after - endif - finish -endif +" Requires Vim 7.0 or newer with +eval. " Undo anything the operating system's vimrc may have broken runtime system.vim @@ -38,8 +23,14 @@ if has('syntax') silent! colorscheme sahara endif - " If not sahara, then default with dark background - if !exists('g:colors_name') + " If my colorscheme loaded, turn on subtle 'cursorline' coloring + if exists('g:colors_name') && g:colors_name ==# 'sahara' + if exists('+cursorline') + set cursorline + endif + + " If it didn't load, default to default scheme with dark background + else set background=dark endif @@ -58,22 +49,22 @@ set backspace+=start " The start of current insertion " Try to keep backups in one system-appropriate dir set backup -set backupdir^=~/.vim/cache/backup if has('win32') || has('win64') - set backupdir-=~/.vim/cache/backup set backupdir^=~/vimfiles/cache/backup +else + set backupdir^=~/.vim/cache/backup endif " Add some paths not to back up -set backupskip^=/dev/shm/* " Shared memory RAM disk -set backupskip^=/var/tmp/* " Debian's $TMPDIR for sudoedit(8) -if !has('unix') - set backupskip-=/dev/shm/* - set backupskip-=/var/tmp/* +if has('unix') + set backupskip^=/dev/shm/* " Shared memory RAM disk + set backupskip^=/var/tmp/* " Debian's $TMPDIR for sudoedit(8) endif -" Indent wrapped lines -silent! set breakindent +" Indent wrapped lines if supported +if exists('+breakindent') + set breakindent +endif " Clear default 'comments' value, let the filetype handle it set comments= @@ -87,18 +78,11 @@ endif " Give me a prompt instead of just rejecting risky :write, :saveas set confirm -" Only turn on 'cursorline' if my colorscheme loaded -if exists('+cursorline') - if exists('g:colors_name') && g:colors_name ==# 'sahara' - set cursorline - endif -endif - " Try to keep swapfiles in one system-appropriate dir -set directory^=~/.vim/cache/swap// if has('win32') || has('win64') - set directory-=~/.vim/cache/swap// set directory^=~/vimfiles/cache/swap// +else + set directory^=~/.vim/cache/swap// endif " Use UTF-8 if we can and env LANG didn't tell us not to @@ -107,8 +91,10 @@ if has('multi_byte') && !exists('$LANG') && &encoding ==# 'latin1' endif " Don't wait for a key after Escape in insert mode -" In vim-tiny but not NeoVim, so just suppress errors -silent! set noesckeys +" Not in NeoVim +if exists('+esckeys') + set noesckeys +endif " Fold based on indent, but only when I ask if has('folding') @@ -117,7 +103,9 @@ if has('folding') endif " Delete comment leaders when joining lines, if supported -silent! set formatoptions+=j +if v:version > 703 || v:version == 703 && has('patch541') + set formatoptions+=j +endif " If available, use GNU grep niceties for searching if system('grep --version') =~# '^grep (GNU grep)' @@ -137,9 +125,7 @@ set history=2000 " Highlight completed searches; clear on reload set hlsearch -if 1 - nohlsearch -endif +nohlsearch " Don't assume I'm editing C; let the filetype set this set include= @@ -163,11 +149,11 @@ set lazyredraw set linebreak " Define extra 'list' display characters -set listchars+=extends:> " Unwrapped text to screen right -set listchars+=precedes:< " Unwrapped text to screen left -set listchars+=tab:>- " Tab characters, preserve width -set listchars+=trail:_ " Trailing spaces -silent! set listchars+=nbsp:+ " Non-breaking spaces +set listchars+=extends:> " Unwrapped text to screen right +set listchars+=precedes:< " Unwrapped text to screen left +set listchars+=tab:>- " Tab characters, preserve width +set listchars+=trail:_ " Trailing spaces +set listchars+=nbsp:+ " Non-breaking spaces " Don't allow setting options via buffer content set nomodeline @@ -205,7 +191,9 @@ set splitright " Right of the current window, not left set timeoutlen=3000 " No terminal mouse, even if we could -silent! set ttymouse= +if exists('+ttymouse') + set ttymouse= +endif " Keep undo files, hopefully in a dedicated directory if has('persistent_undo') @@ -218,9 +206,11 @@ if has('persistent_undo') endif " Wildmenu settings; see also plugin/wildignore.vim -set wildmenu " Use wildmenu -set wildmode=list:longest " Tab press completes and lists -silent! set wildignorecase " Case insensitive, if supported +set wildmenu " Use wildmenu +set wildmode=list:longest " Tab press completes and lists +if exists('+wildignorecase') + set wildignorecase " Case insensitive, if supported +endif " Let me move beyond buffer text in visual block mode if exists('+virtualedit') @@ -273,164 +263,164 @@ nnoremap ]l :lnext nmap [ (PutBlankLinesAbove) nmap ] (PutBlankLinesBelow) -" Normal leader maps; use not for vim-tiny +" Normal leader maps; use not for vim-tiny " \a toggles 'formatoptions' 'a' flag using a plugin -nnoremap a :ToggleFlagLocal formatoptions a +nnoremap a :ToggleFlagLocal formatoptions a " \b toggles copy-pasteable linebreak settings -nmap b (CopyLinebreakToggle) +nmap b (CopyLinebreakToggle) " \c toggles 'cursorline'; no visual mode map as it doesn't work -nnoremap c :setlocal cursorline! cursorline? +nnoremap c :setlocal cursorline! cursorline? " \C toggles 'cursorcolumn'; works in visual mode -nnoremap C :setlocal cursorcolumn! cursorcolumn? -xnoremap C :setlocal cursorcolumn! cursorcolumn?gv +nnoremap C :setlocal cursorcolumn! cursorcolumn? +xnoremap C :setlocal cursorcolumn! cursorcolumn?gv " \d inserts the local date (POSIX date) -nnoremap d :read !date +nnoremap d :read !date " \D inserts the UTC date (POSIX date) -nnoremap D :read !date -u +nnoremap D :read !date -u " \e forces a buffer to be editable -nnoremap e :setlocal modifiable noreadonly +nnoremap e :setlocal modifiable noreadonly " \f shows the current 'formatoptions' at a glance -nnoremap f :setlocal formatoptions? +nnoremap f :setlocal formatoptions? " \F reloads filetype plugins -nnoremap F :doautocmd filetypedetect BufRead +nnoremap F :doautocmd filetypedetect BufRead " \g changes directory to the current file's location -nnoremap g :cd %:h:pwd +nnoremap g :cd %:h:pwd " \h toggles highlighting search results -nnoremap h :set hlsearch! hlsearch? +nnoremap h :set hlsearch! hlsearch? " \H shows command history -nnoremap H :history : +nnoremap H :history : " \i toggles showing matches as I enter my pattern -nnoremap i :set incsearch! incsearch? +nnoremap i :set incsearch! incsearch? " \j jumps to buffers (jetpack) -nnoremap j :buffers:buffer +nnoremap j :buffers:buffer " \k shows my marks -nnoremap k :marks +nnoremap k :marks " \l toggles showing tab, end-of-line, and trailing whitespace -nnoremap l :setlocal list! list? -xnoremap l :setlocal list! list?gv +nnoremap l :setlocal list! list? +xnoremap l :setlocal list! list?gv " \m shows normal maps -nnoremap m :map +nnoremap m :map " \M shows buffer-local normal maps -nnoremap M :map +nnoremap M :map " \n toggles line number display -nnoremap n :setlocal number! number? -xnoremap n :setlocal number! number?gv +nnoremap n :setlocal number! number? +xnoremap n :setlocal number! number?gv " \N toggles position display in bottom right -nnoremap N :set ruler! ruler? -xnoremap N :set ruler! ruler?gv +nnoremap N :set ruler! ruler? +xnoremap N :set ruler! ruler?gv " \o opens a line below in paste mode -nmap o (PasteOpenBelow) +nmap o (PasteOpenBelow) " \O opens a line above in paste mode -nmap O (PasteOpenAbove) +nmap O (PasteOpenAbove) " \p toggles paste mode -nnoremap p :set paste! paste? +nnoremap p :set paste! paste? " \q formats the current paragraph -nnoremap q gqap +nnoremap q gqap " \r acts as a replacement operator -nmap r (ReplaceOperator) -xmap r (ReplaceOperator) +nmap r (ReplaceOperator) +xmap r (ReplaceOperator) " \R reloads ~/.vimrc -nnoremap R :source $MYVIMRC +nnoremap R :source $MYVIMRC " \s toggles spell checking -nnoremap s :setlocal spell! spell? +nnoremap s :setlocal spell! spell? " \t shows current filetype -nnoremap t :setlocal filetype? +nnoremap t :setlocal filetype? " \T clears filetype -nnoremap T :setlocal filetype= +nnoremap T :setlocal filetype= " \u sets US English spelling (compare \z) -nnoremap u :setlocal spelllang=en_us +nnoremap u :setlocal spelllang=en_us " \v shows all global variables -nnoremap v :let g: v: +nnoremap v :let g: v: " \V shows all local variables -nnoremap V :let b: t: w: +nnoremap V :let b: t: w: " \w toggles wrapping -nnoremap w :setlocal wrap! wrap? -xnoremap w :setlocal wrap! wrap?gv +nnoremap w :setlocal wrap! wrap? +xnoremap w :setlocal wrap! wrap?gv " \x strips trailing whitespace via a custom plugin -nmap x :StripTrailingWhitespace -xmap x :StripTrailingWhitespace +nmap x :StripTrailingWhitespace +xmap x :StripTrailingWhitespace " \X squeezes repeated blank lines via a custom plugin -nmap X :SqueezeRepeatBlanks -xmap X :SqueezeRepeatBlanks +nmap X :SqueezeRepeatBlanks +xmap X :SqueezeRepeatBlanks " \y shows all registers -nnoremap y :registers +nnoremap y :registers " \z sets NZ English spelling (compare \u) -nnoremap z :setlocal spelllang=en_nz +nnoremap z :setlocal spelllang=en_nz " \= runs the whole buffer through =, preserving position -nnoremap = :call vimrc#Anchor('1G=G') +nnoremap = :call vimrc#Anchor('1G=G') " \+ runs the whole buffer through gq, preserving position -nnoremap + :call vimrc#Anchor('1GgqG') +nnoremap + :call vimrc#Anchor('1GgqG') " \. runs the configured make program into the location list -nnoremap . :lmake! +nnoremap . :lmake! " \< and \> adjust indent of last edit; good for pasting -nnoremap :'[,'] -nnoremap > :'[,']> +nnoremap :'[,'] +nnoremap > :'[,']> " \_ uses last changed or yanked text as a characterwise object -onoremap _ :normal! `[v`] +onoremap _ :normal! `[v`] " \% uses entire buffer as a linewise object -onoremap % :normal! 1GVG +onoremap % :normal! 1GVG " \{ and \} move to lines with non-space chars before current column -nmap { (VerticalRegionUpNormal) -nmap } (VerticalRegionDownNormal) -omap { (VerticalRegionUpOperator) -omap } (VerticalRegionDownOperator) -xmap { (VerticalRegionUpVisual) -xmap } (VerticalRegionDownVisual) +nmap { (VerticalRegionUpNormal) +nmap } (VerticalRegionDownNormal) +omap { (VerticalRegionUpOperator) +omap } (VerticalRegionDownOperator) +xmap { (VerticalRegionUpVisual) +xmap } (VerticalRegionDownVisual) " \/ types :vimgrep for me ready to enter a search pattern -nnoremap / :vimgrep /\c/ ** +nnoremap / :vimgrep /\c/ ** " \? types :helpgrep for me ready to enter a search pattern -nnoremap ? :helpgrep \c +nnoremap ? :helpgrep \c " \DEL deletes the current buffer -nnoremap :bdelete +nnoremap :bdelete " \INS edits a new buffer -nnoremap :enew +nnoremap :enew " Execution mappings; each of these clobbers register z " \@ executes line in normal mode -nnoremap @ ^"zyg_@z +nnoremap @ ^"zyg_@z " \: executes line in command mode -nnoremap : ^"zyg_:z +nnoremap : ^"zyg_:z " \! executes line with 'shell' -nnoremap ! ^"zyg_:!z +nnoremap ! ^"zyg_:!z " Source any .vim files from ~/.vim/config runtime! config/*.vim diff --git a/vim/vimrc.stub.vim b/vim/vimrc.stub.vim new file mode 100644 index 00000000..51ca436a --- /dev/null +++ b/vim/vimrc.stub.vim @@ -0,0 +1,4 @@ +" If we have Vim version >=7, and (implicitly) +eval, source real vimrc +if v:version >= 700 + runtime vimrc +endif -- cgit v1.2.3