From ac577df9f6516308c2f9661c8abbc44f6c19d854 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 11:57:21 +1300 Subject: Use sh.vim local vars not global POSIX hacks Rather than setting g:is_posix and working around core syntax/sh.vim's ideas about Korn and POSIX shells, forego sh.vim's efforts to guess what shell the system /bin/sh is entirely. It's irrelevant to me anyway, since I'll often be writing shell scripts to run on an entirely different system. Instead, if we have a #!/bin/sh shebang reflected in the b:is_sh variable set by core filetype.vim, and we don't have any other buffer-level indication of what shell this is, assume it's POSIX, because I very rarely write Bourne. Then, after the syntax file is loaded, clear away all but one of the resulting b:is_* variables. I have a feeling this is going to end with me re-implementing this syntax file, possibly as separate sh.vim, bash.vim, and ksh.vim files. --- vim/after/syntax/sh.vim | 16 +++++++++------- vim/ftplugin/sh.vim | 33 ++++++++++++++------------------- 2 files changed, 23 insertions(+), 26 deletions(-) (limited to 'vim') diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index d07f4cff..930255fc 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -1,10 +1,12 @@ -" If g:is_posix is set, g:is_kornshell is probably set too, a strange decision -" by sh.vim. No matter; we can tease out whether this is actually a Korn shell -" script using our own b:is_ksh flag set at the end of ~/.vim/ftdetect/sh.vim, -" and if it isn't, we'll throw away the highlighting groups for ksh. -if exists('g:is_kornshell') && !exists('b:is_ksh') - syntax clear kshSpecialVariables - syntax clear kshStatement +" If we know we have another shell type, clear away the others completely, now +" that core syntax/sh.vim is done prodding /bin/sh to determine the system +" shell type (which I don't care about). +if exists('b:is_bash') + unlet! b:is_sh b:is_posix b:is_kornshell +elseif exists('b:is_kornshell') + unlet! b:is_sh b:is_posix +elseif exists('b:is_posix') + unlet! b:is_sh endif " Some corrections for highlighting if we have any of POSIX, Bash, or Ksh diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 21d494e3..7f453e92 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -1,23 +1,18 @@ -" Default to POSIX shell, as I never write Bourne, and if I write Bash or Ksh -" it'll be denoted with either a shebang or an appropriate extension. -let g:is_posix = 1 - -" -" Setting g:is_posix above also prompts Vim's core syntax/sh.vim script to -" set g:is_kornshell and thereby b:is_kornshell to the same value as g:is_posix. -" -" That's very confusing, so before it happens we'll copy b:is_kornshell's -" value as determined by filetype.vim and ~/.vim/ftdetect/sh.vim into a custom -" variable b:is_ksh, before its meaning gets confused. " -" b:is_ksh as a name is more inline with b:is_bash and b:is_sh, anyway, so -" we'll just treat b:is_kornshell like it's both misnamed and broken. +" If we have a #!/bin/sh shebang and filetype.vim determined we were neither +" POSIX nor Bash nor Korn shell, we'll guess POSIX, just because it's far more +" likely that's what I want to write than plain Bourne shell. " -" We can then switch on our custom variable in ~/.vim/after/syntax/sh.vim to -" apply settings that actually *are* unique to Korn shell and its derivatives. +" You're supposed to be able to do this by setting g:is_posix, but if that's +" set, the syntax file ends up setting g:is_kornshell for you too, for reasons +" I don't really understand. This method works though, and is cleaner than +" the other workaround I had been trying. " -if exists('b:is_kornshell') - let b:is_ksh = b:is_kornshell +if exists('b:is_sh') + unlet b:is_sh + if !exists('b:is_bash') && !exists('b:is_kornshell') + let b:is_posix = 1 + endif endif " Use han(1df) as a man(1) wrapper for Bash files if available @@ -30,7 +25,7 @@ endif " Map checker based on shell family if exists('b:is_bash') && b:is_bash let b:check = 'write !bash -n' -elseif exists('b:is_ksh') && b:is_ksh +elseif exists('b:is_kornshell') && b:is_kornshell let b:check = 'write !ksh -n' else let b:check = 'write !sh -n' @@ -42,7 +37,7 @@ nnoremap " Map linter based on shell family if exists('b:is_bash') && b:is_bash let b:lint = 'write !shellcheck -s bash -' -elseif exists('b:is_ksh') && b:is_ksh +elseif exists('b:is_kornshell') && b:is_kornshell let b:lint = 'write !shellcheck -s ksh -' else let b:lint = 'write !shellcheck -s sh -' -- cgit v1.2.3 From 951d19084a9f9a8f82225397b7c41603c6f4860d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:34:22 +1300 Subject: Remove superfluous augroups around ftdetect defs From :help ftdetect, item 2: > 2. Create a file that contains an autocommand to detect the file type. > Example: > au BufRead,BufNewFile *.mine set filetype=mine > Note that there is no "augroup" command, this has already been done > when sourcing your file. --- vim/ftdetect/csv.vim | 9 +++------ vim/ftdetect/muttrc.vim | 9 +++------ vim/ftdetect/sh.vim | 34 +++++++++++++++------------------- vim/ftdetect/tsv.vim | 9 +++------ vim/ftdetect/xdefaults.vim | 9 +++------ 5 files changed, 27 insertions(+), 43 deletions(-) (limited to 'vim') diff --git a/vim/ftdetect/csv.vim b/vim/ftdetect/csv.vim index e5a38e10..a234c093 100644 --- a/vim/ftdetect/csv.vim +++ b/vim/ftdetect/csv.vim @@ -1,7 +1,4 @@ " Add automatic commands to detect CSV files -augroup dotfiles_ftdetect_csv - autocmd! - autocmd BufNewFile,BufRead - \ *.csv - \ setfiletype csv -augroup END +autocmd BufNewFile,BufRead + \ *.csv + \ setfiletype csv diff --git a/vim/ftdetect/muttrc.vim b/vim/ftdetect/muttrc.vim index 0f625f2b..55eeea93 100644 --- a/vim/ftdetect/muttrc.vim +++ b/vim/ftdetect/muttrc.vim @@ -1,7 +1,4 @@ " Add automatic commands to detect .muttrc files -augroup dotfiles_ftdetect_muttrc - autocmd! - autocmd BufNewFile,BufRead - \ **/.dotfiles/mutt/muttrc.d/*.rc,**/.muttrc.d/*.rc - \ setfiletype muttrc -augroup END +autocmd BufNewFile,BufRead + \ **/.dotfiles/mutt/muttrc.d/*.rc,**/.muttrc.d/*.rc + \ setfiletype muttrc diff --git a/vim/ftdetect/sh.vim b/vim/ftdetect/sh.vim index f00a5659..880f08e9 100644 --- a/vim/ftdetect/sh.vim +++ b/vim/ftdetect/sh.vim @@ -1,23 +1,19 @@ " Add automatic commands to choose shell flavours based on filename pattern -augroup dotfiles_ftdetect_sh - autocmd! - " Names/paths of things that are Bash shell script - autocmd BufNewFile,BufRead - \ **/.dotfiles/bash/**,bash-fc-* - \ let b:is_bash = 1 - \ | setfiletype sh +" Names/paths of things that are Bash shell script +autocmd BufNewFile,BufRead + \ **/.dotfiles/bash/**,bash-fc-* + \ let b:is_bash = 1 + \ | setfiletype sh - " Names/paths of things that are Korn shell script - autocmd BufNewFile,BufRead - \ **/.dotfiles/ksh/**,.kshrc,*.ksh - \ let b:is_kornshell = 1 - \ | setfiletype sh +" Names/paths of things that are Korn shell script +autocmd BufNewFile,BufRead + \ **/.dotfiles/ksh/**,.kshrc,*.ksh + \ let b:is_kornshell = 1 + \ | setfiletype sh - " Names/paths of things that are POSIX shell script - autocmd BufNewFile,BufRead - \ **/.dotfiles/sh/**,.shinit,.shrc,.xinitrc,/etc/default/* - \ let b:is_posix = 1 - \ | setfiletype sh - -augroup END +" Names/paths of things that are POSIX shell script +autocmd BufNewFile,BufRead + \ **/.dotfiles/sh/**,.shinit,.shrc,.xinitrc,/etc/default/* + \ let b:is_posix = 1 + \ | setfiletype sh diff --git a/vim/ftdetect/tsv.vim b/vim/ftdetect/tsv.vim index 673721f5..a345ac65 100644 --- a/vim/ftdetect/tsv.vim +++ b/vim/ftdetect/tsv.vim @@ -1,7 +1,4 @@ " Add automatic commands to detect TSV files -augroup dotfiles_ftdetect_tsv - autocmd! - autocmd BufNewFile,BufRead - \ *.tsv - \ setfiletype tsv -augroup END +autocmd BufNewFile,BufRead + \ *.tsv + \ setfiletype tsv diff --git a/vim/ftdetect/xdefaults.vim b/vim/ftdetect/xdefaults.vim index 1529e5c9..f45a22a7 100644 --- a/vim/ftdetect/xdefaults.vim +++ b/vim/ftdetect/xdefaults.vim @@ -1,7 +1,4 @@ " Add automatic commands to find Xresources subfiles -augroup dotfiles_ftdetect_xdefaults - autocmd! - autocmd BufNewFile,BufRead - \ **/.Xresources.d/* - \ setfiletype xdefaults -augroup END +autocmd BufNewFile,BufRead + \ **/.Xresources.d/* + \ setfiletype xdefaults -- cgit v1.2.3 From aa8690deaa873c384b9d3eafd2d39059ff0d753e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:38:02 +1300 Subject: Use correct undo variable name in ftplugin/sh.vim This was likely a copy-paste error. --- vim/ftplugin/sh.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vim') diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 7f453e92..50add09b 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -18,7 +18,7 @@ endif " Use han(1df) as a man(1) wrapper for Bash files if available if exists('b:is_bash') && executable('han') setlocal keywordprg=han - let b:undo_user_indent + let b:undo_user_ftplugin \ = 'setlocal keywordprg<' endif -- cgit v1.2.3 From 58dd8c7f1399a33967a839711a91286da1d7966b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:39:21 +1300 Subject: Move ftplugin/sh.vim b:undo def to end of file --- vim/ftplugin/sh.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'vim') diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 50add09b..f2592e6e 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -18,8 +18,6 @@ endif " Use han(1df) as a man(1) wrapper for Bash files if available if exists('b:is_bash') && executable('han') setlocal keywordprg=han - let b:undo_user_ftplugin - \ = 'setlocal keywordprg<' endif " Map checker based on shell family @@ -45,3 +43,7 @@ endif nnoremap \ l \ :execute b:lint + +" Clear away these extra changes +let b:undo_user_ftplugin + \ = 'setlocal keywordprg<' -- cgit v1.2.3 From ba1c36ee30af10c9199a90114ca97264803cf794 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:40:28 +1300 Subject: Clear b:check/lint in ftdetect/sh.vim b:undo --- vim/ftplugin/sh.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vim') diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index f2592e6e..5faf9055 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -46,4 +46,4 @@ nnoremap " Clear away these extra changes let b:undo_user_ftplugin - \ = 'setlocal keywordprg<' + \ = 'setlocal keywordprg< | unlet! b:check b:lint' -- cgit v1.2.3 From fc26455e79be92b13a7f7765b29949e5c601e3a8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:48:00 +1300 Subject: Remove overkill defined-and-false check of sh vars syntax/sh.vim only uses the existence of these variables for its checks and as far as I can see never their actual values, so let's not overdo things. --- vim/ftplugin/sh.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'vim') diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 5faf9055..29dc7c11 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -21,9 +21,9 @@ if exists('b:is_bash') && executable('han') endif " Map checker based on shell family -if exists('b:is_bash') && b:is_bash +if exists('b:is_bash') let b:check = 'write !bash -n' -elseif exists('b:is_kornshell') && b:is_kornshell +elseif exists('b:is_kornshell') let b:check = 'write !ksh -n' else let b:check = 'write !sh -n' @@ -33,9 +33,9 @@ nnoremap \ :execute b:check " Map linter based on shell family -if exists('b:is_bash') && b:is_bash +if exists('b:is_bash') let b:lint = 'write !shellcheck -s bash -' -elseif exists('b:is_kornshell') && b:is_kornshell +elseif exists('b:is_kornshell') let b:lint = 'write !shellcheck -s ksh -' else let b:lint = 'write !shellcheck -s sh -' -- cgit v1.2.3 From 587844257afebc8d879136fb449a867984c0a550 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:49:12 +1300 Subject: Rename b:check and b:lint with sh_ prefix Just to reduce the chance of colliding with existing buffer variable names. --- vim/ftplugin/sh.vim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'vim') diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 29dc7c11..35bfefc9 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -22,28 +22,28 @@ endif " Map checker based on shell family if exists('b:is_bash') - let b:check = 'write !bash -n' + let b:sh_check = 'write !bash -n' elseif exists('b:is_kornshell') - let b:check = 'write !ksh -n' + let b:sh_check = 'write !ksh -n' else - let b:check = 'write !sh -n' + let b:sh_check = 'write !sh -n' endif nnoremap \ c - \ :execute b:check + \ :execute b:sh_check " Map linter based on shell family if exists('b:is_bash') - let b:lint = 'write !shellcheck -s bash -' + let b:sh_lint = 'write !shellcheck -s bash -' elseif exists('b:is_kornshell') - let b:lint = 'write !shellcheck -s ksh -' + let b:sh_lint = 'write !shellcheck -s ksh -' else - let b:lint = 'write !shellcheck -s sh -' + let b:sh_lint = 'write !shellcheck -s sh -' endif nnoremap \ l - \ :execute b:lint + \ :execute b:sh_lint " Clear away these extra changes let b:undo_user_ftplugin - \ = 'setlocal keywordprg< | unlet! b:check b:lint' + \ = 'setlocal keywordprg< | unlet! b:sh_check b:sh_lint' -- cgit v1.2.3 From 129d77372dc3ea6c4a981a97620c10ca0ad90d29 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:49:35 +1300 Subject: Break a long conditional in vim/ftdetect/sh.vim Just for legibility. --- vim/ftplugin/sh.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'vim') diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 35bfefc9..179ea56e 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -16,7 +16,8 @@ if exists('b:is_sh') endif " Use han(1df) as a man(1) wrapper for Bash files if available -if exists('b:is_bash') && executable('han') +if exists('b:is_bash') + \ && executable('han') setlocal keywordprg=han endif -- cgit v1.2.3 From 388081f881656dece4388ba448713b9f2f062905 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:51:30 +1300 Subject: Disable unwanted shell error syntax for any shell --- vim/after/syntax/sh.vim | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'vim') diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index 930255fc..48a3452d 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -9,19 +9,14 @@ elseif exists('b:is_posix') unlet! b:is_sh endif -" Some corrections for highlighting if we have any of POSIX, Bash, or Ksh -if exists('g:is_posix') || exists('b:is_bash') || exists('b:is_ksh') +" The syntax highlighter seems to flag '/baz' in '"${foo:-"$bar"/baz}"' as an +" error, which it isn't, at least in POSIX sh, Bash, and Ksh. +syntax clear shDerefWordError - " The syntax highlighter seems to flag '/baz' in '"${foo:-"$bar"/baz}"' as an - " error, and I'm pretty sure it's not, at least in POSIX sh, Bash, and Ksh. - syntax clear shDerefWordError - - " The syntax highlighter doesn't match parens for subshells for 'if' tests - " correctly if they're on separate lines. This happens enough that it's - " probably not worth keeping the error. - syntax clear shParenError - -endif +" The syntax highlighter doesn't match parens for subshells for 'if' tests +" correctly if they're on separate lines. This happens enough that it's +" probably not worth keeping the error. +syntax clear shParenError " Some corrections for highlighting specific to the Bash mode if exists('b:is_bash') -- cgit v1.2.3 From 2ba00c6c583cef8f3dcf06a8aa9bec8754b81498 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 12:53:22 +1300 Subject: Override commands and variables for syntax/sh.vim The defaults for these groups don't make much sense to me, so I completely reset them. This isn't quite complete yet; for some reason as soon as e.g. an IFS= setting is contained in e.g. an "if" or "while" block, they don't highlight correctly anymore. There's probably some other part of the core syntax/sh.vim file I need to include here. --- vim/after/syntax/sh.vim | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'vim') diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index 48a3452d..9692ea9f 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -18,6 +18,82 @@ syntax clear shDerefWordError " probably not worth keeping the error. syntax clear shParenError +" Highlighting corrections specific to POSIX mode +if exists('b:is_posix') + + " Highlight some commands that are both defined by POSIX and builtin + " commands in dash, as a rough but useable proxy for 'shell builtins'. This + " list was wrested from `man 1 dash`. + syntax clear shStatement + syntax keyword shStatement + \ alias + \ bg + \ cd + \ command + \ echo + \ eval + \ exec + \ exit + \ export + \ fc + \ fg + \ getopts + \ hash + \ printf + \ pwd + \ read + \ readonly + \ set + \ shift + \ test + \ times + \ trap + \ true + \ type + \ ulimit + \ umask + \ unalias + \ unset + \ wait + + " Core syntax/sh.vim puts IFS and other variables that affect shell function + " in another color, but a subset of them actually apply to POSIX shell too + " (and plain Bourne). These are selected by searching the POSIX manpages. I + " added NLSPATH too, which wasn't in the original. + syntax clear shShellVariables + syntax keyword shShellVariables + \ CDPATH + \ ENV + \ FCEDIT + \ HISTFILE + \ HISTSIZE + \ HISTTIMEFORMAT + \ HOME + \ IFS + \ LANG + \ LC_ALL + \ LC_COLLATE + \ LC_CTYPE + \ LC_MESSAGES + \ LC_NUMERIC + \ LINENO + \ MAIL + \ MAILCHECK + \ MAILPATH + \ NLSPATH + \ OLDPWD + \ OPTARG + \ OPTERR + \ OPTIND + \ PATH + \ PS1 + \ PS2 + \ PS3 + \ PS4 + \ PWD + +endif + " Some corrections for highlighting specific to the Bash mode if exists('b:is_bash') -- cgit v1.2.3 From 6b502d0bd300d9df1150a1e8f6c9c974d3d75b5b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 13:07:14 +1300 Subject: Add `break`, `continue`, `return` as shStatement --- vim/after/syntax/sh.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'vim') diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index 9692ea9f..99c0cc3a 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -23,13 +23,16 @@ if exists('b:is_posix') " Highlight some commands that are both defined by POSIX and builtin " commands in dash, as a rough but useable proxy for 'shell builtins'. This - " list was wrested from `man 1 dash`. + " list was mostly wrested from `man 1 dash`. Also include control structure + " keywords like `break`, `continue`, and `return`. syntax clear shStatement syntax keyword shStatement \ alias \ bg + \ break \ cd \ command + \ continue \ echo \ eval \ exec @@ -43,6 +46,7 @@ if exists('b:is_posix') \ pwd \ read \ readonly + \ return \ set \ shift \ test -- cgit v1.2.3 From df15841b3034ccb6e6c670ad474ffe94945e81cd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 13:07:44 +1300 Subject: Add `kill` as shStatement It's not a shell builtin in `dash`, but it is in `Bash`, and I kind of think of it that way. --- vim/after/syntax/sh.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'vim') diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index 99c0cc3a..41ec27b4 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -42,6 +42,7 @@ if exists('b:is_posix') \ fg \ getopts \ hash + \ kill \ printf \ pwd \ read -- cgit v1.2.3 From 98e19b3fb954c63b77c9b6fe8f38c0a2c7c5627f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 13:08:10 +1300 Subject: Add clustering for POSIX shell syntax groups This is what was missing after I initially redefined these groups and stopped all POSIX shell scripts thinking they were POSIX. The words now highlight correctly when within control structures again. --- vim/after/syntax/sh.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'vim') diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index 41ec27b4..ba209e99 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -26,6 +26,8 @@ if exists('b:is_posix') " list was mostly wrested from `man 1 dash`. Also include control structure " keywords like `break`, `continue`, and `return`. syntax clear shStatement + syntax cluster shCommandSubList add=shStatement + syntax cluster shCaseList add=shStatement syntax keyword shStatement \ alias \ bg @@ -66,6 +68,7 @@ if exists('b:is_posix') " (and plain Bourne). These are selected by searching the POSIX manpages. I " added NLSPATH too, which wasn't in the original. syntax clear shShellVariables + syntax cluster shCommandSubList add=shShellVariables syntax keyword shShellVariables \ CDPATH \ ENV -- cgit v1.2.3 From 02a368550446f9d2ee959905e0d633dc0f4edc98 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 13:39:30 +1300 Subject: Use consistent/thorough ftplugin/indent unloading Unload all maps too, with silent! in case they don't exist. --- vim/ftplugin/html.vim | 6 ++++++ vim/ftplugin/mail.vim | 2 ++ vim/ftplugin/markdown.vim | 6 ++++-- vim/ftplugin/perl.vim | 6 ++++++ vim/ftplugin/sh.vim | 9 ++++++--- vim/ftplugin/text.vim | 6 ++++-- vim/ftplugin/vim.vim | 4 ++++ vim/indent/csv.vim | 2 ++ vim/indent/tsv.vim | 2 ++ vim/indent/vim.vim | 10 ++++------ 10 files changed, 40 insertions(+), 13 deletions(-) (limited to 'vim') diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 3db5dcca..27b38424 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -28,3 +28,9 @@ endfunction nnoremap \ r \ :call UrlLink() + +" Unload this filetype plugin +let b:undo_user_ftplugin = '' + \ . '|silent! nunmap c' + \ . '|silent! nunmap t' + \ . '|silent! nunmap r' diff --git a/vim/ftplugin/mail.vim b/vim/ftplugin/mail.vim index d4840bfd..697ce499 100644 --- a/vim/ftplugin/mail.vim +++ b/vim/ftplugin/mail.vim @@ -1,4 +1,6 @@ " Use trailing whitespace to denote continued paragraph setlocal formatoptions+=w + +" Unload this filetype plugin let b:undo_user_ftplugin \ = 'setlocal formatoptions<' diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim index ab27c2f7..f26fb156 100644 --- a/vim/ftplugin/markdown.vim +++ b/vim/ftplugin/markdown.vim @@ -1,6 +1,8 @@ " Spellcheck documents by default if has('syntax') setlocal spell - let b:undo_user_ftplugin - \ = 'setlocal spell<' endif + +" Unload this filetype plugin +let b:undo_user_ftplugin + \ = 'silent! setlocal spell<' diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index 07cf9a1f..7f6eb7fe 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -12,3 +12,9 @@ nnoremap nnoremap \ t \ :%!perltidy + +" Unload this filetype plugin +let l:undo_user_ftplugin = '' + \ . '|silent! unmap c' + \ . '|silent! unmap l' + \ . '|silent! unmap t' diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 179ea56e..a8c94445 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -45,6 +45,9 @@ nnoremap \ l \ :execute b:sh_lint -" Clear away these extra changes -let b:undo_user_ftplugin - \ = 'setlocal keywordprg< | unlet! b:sh_check b:sh_lint' +" Unload this filetype plugin +let b:undo_user_ftplugin = '' + \ . '|setlocal keywordprg<' + \ . '|unlet! b:sh_check b:sh_lint' + \ . '|silent! unmap c' + \ . '|silent! unmap l' diff --git a/vim/ftplugin/text.vim b/vim/ftplugin/text.vim index ab27c2f7..f26fb156 100644 --- a/vim/ftplugin/text.vim +++ b/vim/ftplugin/text.vim @@ -1,6 +1,8 @@ " Spellcheck documents by default if has('syntax') setlocal spell - let b:undo_user_ftplugin - \ = 'setlocal spell<' endif + +" Unload this filetype plugin +let b:undo_user_ftplugin + \ = 'silent! setlocal spell<' diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim index d4e55ace..e8113134 100644 --- a/vim/ftplugin/vim.vim +++ b/vim/ftplugin/vim.vim @@ -4,3 +4,7 @@ nnoremap \ l \ :write !vint -s /dev/stdin + +" Unload this filetype plugin +let b:undo_user_ftplugin + \ = 'silent! nunmap l' diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim index 682bc3a8..ae2b6f6c 100644 --- a/vim/indent/csv.vim +++ b/vim/indent/csv.vim @@ -1,5 +1,7 @@ " Manual indenting and literal tabs for CSVs setlocal noautoindent setlocal noexpandtab + +" Unload this indent plugin let b:undo_user_indent \ = 'setlocal autoindent< expandtab<' diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim index 951b3e60..759602ed 100644 --- a/vim/indent/tsv.vim +++ b/vim/indent/tsv.vim @@ -1,5 +1,7 @@ " Manual indenting and literal tabs for TSVs setlocal noautoindent setlocal noexpandtab + +" Unload this indent plugin let b:undo_user_indent \ = 'setlocal autoindent< expandtab<' diff --git a/vim/indent/vim.vim b/vim/indent/vim.vim index 047a353d..138b9205 100644 --- a/vim/indent/vim.vim +++ b/vim/indent/vim.vim @@ -3,9 +3,7 @@ setlocal shiftwidth=2 setlocal softtabstop=2 setlocal tabstop=2 -" Ancient Vim can't use the '<' suffix syntax for resetting local integer -" options -if v:version > 700 - let b:undo_user_indent - \ = 'setlocal shiftwidth< softtabstop< tabstop<' -endif +" Unload this indent plugin; suppress errors because ancient Vim can't use the +" '<' suffix syntax for resetting local integer +let b:undo_user_indent + \ = 'silent! setlocal shiftwidth< softtabstop< tabstop<' -- cgit v1.2.3 From 6552de5accb651a5c0436bb77e97cffd93c6a72b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 13:50:33 +1300 Subject: Remove null command from b:undo_* variables I didn't realise that a null command at the front of .e.g '|cmd|cmd2' printed the current line! Removed that. --- vim/ftplugin/html.vim | 4 ++-- vim/ftplugin/perl.vim | 4 ++-- vim/ftplugin/sh.vim | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'vim') diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 27b38424..d2c6a3e3 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -30,7 +30,7 @@ nnoremap \ :call UrlLink() " Unload this filetype plugin -let b:undo_user_ftplugin = '' - \ . '|silent! nunmap c' +let b:undo_user_ftplugin + \ = 'silent! nunmap c' \ . '|silent! nunmap t' \ . '|silent! nunmap r' diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index 7f6eb7fe..0db8d1ab 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -14,7 +14,7 @@ nnoremap \ :%!perltidy " Unload this filetype plugin -let l:undo_user_ftplugin = '' - \ . '|silent! unmap c' +let l:undo_user_ftplugin + \ = 'silent! unmap c' \ . '|silent! unmap l' \ . '|silent! unmap t' diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index a8c94445..61d2994d 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -46,8 +46,8 @@ nnoremap \ :execute b:sh_lint " Unload this filetype plugin -let b:undo_user_ftplugin = '' - \ . '|setlocal keywordprg<' +let b:undo_user_ftplugin + \ = 'setlocal keywordprg<' \ . '|unlet! b:sh_check b:sh_lint' \ . '|silent! unmap c' \ . '|silent! unmap l' -- cgit v1.2.3 From 6a5c86738c85296e0b8393dac7ce58285fa85149 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 8 Nov 2017 13:51:32 +1300 Subject: Use "nunmap" not "unmap" for b:undo_* var We only want to remove the normal mode mapping, since that's all we set. --- vim/ftplugin/perl.vim | 6 +++--- vim/ftplugin/sh.vim | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'vim') diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index 0db8d1ab..c18653d2 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -15,6 +15,6 @@ nnoremap " Unload this filetype plugin let l:undo_user_ftplugin - \ = 'silent! unmap c' - \ . '|silent! unmap l' - \ . '|silent! unmap t' + \ = 'silent! nunmap c' + \ . '|silent! nunmap l' + \ . '|silent! nunmap t' diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 61d2994d..60e8b6c4 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -49,5 +49,5 @@ nnoremap let b:undo_user_ftplugin \ = 'setlocal keywordprg<' \ . '|unlet! b:sh_check b:sh_lint' - \ . '|silent! unmap c' - \ . '|silent! unmap l' + \ . '|silent! nunmap c' + \ . '|silent! nunmap l' -- cgit v1.2.3