From a1ee04d02877e1312fa2e7020da658f601551583 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 1 Nov 2017 14:16:19 +1300 Subject: Make 'shellslash' setting conditional on feature :help 'shellslash' says: > 'shellslash' only works when a backslash can be used as a path > separator. To test if this is so use: > if exists('+shellslash') This has actually already been done before in 795fd10, but the change was lost in a merge with a branch that restructured the whole Vim configuration. --- vim/command.vim | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 vim/command.vim diff --git a/vim/command.vim b/vim/command.vim new file mode 100644 index 00000000..af7c8e36 --- /dev/null +++ b/vim/command.vim @@ -0,0 +1,39 @@ +" Keep plenty of command and search history, because disk space is cheap +set history=2000 + +" Always tell me the number of lines changed by a command +set report=0 + +" Command-line based features +if has('cmdline_info') + + " Show my current position in the status bar + set ruler + + " Show the keystrokes being entered in the screen + set showcmd + + " Show the mode we're using if not normal mode (e.g. --INSERT--) + set showmode +endif + +" Always use forward slashes, I very seldom need to use Vim on Windows for +" more than scratch space anyway +if exists('+shellslash') + set shellslash +endif + +" Tolerate typos like :Wq, :Q, or :Qa and do what I mean, including any +" arguments or modifiers; I fat-finger these commands a lot because I type +" them so rapidly, and they don't correspond to any other commands I use +if has('user_commands') + command! -bang -complete=file -nargs=? E e + command! -bang -complete=file -nargs=? W w + command! -bang -complete=file -nargs=? WQ wq + command! -bang -complete=file -nargs=? Wq wq + command! -bang Q q + command! -bang Qa qa + command! -bang QA qa + command! -bang Wa wa + command! -bang WA wa +endif -- cgit v1.2.3 From 570f7b060c6a9a70c8543216fe40822a8ab35730 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 1 Nov 2017 14:40:28 +1300 Subject: Move 'shellpipe' setting to more logical location It makes more sense next to 'shellslash' in vim/config/command.vim than it does in vim/config/term.vim; the latter file is supposed to describe settings related to the terminal, not the shell. --- vim/config/command.vim | 3 +++ vim/config/term.vim | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/config/command.vim b/vim/config/command.vim index a7389cfb..1d2b647a 100644 --- a/vim/config/command.vim +++ b/vim/config/command.vim @@ -17,6 +17,9 @@ if has('cmdline_info') set showmode endif +" Don't write the output of :make to the terminal +set shellpipe=> + " Always use forward slashes, I very seldom need to use Vim on Windows for " more than scratch space anyway set shellslash diff --git a/vim/config/term.vim b/vim/config/term.vim index f368e481..8dbda431 100644 --- a/vim/config/term.vim +++ b/vim/config/term.vim @@ -22,6 +22,3 @@ set timeoutlen=1000 " correctly; I don't use Escape as a meta key anyway set ttimeout set ttimeoutlen=50 - -" Don't write the output of :make to the terminal -set shellpipe=> -- cgit v1.2.3 From eed5c3a4c4d01ea69ab653a6da036fa59cdb71ee Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 1 Nov 2017 14:42:22 +1300 Subject: Move 'tildeop' setting to new case.vim file Since it pertains to the casing of text, and there are potentially other items that could go in here too. --- vim/config/case.vim | 3 +++ vim/config/tildeop.vim | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 vim/config/case.vim delete mode 100644 vim/config/tildeop.vim diff --git a/vim/config/case.vim b/vim/config/case.vim new file mode 100644 index 00000000..bb21aefd --- /dev/null +++ b/vim/config/case.vim @@ -0,0 +1,3 @@ +" Use the tilde as an operator with motions, rather than just swapping the +" case of the character under the cursor +set tildeop diff --git a/vim/config/tildeop.vim b/vim/config/tildeop.vim deleted file mode 100644 index bb21aefd..00000000 --- a/vim/config/tildeop.vim +++ /dev/null @@ -1,3 +0,0 @@ -" Use the tilde as an operator with motions, rather than just swapping the -" case of the character under the cursor -set tildeop -- cgit v1.2.3 From a0cc0969ee1cc1f295bc865161432d4be467cffa Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:07:33 +1300 Subject: Move Vim big file options config into plugin Created targets install-vim-doc and install-vim-plugin with accompanying subdirectories of "vim". Added a very short summary of what the plugin does to bigfile.txt. I intend to spin off at least a couple of the blocks of my Vim configuration that are starting to coalesce into distinct plugins unto themselves, and will place the files in these directories. --- Makefile | 12 +++++++++++- vim/config/bigfile.vim | 28 ---------------------------- vim/doc/bigfile.txt | 12 ++++++++++++ vim/plugin/bigfile.vim | 28 ++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 29 deletions(-) delete mode 100644 vim/config/bigfile.vim create mode 100644 vim/doc/bigfile.txt create mode 100644 vim/plugin/bigfile.vim diff --git a/Makefile b/Makefile index 6440b805..c09541fd 100644 --- a/Makefile +++ b/Makefile @@ -474,9 +474,11 @@ install-urxvt: urxvt/ext/select install-vim: install-vim-after \ install-vim-bundle \ install-vim-config \ + install-vim-doc \ install-vim-ftdetect \ install-vim-ftplugin \ - install-vim-indent + install-vim-indent \ + install-vim-plugin install-vim-after: find vim/after -name .git -prune -o \ @@ -493,6 +495,10 @@ install-vim-config: cp -p -- vim/vimrc $(HOME)/.vimrc cp -p -- vim/config/*.vim $(HOME)/.vim/config +install-vim-doc: + mkdir -p -- $(HOME)/.vim/doc + cp -p -- vim/doc/*.txt $(HOME)/.vim/doc + install-vim-ftdetect: mkdir -p -- $(HOME)/.vim/ftdetect cp -p -- vim/ftdetect/*.vim $(HOME)/.vim/ftdetect @@ -505,6 +511,10 @@ install-vim-indent: mkdir -p -- $(HOME)/.vim/indent cp -p -- vim/indent/*.vim $(HOME)/.vim/indent +install-vim-plugin: + mkdir -p -- $(HOME)/.vim/plugin + cp -p -- vim/plugin/*.vim $(HOME)/.vim/plugin + install-vim-gui: install-vim \ install-vim-gui-config diff --git a/vim/config/bigfile.vim b/vim/config/bigfile.vim deleted file mode 100644 index 5c68b1a7..00000000 --- a/vim/config/bigfile.vim +++ /dev/null @@ -1,28 +0,0 @@ -" When opening a large file, take some measures to keep things loading quickly -if has('eval') && has('autocmd') - - " Threshold is 10 MiB - let g:big_file_size = 10 * 1024 * 1024 - - " Declare function for turning off slow options - function! s:BigFileMeasures() - let l:file = expand('') - if getfsize(l:file) > g:big_file_size - setlocal nobackup - setlocal nowritebackup - setlocal noswapfile - if has('persistent_undo') - setlocal noundofile - endif - if exists('&synmaxcol') - setlocal synmaxcol=256 - endif - endif - endfunction - - " Define autocmd for calling to check filesize - augroup dotfiles_big_file_measures - autocmd! - autocmd BufReadPre * call s:BigFileMeasures() - augroup end -endif diff --git a/vim/doc/bigfile.txt b/vim/doc/bigfile.txt new file mode 100644 index 00000000..d7e56f28 --- /dev/null +++ b/vim/doc/bigfile.txt @@ -0,0 +1,12 @@ +*bigfile.txt* Disable slow options for big files to speed things up + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin adds an |autocmd| hook to check the file size of an incoming +buffer, and if it's over a certain threshold, disables certain options in order +to make the file a bit easier to edit. + +This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun +off into a separate distribution as it solidifies and this documentation +improves. diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim new file mode 100644 index 00000000..5c68b1a7 --- /dev/null +++ b/vim/plugin/bigfile.vim @@ -0,0 +1,28 @@ +" When opening a large file, take some measures to keep things loading quickly +if has('eval') && has('autocmd') + + " Threshold is 10 MiB + let g:big_file_size = 10 * 1024 * 1024 + + " Declare function for turning off slow options + function! s:BigFileMeasures() + let l:file = expand('') + if getfsize(l:file) > g:big_file_size + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile + endif + if exists('&synmaxcol') + setlocal synmaxcol=256 + endif + endif + endfunction + + " Define autocmd for calling to check filesize + augroup dotfiles_big_file_measures + autocmd! + autocmd BufReadPre * call s:BigFileMeasures() + augroup end +endif -- cgit v1.2.3 From dc6ff333e5d537b7702d6565ac06c271c7f7e761 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:12:14 +1300 Subject: Expand comment header for bigfile.vim Include some author and license metadata. --- vim/plugin/bigfile.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim index 5c68b1a7..d1d9ca61 100644 --- a/vim/plugin/bigfile.vim +++ b/vim/plugin/bigfile.vim @@ -1,4 +1,11 @@ -" When opening a large file, take some measures to keep things loading quickly +" +" bigfile.vim: When opening a large file, take some measures to keep things +" loading quickly. +" +" Author: Tom Ryder +" Copyright: 2017 +" License: Same as Vim itself +" if has('eval') && has('autocmd') " Threshold is 10 MiB -- cgit v1.2.3 From 080a0802d95ce3d89a4cfd9dded76d11b3092e88 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:13:32 +1300 Subject: Make bigfile size variable an option with default This arranges for g:big_file_size only to set itself to 10 MiB if the variable is not already set, presumably by the user in their vimrc. --- vim/plugin/bigfile.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim index d1d9ca61..7f28c539 100644 --- a/vim/plugin/bigfile.vim +++ b/vim/plugin/bigfile.vim @@ -8,8 +8,10 @@ " if has('eval') && has('autocmd') - " Threshold is 10 MiB - let g:big_file_size = 10 * 1024 * 1024 + " Default threshold is 10 MiB + if !exists('g:big_file_size') + let g:big_file_size = 10 * 1024 * 1024 + endif " Declare function for turning off slow options function! s:BigFileMeasures() -- cgit v1.2.3 From 17bd794328560cf68c23db2f2a1b04526abe932b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:18:04 +1300 Subject: Rename variable and autocmd to use plugin prefix Just removing an underscore from the variable name so that g:big_file_size becomes g:bigfile_size, and remove the "dotfiles" prefix from the autocmd. --- vim/plugin/bigfile.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim index 7f28c539..962d7153 100644 --- a/vim/plugin/bigfile.vim +++ b/vim/plugin/bigfile.vim @@ -9,14 +9,14 @@ if has('eval') && has('autocmd') " Default threshold is 10 MiB - if !exists('g:big_file_size') - let g:big_file_size = 10 * 1024 * 1024 + if !exists('g:bigfile_size') + let g:bigfile_size = 10 * 1024 * 1024 endif " Declare function for turning off slow options function! s:BigFileMeasures() let l:file = expand('') - if getfsize(l:file) > g:big_file_size + if getfsize(l:file) > g:bigfile_size setlocal nobackup setlocal nowritebackup setlocal noswapfile @@ -30,7 +30,7 @@ if has('eval') && has('autocmd') endfunction " Define autocmd for calling to check filesize - augroup dotfiles_big_file_measures + augroup bigfile_options_bufreadpre autocmd! autocmd BufReadPre * call s:BigFileMeasures() augroup end -- cgit v1.2.3 From e316ef5df7c70fb67a07886b48c95d36a4e8c984 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:20:00 +1300 Subject: Refactor plugin function for dependency injection Pass the filename to check and the size limit into the function directly from the autocmd hook. Improve commenting and spacing as we go. --- vim/plugin/bigfile.vim | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim index 962d7153..82d1a7dd 100644 --- a/vim/plugin/bigfile.vim +++ b/vim/plugin/bigfile.vim @@ -14,24 +14,32 @@ if has('eval') && has('autocmd') endif " Declare function for turning off slow options - function! s:BigFileMeasures() - let l:file = expand('') - if getfsize(l:file) > g:bigfile_size - setlocal nobackup - setlocal nowritebackup - setlocal noswapfile - if has('persistent_undo') - setlocal noundofile - endif - if exists('&synmaxcol') - setlocal synmaxcol=256 - endif + function! s:BigFileOptions(name, size) + + " Don't do anything if the file is under the threshold + if getfsize(a:name) <= a:size + return + endif + + " Turn off backups, swap files, and undo files + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile endif + + " Limit the number of columns of syntax highlighting + if exists('&synmaxcol') + setlocal synmaxcol=256 + endif + endfunction " Define autocmd for calling to check filesize augroup bigfile_options_bufreadpre autocmd! - autocmd BufReadPre * call s:BigFileMeasures() + autocmd BufReadPre * call s:BigFileOptions(expand(''), g:bigfile_size) augroup end + endif -- cgit v1.2.3 From 607a1b5a2ece6053b7849402041b06178d7d699c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:25:54 +1300 Subject: Make bigfile 'synmaxcol' setting configurable Defaults to 256 columns and only sets it if the option's value isn't already lower than that. --- vim/plugin/bigfile.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim index 82d1a7dd..c5dee62a 100644 --- a/vim/plugin/bigfile.vim +++ b/vim/plugin/bigfile.vim @@ -13,6 +13,11 @@ if has('eval') && has('autocmd') let g:bigfile_size = 10 * 1024 * 1024 endif + " Cut 'synmaxcol' down to this or smaller for big files + if !exists('g:bigfile_size_synmaxcol') + let g:bigfile_size_synmaxcol = 256 + endif + " Declare function for turning off slow options function! s:BigFileOptions(name, size) @@ -30,8 +35,8 @@ if has('eval') && has('autocmd') endif " Limit the number of columns of syntax highlighting - if exists('&synmaxcol') - setlocal synmaxcol=256 + if exists('&synmaxcol') && &synmaxcol > g:bigfile_size_synmaxcol + execute 'setlocal synmaxcol=' . g:bigfile_size_synmaxcol endif endfunction -- cgit v1.2.3 From 7055ff62f078dad446c4192ab3d98f16ed82caeb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:26:38 +1300 Subject: Have bigfileturn local syntax off (configurably) --- vim/plugin/bigfile.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim index c5dee62a..fece3d9b 100644 --- a/vim/plugin/bigfile.vim +++ b/vim/plugin/bigfile.vim @@ -13,6 +13,11 @@ if has('eval') && has('autocmd') let g:bigfile_size = 10 * 1024 * 1024 endif + " Default to leaving syntax highlighting off + if !exists('g:bigfile_syntax') + let g:bigfile_syntax = 0 + endif + " Cut 'synmaxcol' down to this or smaller for big files if !exists('g:bigfile_size_synmaxcol') let g:bigfile_size_synmaxcol = 256 @@ -39,6 +44,11 @@ if has('eval') && has('autocmd') execute 'setlocal synmaxcol=' . g:bigfile_size_synmaxcol endif + " Disable syntax highlighting if configured to do so + if !g:bigfile_syntax + setlocal syntax=OFF + endif + endfunction " Define autocmd for calling to check filesize -- cgit v1.2.3 From bb83d050fe12ca8da269384902bc828667fea674 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:31:46 +1300 Subject: Bump version number to 0.4.0 --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 3b8694f2..b787a6dd 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.3.2 -Wed Nov 1 13:11:51 NZDT 2017 +tejr dotfiles v0.4.0 +Thu Nov 2 14:31:35 NZDT 2017 -- cgit v1.2.3 From 30351424045da6e0a440acba8a7d110a1037e918 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:32:53 +1300 Subject: Add vim/plugin to lint-vim arguments This ensures that new plugin code gets tested before being released. We don't add the new vim/doc directory, as it's plain text rather than VimL. --- lint/vim.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/lint/vim.sh b/lint/vim.sh index d876d770..c370e177 100644 --- a/lint/vim.sh +++ b/lint/vim.sh @@ -5,6 +5,7 @@ set -- \ vim/ftplugin \ vim/gvimrc \ vim/indent \ + vim/plugin \ vim/vimrc vint -s -- "$@" || exit printf 'Vim configuration linted successfully.\n' -- cgit v1.2.3