From 10248b6cebe76833d9f92f14417e855aaab90ae5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 2 Nov 2017 14:39:13 +1300 Subject: Remove an idea that has now been implemented This was implemented and released in v0.4.0 as vim/plugin/bigfile.vim and vim/doc/bigfile.txt. --- IDEAS.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/IDEAS.md b/IDEAS.md index 6bb4af82..37857163 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -19,8 +19,6 @@ Ideas * I can probably get rid of all that nasty templated shell by writing something that wraps around td(1df) and generates shell script to run, and calls that via `eval`. -* The BigFileMeasures() function in .vim/config/bigfile.vim should maybe be a - self-contained plugin rather than a config subfile. * Ideally, the .awk and/or .sed scripts in the bin and games dirs should be syntax-checked or linted. I could at least add some patient application of appropriate `gawk --lint` calls for each of the .awk scripts. -- cgit v1.2.3 From 8ffc267a1f97278bd98b5028e2dc7463aca2a61a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 00:00:17 +1300 Subject: Move misplaced command.vim file Looks like this was added in a1ee04d for v0.4.0 and was intended to replace the file in its correct path at vim/config/comment.vim. --- vim/command.vim | 39 --------------------------------------- vim/config/command.vim | 4 +++- 2 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 vim/command.vim diff --git a/vim/command.vim b/vim/command.vim deleted file mode 100644 index af7c8e36..00000000 --- a/vim/command.vim +++ /dev/null @@ -1,39 +0,0 @@ -" 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 diff --git a/vim/config/command.vim b/vim/config/command.vim index 1d2b647a..2a60bab3 100644 --- a/vim/config/command.vim +++ b/vim/config/command.vim @@ -22,7 +22,9 @@ set shellpipe=> " Always use forward slashes, I very seldom need to use Vim on Windows for " more than scratch space anyway -set shellslash +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 -- cgit v1.2.3 From cd8e9cc27f7dd9d360b64f4a34b8c2d048f42e45 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 13:46:30 +1300 Subject: Apply simpler method for sd2u(1df) and su2d(1df) This method is shorter, easier to read, and more idiomatic. --- bin/sd2u.awk | 6 +++--- bin/su2d.awk | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/sd2u.awk b/bin/sd2u.awk index 02584952..b6e3da89 100644 --- a/bin/sd2u.awk +++ b/bin/sd2u.awk @@ -1,3 +1,3 @@ -# Convert DOS line endings to UNIX ones -{ sub(/\r$/, "") } -{ print } +# Convert stream DOS line endings to UNIX ones +BEGIN { RS = "\r\n" } +1 diff --git a/bin/su2d.awk b/bin/su2d.awk index 34a8c5ae..5a8eabaf 100644 --- a/bin/su2d.awk +++ b/bin/su2d.awk @@ -1,3 +1,3 @@ -# Convert UNIX line endings to DOS ones -!/\r$/ { $0 = $0 "\r" } -{ print } +# Convert stream UNIX line endings to DOS ones +BEGIN { ORS = "\r\n" } +1 -- cgit v1.2.3 From 29059804f7708413843687c1764bc845d374a82d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 13:58:23 +1300 Subject: Remove idempotency assert for sd2u(1df)/su2d(1df) Commit cd8e9cc applies a cleaner implementation of these tools but loses the idempotency: * Repeated su2d applications will result in double \r, so \r\r\n * Repeated s2ru applications will result in an extra newline at the end of the file, because the whole file will be interpreted as one line However, I am OK with this, as I think of the operation as simpler and more predictable, and I wouldn't apply it as a means to "force" a file of unknown or various line-ending types to one type. --- man/man1/sd2u.1df | 2 +- man/man1/su2d.1df | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/man/man1/sd2u.1df b/man/man1/sd2u.1df index f07ebdb9..ee00c473 100644 --- a/man/man1/sd2u.1df +++ b/man/man1/sd2u.1df @@ -13,7 +13,7 @@ program | .B sd2u .SH DESCRIPTION Applies awk(1) to change DOS \\r\\n (CRLF) line endings to UNIX \\n line -endings. Lines already in UNIX format should be unchanged. +endings. .SH SEE ALSO awk(1), su2d(1df), d2u(1df), u2d(1df) .SH AUTHOR diff --git a/man/man1/su2d.1df b/man/man1/su2d.1df index aa6a8821..22aa80bd 100644 --- a/man/man1/su2d.1df +++ b/man/man1/su2d.1df @@ -13,7 +13,7 @@ program | .B su2d .SH DESCRIPTION Applies awk(1) to change UNIX \\n line endings to DOS \\r\\n (CRLF) line -endings. Lines already in DOS format should be unchanged. +endings. .SH SEE ALSO awk(1), sd2u(1df), d2u(1df), u2d(1df) .SH AUTHOR -- cgit v1.2.3 From 0b3aa702497fe3fa690a31998f3c7aedb96e5c73 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 14:05:59 +1300 Subject: Make d2u(1df)/u2d(1df) like their stream analogues Remove the idempotency guarantee, and simplify the ed(1) scripts. See commits 2905980 and cd8e9cc: >commit 29059804f7708413843687c1764bc845d374a82d >Author: Tom Ryder >Date: Fri Nov 3 13:58:23 2017 > > Remove idempotency assert for sd2u(1df)/su2d(1df) > > Commit cd8e9cc applies a cleaner implementation of these tools but > loses the idempotency: > > * Repeated su2d applications will result in double \r, so \r\r\n > * Repeated s2ru applications will result in an extra newline at the > end of the file, because the whole file will be interpreted as > one line > > However, I am OK with this, as I think of the operation as simpler > and more predictable, and I wouldn't apply it as a means to "force" > a file of unknown or various line-ending types to one type. > >commit cd8e9cc27f7dd9d360b64f4a34b8c2d048f42e45 >Author: Tom Ryder >Date: Fri Nov 3 13:46:30 2017 > > Apply simpler method for sd2u(1df) and su2d(1df) > > This method is shorter, easier to read, and more idiomatic. --- bin/d2u.sh | 2 +- bin/u2d.sh | 3 +-- man/man1/d2u.1df | 2 +- man/man1/u2d.1df | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/d2u.sh b/bin/d2u.sh index 22c8e16b..892c446b 100644 --- a/bin/d2u.sh +++ b/bin/d2u.sh @@ -16,7 +16,7 @@ for fn ; do # $r within it to get a literal carriage return; the escape characters # prescribed for ed(1) by POSIX are very limited ed -s -- "$fn" < Date: Fri, 3 Nov 2017 20:35:23 +1300 Subject: Use / correctly in Vim config From ":help ": > In a global plugin should be used and in a filetype plugin > . "mapleader" and "maplocalleader" can be equal. --- vim/config/format.vim | 6 +++--- vim/config/list.vim | 2 +- vim/config/number.vim | 2 +- vim/config/search.vim | 4 ++-- vim/config/spell.vim | 6 +++--- vim/config/whitespace.vim | 2 +- vim/config/wrap.vim | 4 ++-- vim/ftplugin/html.vim | 4 ++-- vim/ftplugin/perl.vim | 6 +++--- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/vim/config/format.vim b/vim/config/format.vim index 35245d0d..b0de7621 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -38,8 +38,8 @@ if has('eval') endfunction " Map leader-letters to corresponding format option flags - nnoremap a :call ToggleFormatFlag('a') - nnoremap c :call ToggleFormatFlag('c') - nnoremap t :call ToggleFormatFlag('t') + nnoremap a :call ToggleFormatFlag('a') + nnoremap c :call ToggleFormatFlag('c') + nnoremap t :call ToggleFormatFlag('t') endif diff --git a/vim/config/list.vim b/vim/config/list.vim index faf5e29a..209bb4ec 100644 --- a/vim/config/list.vim +++ b/vim/config/list.vim @@ -1,7 +1,7 @@ " Don't show whitespace characters or end-of-line characters visually by " default, but make \l toggle between them set nolist -nnoremap l :setlocal list! list? +nnoremap l :setlocal list! list? " Clearly show when the start or end of the row does not correspond to the " start and end of the line diff --git a/vim/config/number.vim b/vim/config/number.vim index 35ec7efe..d7d9919c 100644 --- a/vim/config/number.vim +++ b/vim/config/number.vim @@ -1,3 +1,3 @@ " Don't show line numbers by default, but \n toggles them set nonumber -nnoremap n :setlocal number! number? +nnoremap n :setlocal number! number? diff --git a/vim/config/search.vim b/vim/config/search.vim index 66b81ab0..0f10eea5 100644 --- a/vim/config/search.vim +++ b/vim/config/search.vim @@ -3,11 +3,11 @@ if has('extra_search') " Searching as I enter my pattern, \i toggles this set incsearch - nnoremap i :setlocal incsearch! incsearch? + nnoremap i :setlocal incsearch! incsearch? " Highlight search results, \h toggles this set hlsearch - nnoremap h :setlocal hlsearch! hlsearch? + nnoremap h :setlocal hlsearch! hlsearch? " Pressing ^L will clear highlighting until the next search-related " operation; quite good because the highlighting gets distracting after diff --git a/vim/config/spell.vim b/vim/config/spell.vim index 046b50ff..6a0167d0 100644 --- a/vim/config/spell.vim +++ b/vim/config/spell.vim @@ -3,12 +3,12 @@ if has('spell') " Don't check spelling by default, but bind \s to toggle this set nospell - nnoremap s :setlocal spell! spell? + nnoremap s :setlocal spell! spell? " Use New Zealand English for spelling by default (it's almost identical " to British English), but bind \u to switch to US English and \z to " switch back set spelllang=en_nz - nnoremap u :setlocal spelllang=en_us spelllang? - nnoremap z :setlocal spelllang=en_nz spelllang? + nnoremap u :setlocal spelllang=en_us spelllang? + nnoremap z :setlocal spelllang=en_nz spelllang? endif diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim index cc2554bd..bfe2663d 100644 --- a/vim/config/whitespace.vim +++ b/vim/config/whitespace.vim @@ -52,6 +52,6 @@ if has('eval') endfunction " Map \x to the function just defined - nnoremap x :call StripTrailingWhitespace() + nnoremap x :call StripTrailingWhitespace() endif diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim index 0e5866d8..7a442e89 100644 --- a/vim/config/wrap.vim +++ b/vim/config/wrap.vim @@ -1,6 +1,6 @@ " Don't wrap by default, but use \w to toggle it on or off quickly set nowrap -nnoremap w :setlocal wrap! wrap? +nnoremap w :setlocal wrap! wrap? " When wrapping text, if a line is so long that not all of it can be shown on " the screen, show as much as possible anyway; by default Vim fills the left @@ -58,7 +58,7 @@ if has('linebreak') endfunction " Map \b to defined function - nnoremap b :call ToggleBreak() + nnoremap b :call ToggleBreak() endif endif diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 3f28e9ea..309b7132 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,5 +1,5 @@ " Run tidy -eq -utf8 on file for the current buffer -nnoremap v :exe "!tidy -eq -utf8 " . shellescape(expand("%")) +nnoremap v :exe "!tidy -eq -utf8 " . shellescape(expand("%")) " Make a bare URL into a link to itself function! s:UrlLink() @@ -8,4 +8,4 @@ function! s:UrlLink() normal! E execute "normal! a\" endfunction -nnoremap r :call UrlLink() +nnoremap r :call UrlLink() diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index dad2ce35..53341183 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,6 +1,6 @@ " Run perl -c on file for the current buffer -nnoremap pc :exe "!perl -c " . shellescape(expand("%")) +nnoremap pc :exe "!perl -c " . shellescape(expand("%")) " Run perlcritic on the file for the current buffer -nnoremap pl :exe "!perlcritic " . shellescape(expand("%")) +nnoremap pl :exe "!perlcritic " . shellescape(expand("%")) " Run the current buffer through perltidy -nnoremap pt :%!perltidy +nnoremap pt :%!perltidy -- cgit v1.2.3 From 854b2273e58f3e831297336dcaa2e2646461b5ce Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 20:43:38 +1300 Subject: Refactor HTML tidy(1) mapping Move the logic into a script function. Use single quotes for the strings, too, since we don't need interpolation. --- vim/ftplugin/html.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 309b7132..b305a223 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,5 +1,8 @@ " Run tidy -eq -utf8 on file for the current buffer -nnoremap v :exe "!tidy -eq -utf8 " . shellescape(expand("%")) +function s:HTMLTidy() + execute '!tidy -eq -utf8 ' . shellescape(expand('%')) +endfunction +nnoremap v :exe :call HTMLTidy() " Make a bare URL into a link to itself function! s:UrlLink() -- cgit v1.2.3 From 4a7b3b3cc29ed48a96535284446d921be414fb0b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 20:47:42 +1300 Subject: Use single quotes for HTML link mapping :execute Saves some backslashing, just like in shell and Perl! --- vim/ftplugin/html.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index b305a223..b4eb9e6b 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -7,8 +7,8 @@ nnoremap v :exe :call HTMLTidy() " Make a bare URL into a link to itself function! s:UrlLink() normal! yiW - execute "normal! i0\">\" + execute 'normal! i\" + execute 'normal! a\' endfunction nnoremap r :call UrlLink() -- cgit v1.2.3 From 810cb9d53c09ccb8d65a4e996f088b7af3b9a40b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 21:55:48 +1300 Subject: Refactor UrlLink() function normal! commands Tidy up the 'normal!' commands and comment them in appropriate groups. Take advantage of the natural command-termination at the end of a 'normal!' string to end insert mode. It would be better to do all of this with pure VimL functions, but I don't know how yet. --- vim/ftplugin/html.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index b4eb9e6b..7400326c 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -6,9 +6,17 @@ nnoremap v :exe :call HTMLTidy() " Make a bare URL into a link to itself function! s:UrlLink() + + " Yank this whole whitespace-separated word normal! yiW - execute 'normal! i + " Paste the URL into the quotes + normal! hP + " Move to the end of the link text URL normal! E - execute 'normal! a\' + " Close the link tag + normal! a + endfunction nnoremap r :call UrlLink() -- cgit v1.2.3 From ffb5cbc7c681e2fdcb780dbdc51cf3458a937791 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 22:20:09 +1300 Subject: Adjust UrlLink() to yank word without text objects --- vim/ftplugin/html.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 7400326c..64cf3175 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -8,7 +8,9 @@ nnoremap v :exe :call HTMLTidy() function! s:UrlLink() " Yank this whole whitespace-separated word - normal! yiW + normal! W + normal! B + normal! yE " Open a link tag normal! i " Paste the URL into the quotes -- cgit v1.2.3 From a6b6f843eea0d101bf533c1e0894a95e13dd1c75 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 22:22:56 +1300 Subject: Revert "Adjust UrlLink() to yank word without t... I thought text objects were introduced to Vim a lot later than they actually were; this works fine even in Vim 6, so I'll leave it as it's nicer. This reverts commit ffb5cbc7c681e2fdcb780dbdc51cf3458a937791. --- vim/ftplugin/html.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 64cf3175..7400326c 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -8,9 +8,7 @@ nnoremap v :exe :call HTMLTidy() function! s:UrlLink() " Yank this whole whitespace-separated word - normal! W - normal! B - normal! yE + normal! yiW " Open a link tag normal! i " Paste the URL into the quotes -- cgit v1.2.3 From 04031093dd873153b8af734fae5122bf27dcdb19 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 22:47:59 +1300 Subject: Check for availability of Vim shellescape() It doesn't seem to be in very old Vims; worth testing for to avoid errors if I try to use the function. --- vim/ftplugin/html.vim | 10 ++++++---- vim/ftplugin/perl.vim | 17 +++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 7400326c..5505dbaa 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,8 +1,10 @@ " Run tidy -eq -utf8 on file for the current buffer -function s:HTMLTidy() - execute '!tidy -eq -utf8 ' . shellescape(expand('%')) -endfunction -nnoremap v :exe :call HTMLTidy() +if exists('*shellescape') + function s:HTMLTidy() + execute '!tidy -eq -utf8 ' . shellescape(expand('%')) + endfunction + nnoremap v :exe :call HTMLTidy() +endif " Make a bare URL into a link to itself function! s:UrlLink() diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index 53341183..c4923051 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,6 +1,11 @@ -" Run perl -c on file for the current buffer -nnoremap pc :exe "!perl -c " . shellescape(expand("%")) -" Run perlcritic on the file for the current buffer -nnoremap pl :exe "!perlcritic " . shellescape(expand("%")) -" Run the current buffer through perltidy -nnoremap pt :%!perltidy +" External commands for Perl files +if exists('*shellescape') + + " Run perl -c on file for the current buffer + nnoremap pc :exe "!perl -c " . shellescape(expand("%")) + " Run perlcritic on the file for the current buffer + nnoremap pl :exe "!perlcritic " . shellescape(expand("%")) + " Run the current buffer through perltidy + nnoremap pt :%!perltidy + +endif -- cgit v1.2.3 From 381812518e1625ffa3d000332e5198b5ac219f73 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 22:52:46 +1300 Subject: Use full ':execute' not just ':exe' in VimL We should probably avoid this sort of abbreviation in scripts. --- vim/ftplugin/html.vim | 2 +- vim/ftplugin/perl.vim | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 5505dbaa..d705bd71 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -3,7 +3,7 @@ if exists('*shellescape') function s:HTMLTidy() execute '!tidy -eq -utf8 ' . shellescape(expand('%')) endfunction - nnoremap v :exe :call HTMLTidy() + nnoremap v :execute :call HTMLTidy() endif " Make a bare URL into a link to itself diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index c4923051..310ffe7e 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -2,9 +2,9 @@ if exists('*shellescape') " Run perl -c on file for the current buffer - nnoremap pc :exe "!perl -c " . shellescape(expand("%")) + nnoremap pc :execute "!perl -c " . shellescape(expand("%")) " Run perlcritic on the file for the current buffer - nnoremap pl :exe "!perlcritic " . shellescape(expand("%")) + nnoremap pl :execute "!perlcritic " . shellescape(expand("%")) " Run the current buffer through perltidy nnoremap pt :%!perltidy -- cgit v1.2.3 From e6bfb8f7065ded88ebc1af4dec865a715f33f03f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 22:55:39 +1300 Subject: Use direct :write !cmd instead of shellescape() This is a much better method of calling external programs on the buffer's contents, not just because it avoids the mess of :execute evaluation but also because it doesn't require that there actually be a filename for the current buffer. This drastically simplifies the HTML tidy(1) call in particular. --- vim/ftplugin/html.vim | 7 +------ vim/ftplugin/perl.vim | 17 ++++++----------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index d705bd71..4d3991f3 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,10 +1,5 @@ " Run tidy -eq -utf8 on file for the current buffer -if exists('*shellescape') - function s:HTMLTidy() - execute '!tidy -eq -utf8 ' . shellescape(expand('%')) - endfunction - nnoremap v :execute :call HTMLTidy() -endif +nnoremap v :write !tidy -eq -utf8 " Make a bare URL into a link to itself function! s:UrlLink() diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index 310ffe7e..eeed2bb7 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,11 +1,6 @@ -" External commands for Perl files -if exists('*shellescape') - - " Run perl -c on file for the current buffer - nnoremap pc :execute "!perl -c " . shellescape(expand("%")) - " Run perlcritic on the file for the current buffer - nnoremap pl :execute "!perlcritic " . shellescape(expand("%")) - " Run the current buffer through perltidy - nnoremap pt :%!perltidy - -endif +" Run perl -c on file for the current buffer +nnoremap pc :write !perl -c +" Run perlcritic on the file for the current buffer +nnoremap pl :write !perlcritic +" Run the current buffer through perltidy +nnoremap pt :%!perltidy -- cgit v1.2.3 From 95e5976068183cf0f5b1601b7b159dfc6fa2cab8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 23:54:52 +1300 Subject: Use long form options for tidy(1) Vim call --- vim/ftplugin/html.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 4d3991f3..3bd1dbdf 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,5 +1,5 @@ -" Run tidy -eq -utf8 on file for the current buffer -nnoremap v :write !tidy -eq -utf8 +" Run `tidy -errors -quiet` for the current buffer +nnoremap c :write !tidy -errors -quiet -utf8 " Make a bare URL into a link to itself function! s:UrlLink() -- cgit v1.2.3 From f1a27833c012d3c0550f2d97839663a5e5ec7171 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 23:58:29 +1300 Subject: Improve comments on check/lint/tidy maps --- vim/ftplugin/html.vim | 2 +- vim/ftplugin/perl.vim | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 3bd1dbdf..520e4fe2 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,4 +1,4 @@ -" Run `tidy -errors -quiet` for the current buffer +" Run `tidy -errors -quiet` over buffer nnoremap c :write !tidy -errors -quiet -utf8 " Make a bare URL into a link to itself diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index eeed2bb7..3355227e 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,6 +1,6 @@ -" Run perl -c on file for the current buffer +" Run `perl -c` over buffer nnoremap pc :write !perl -c -" Run perlcritic on the file for the current buffer +" Run `perlcritic` over buffer nnoremap pl :write !perlcritic -" Run the current buffer through perltidy +" Filter buffer through `perltidy` nnoremap pt :%!perltidy -- cgit v1.2.3 From 703c63113d6e089136259ab077422b51f636309a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 00:31:04 +1300 Subject: Make all lint/check/tidy maps local and silent That is, apply and to each of them, to make them only apply to the current buffer and to prevent them from echoing the command they're running. --- vim/ftplugin/html.vim | 4 ++-- vim/ftplugin/perl.vim | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 520e4fe2..f16bc8cf 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,5 +1,5 @@ " Run `tidy -errors -quiet` over buffer -nnoremap c :write !tidy -errors -quiet -utf8 +nnoremap c :write !tidy -errors -quiet " Make a bare URL into a link to itself function! s:UrlLink() @@ -16,4 +16,4 @@ function! s:UrlLink() normal! a endfunction -nnoremap r :call UrlLink() +nnoremap r :call UrlLink() diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index 3355227e..38c3308b 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,6 +1,6 @@ " Run `perl -c` over buffer -nnoremap pc :write !perl -c +nnoremap c :write !perl -c " Run `perlcritic` over buffer -nnoremap pl :write !perlcritic +nnoremap l :write !perlcritic " Filter buffer through `perltidy` -nnoremap pt :%!perltidy +nnoremap t :%!perltidy -- cgit v1.2.3 From ccabcefafef457e7d488ef2ee1b27b4b56e03267 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 00:32:04 +1300 Subject: Break long lines in check/lint/tidy mappings --- vim/ftplugin/html.vim | 6 ++++-- vim/ftplugin/perl.vim | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index f16bc8cf..a56ae778 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,5 +1,6 @@ " Run `tidy -errors -quiet` over buffer -nnoremap c :write !tidy -errors -quiet +nnoremap c + \ :write !tidy -errors -quiet " Make a bare URL into a link to itself function! s:UrlLink() @@ -16,4 +17,5 @@ function! s:UrlLink() normal! a endfunction -nnoremap r :call UrlLink() +nnoremap r + \ :call UrlLink() diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index 38c3308b..2ea4676b 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,6 +1,11 @@ " Run `perl -c` over buffer -nnoremap c :write !perl -c +nnoremap c + \ :write !perl -c + " Run `perlcritic` over buffer -nnoremap l :write !perlcritic +nnoremap l + \ :write !perlcritic + " Filter buffer through `perltidy` -nnoremap t :%!perltidy +nnoremap t + \ :%!perltidy -- cgit v1.2.3 From 374ceec9af29401a183b3be44f5dc75e096abae9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 00:32:44 +1300 Subject: Add tidy mapping for HTML This mapping mirrors the one for Perl that passes the content of the buffer through a program to tidy it (i.e. not merely check but actively change it). The tidy(1) option chosen here, -quiet, is the bare minimum to make this invocation useful. We would never want the boilerplate it otherwise emits to be in the buffer after a call. Everything else should be applied in a configuration file, which I'll do in a separate feature. --- vim/ftplugin/html.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index a56ae778..c756eb80 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -2,6 +2,10 @@ nnoremap c \ :write !tidy -errors -quiet +" Filter buffer through `tidy` +nnoremap t + \ :%!tidy -quiet + " Make a bare URL into a link to itself function! s:UrlLink() -- cgit v1.2.3 From ad80283eec33af208d6bf24834809e351f54f90f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 00:32:58 +1300 Subject: Add check and lint mappings for shell script The commands to use in this case are dependent on the particular shell being used. --- vim/ftplugin/sh.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index a6dd62eb..c09e4fe8 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -24,3 +24,25 @@ endif if exists('b:is_bash') && executable('han') setlocal keywordprg=han endif + +" Map checker based on shell family +if exists('b:is_bash') && b:is_bash + let b:check = 'bash -n' +elseif exists('b:is_ksh') && b:is_ksh + let b:check = 'ksh -n' +else + let b:check = 'sh -n' +endif +nnoremap c + \ :execute ':write !' . b:check + +" Map linter based on shell family +if exists('b:is_bash') && b:is_bash + let b:lint = 'shellcheck -s bash -' +elseif exists('b:is_ksh') && b:is_ksh + let b:lint = 'shellcheck -s ksh -' +else + let b:lint = 'shellcheck -s sh -' +endif +nnoremap l + \ :execute ':write !' . b:lint -- cgit v1.2.3 From acec3d790704ab65a0c4229f4355e99fafcbdde5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 00:45:41 +1300 Subject: Use underscore as local map leader This should allow me to mentally separate actions specific to a buffer type from actions that apply to buffers in general. It also removes the overlap of l for 'list' toggling and filetype linting. From ":help maplocalleader": > is just like , except that it uses > "maplocalleader" instead of "mapleader". is to be used > for mappings which are local to a buffer. Example: > > :map A oanother line > > In a global plugin should be used and in a filetype plugin > . "mapleader" and "maplocalleader" can be equal. > Although, if you make them different, there is a smaller chance of > mappings from global plugins to clash with mappings for filetype > plugins. For example, you could keep "mapleader" at the default > backslash, and set "maplocalleader" to an underscore. --- vim/config/leader.vim | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 vim/config/leader.vim diff --git a/vim/config/leader.vim b/vim/config/leader.vim new file mode 100644 index 00000000..2d7b98ae --- /dev/null +++ b/vim/config/leader.vim @@ -0,0 +1,3 @@ +" Use different keys for global and local leaders +let mapleader = '\' +let maplocalleader = '_' -- cgit v1.2.3 From 55699ddf44405c16f5ad6fbad6022aaeb4373683 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 00:57:28 +1300 Subject: Specify scope of mapleader variables `vint -s` says: vim/config/leader.vim:2:5: Make the scope explicit like `g:mapleader` (see Anti-pattern of vimrc (Scope of identifier)) vim/config/leader.vim:3:5: Make the scope explicit like `g:maplocalleader` (see Anti-pattern of vimrc (Scope of identifier)) This does still seem to work with the prefixes, despite not being the way the documentation specifies the variables. --- vim/config/leader.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/config/leader.vim b/vim/config/leader.vim index 2d7b98ae..9ca8f762 100644 --- a/vim/config/leader.vim +++ b/vim/config/leader.vim @@ -1,3 +1,3 @@ " Use different keys for global and local leaders -let mapleader = '\' -let maplocalleader = '_' +let g:mapleader = '\' +let g:maplocalleader = '_' -- cgit v1.2.3 From 43165b683c25a198f73304cca8b76cb9f1fae2ce Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 00:59:23 +1300 Subject: Add lint mapping for Vimscript Runs `vint -s`; the -s includes stylistic suggestions. --- vim/ftplugin/vim.vim | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 vim/ftplugin/vim.vim diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim new file mode 100644 index 00000000..e023553e --- /dev/null +++ b/vim/ftplugin/vim.vim @@ -0,0 +1,5 @@ +" Run `vint` over buffer +" /dev/stdin is not optimal here; it's widely implemented, but not POSIX. +" `vint` does not seem to have another way to parse standard input. +nnoremap l + \ :write !vint -s /dev/stdin -- cgit v1.2.3 From 0f5fb5ec1b50a52e245ef0d1b46550091f222c31 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 01:02:06 +1300 Subject: Update documentation to reflect ftplugin changes --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 028a42fa..c3ffbf44 100644 --- a/README.md +++ b/README.md @@ -342,8 +342,12 @@ The configuration is broken into subfiles in `~/.vim/config/*.vim`, included by extensively commented, mostly because I was reading through it one day and realised I'd forgotten what half of it did. -Plugins are in submodules in `~/.vim/bundle`, loaded using Tim Pope's -[pathogen.vim](https://github.com/tpope/vim-pathogen). +I define a few custom per-filetype rules for stuff I often edit in +`~/.vim/ftplugin`, including some local mappings for checking, linting, and +tidying. + +Third-party plugins are in submodules in `~/.vim/bundle`, loaded using Tim +Pope's [pathogen.vim](https://github.com/tpope/vim-pathogen). Scripts ------- -- cgit v1.2.3 From b7cd2ec0a52c483fc56425bc9c9a65a9294f075d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 01:05:19 +1300 Subject: Bump version number to 0.5.0 --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index e02a52a4..e9f5dabc 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.4.2 -Fri Nov 3 07:10:09 UTC 2017 +tejr dotfiles v0.5.0 +Fri Nov 3 12:05:08 UTC 2017 -- cgit v1.2.3