From 047370533503e29b2e651ee6179f4e7074c202b8 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 13 Oct 2019 19:33:20 +0200 Subject: [PATCH] [UPDATE][VIM] Use b:undo_ftplugin You're supposed to undo the changes that you made to a buffer's variables when doing filetype-related settings. The variable 'b:undo_ftplugin' contains the commands necessary to revert any changes that you have made to accomodate this filetype. I removed the mappings for left and right in a quickfix windows because I don't use them, and the 'qf' plug-in already maps those (meaning I had an error when I tried to unmap them after qf already did so). --- vim/.vim/after/ftplugin/bash.vim | 3 +++ vim/.vim/after/ftplugin/c.vim | 1 + vim/.vim/after/ftplugin/cpp.vim | 1 + vim/.vim/after/ftplugin/d.vim | 1 + vim/.vim/after/ftplugin/gitcommit.vim | 1 + vim/.vim/after/ftplugin/json.vim | 1 + vim/.vim/after/ftplugin/pandoc.vim | 1 + vim/.vim/after/ftplugin/python.vim | 5 +++++ vim/.vim/after/ftplugin/qf.vim | 6 ++---- vim/.vim/after/ftplugin/rust.vim | 1 + vim/.vim/after/ftplugin/sh.vim | 3 +++ vim/.vim/after/ftplugin/zsh.vim | 3 +++ 12 files changed, 23 insertions(+), 4 deletions(-) diff --git a/vim/.vim/after/ftplugin/bash.vim b/vim/.vim/after/ftplugin/bash.vim index c69fa31..93ca934 100644 --- a/vim/.vim/after/ftplugin/bash.vim +++ b/vim/.vim/after/ftplugin/bash.vim @@ -1,8 +1,11 @@ " Use shfmt as ALE fixer for bash let b:ale_fixers=[ 'shfmt' ] +let b:undo_ftplugin.='|unlet b:ale_fixers' " Indent with 4 spaces, simplify script, indent switch cases, use Bash variant let b:ale_sh_shfmt_options='-i 4 -s -ci -ln bash' +let b:undo_ftplugin.='|unlet b:ale_sh_shfmt_options' " Use bash dialect explicitly, require explicit empty string test let b:ale_sh_shellcheck_options='-s bash -o avoid-nullary-conditions' +let b:undo_ftplugin.='|unlet b:ale_sh_shellcheck_options' diff --git a/vim/.vim/after/ftplugin/c.vim b/vim/.vim/after/ftplugin/c.vim index f80c047..432d12a 100644 --- a/vim/.vim/after/ftplugin/c.vim +++ b/vim/.vim/after/ftplugin/c.vim @@ -1,2 +1,3 @@ " Use compile_commands.json to look for additional flags let b:ale_c_parse_compile_commands=1 +let b:undo_ftplugin.='|unlet b:ale_c_parse_compile_commands' diff --git a/vim/.vim/after/ftplugin/cpp.vim b/vim/.vim/after/ftplugin/cpp.vim index f80c047..432d12a 100644 --- a/vim/.vim/after/ftplugin/cpp.vim +++ b/vim/.vim/after/ftplugin/cpp.vim @@ -1,2 +1,3 @@ " Use compile_commands.json to look for additional flags let b:ale_c_parse_compile_commands=1 +let b:undo_ftplugin.='|unlet b:ale_c_parse_compile_commands' diff --git a/vim/.vim/after/ftplugin/d.vim b/vim/.vim/after/ftplugin/d.vim index 2f58b05..4ade9e2 100644 --- a/vim/.vim/after/ftplugin/d.vim +++ b/vim/.vim/after/ftplugin/d.vim @@ -1,2 +1,3 @@ " Use my desired ALE fixer for D let b:ale_fixers=[ 'dfmt' ] +let b:undo_ftplugin.='|unlet b:ale_fixers' diff --git a/vim/.vim/after/ftplugin/gitcommit.vim b/vim/.vim/after/ftplugin/gitcommit.vim index aa7a9b8..786a668 100644 --- a/vim/.vim/after/ftplugin/gitcommit.vim +++ b/vim/.vim/after/ftplugin/gitcommit.vim @@ -1,2 +1,3 @@ " Enable spell checking on commit messages setlocal spell +let b:undo_ftplugin.='|setlocal spell<' diff --git a/vim/.vim/after/ftplugin/json.vim b/vim/.vim/after/ftplugin/json.vim index 7fbfbce..af3cb2b 100644 --- a/vim/.vim/after/ftplugin/json.vim +++ b/vim/.vim/after/ftplugin/json.vim @@ -1,2 +1,3 @@ " Use my desired ALE fixer for JSON let b:ale_fixers=[ 'jq' ] +let b:undo_ftplugin.='|unlet b:ale_fixers' diff --git a/vim/.vim/after/ftplugin/pandoc.vim b/vim/.vim/after/ftplugin/pandoc.vim index f922bf3..e96f98b 100644 --- a/vim/.vim/after/ftplugin/pandoc.vim +++ b/vim/.vim/after/ftplugin/pandoc.vim @@ -1,2 +1,3 @@ " Let ALE know that I want Markdown linters let b:ale_linter_aliases=[ 'markdown' ] +let b:undo_ftplugin.='|unlet b:ale_linter_aliases' diff --git a/vim/.vim/after/ftplugin/python.vim b/vim/.vim/after/ftplugin/python.vim index 061486b..294839b 100644 --- a/vim/.vim/after/ftplugin/python.vim +++ b/vim/.vim/after/ftplugin/python.vim @@ -1,10 +1,13 @@ " Use my desired ALE fixers for python let b:ale_fixers=[ 'black', 'isort' ] +let b:undo_ftplugin.='|unlet b:ale_fixers' " Use my desired ALE linters for python let b:ale_linters=[ 'flake8', 'mypy', 'pylint', 'pyls' ] +let b:undo_ftplugin.='|unlet b:ale_linters' "let b:ale_python_pyls_executable='pyls' let b:ale_python_pyls_auto_pipenv=1 +let b:undo_ftplugin.='|unlet b:ale_python_pyls_auto_pipenv' " Disable pycodestyle checks from pyls because I'm already using flake8 let b:ale_python_pyls_config={ @@ -16,6 +19,8 @@ let b:ale_python_pyls_config={ \ }, \ }, \ } +let b:undo_ftplugin.='|unlet b:ale_python_pyls_config' " Change max length of a line to 88 for this buffer to match black's settings setlocal colorcolumn=88 +let b:undo_ftplugin.='|setlocal colorcolumn<' diff --git a/vim/.vim/after/ftplugin/qf.vim b/vim/.vim/after/ftplugin/qf.vim index 32cc250..4947593 100644 --- a/vim/.vim/after/ftplugin/qf.vim +++ b/vim/.vim/after/ftplugin/qf.vim @@ -1,7 +1,5 @@ " Use h/l to go to the previous/next non-empty quickfix or location list nnoremap h :call quickfixed#older() +let b:undo_ftplugin.='|nunmap h' nnoremap l :call quickfixed#newer() - -" Use left/right to go to the previous/next non-empty quickfix or location list -nnoremap :call quickfixed#older() -nnoremap :call quickfixed#newer() +let b:undo_ftplugin.='|nunmap l' diff --git a/vim/.vim/after/ftplugin/rust.vim b/vim/.vim/after/ftplugin/rust.vim index 44d4666..234c187 100644 --- a/vim/.vim/after/ftplugin/rust.vim +++ b/vim/.vim/after/ftplugin/rust.vim @@ -1,2 +1,3 @@ " Use rustfmt as ALE fixer for rust let b:ale_fixers=[ 'rustfmt' ] +let b:undo_ftplugin.='|unlet b:ale_fixers' diff --git a/vim/.vim/after/ftplugin/sh.vim b/vim/.vim/after/ftplugin/sh.vim index f4e1bf1..e038c78 100644 --- a/vim/.vim/after/ftplugin/sh.vim +++ b/vim/.vim/after/ftplugin/sh.vim @@ -1,8 +1,11 @@ " Use shfmt as ALE fixer for sh let b:ale_fixers=[ 'shfmt' ] +let b:undo_ftplugin.='|unlet b:ale_fixers' " Indent with 4 spaces, simplify the code, indent switch cases, use POSIX let b:ale_sh_shfmt_options='-i 4 -s -ci -ln posix' +let b:undo_ftplugin.='|unlet b:ale_sh_shfmt_options' " Require explicit empty string test let b:ale_sh_shellcheck_options='-o avoid-nullary-conditions' +let b:undo_ftplugin.='|unlet b:ale_sh_shellcheck_options' diff --git a/vim/.vim/after/ftplugin/zsh.vim b/vim/.vim/after/ftplugin/zsh.vim index 20233e4..7cc0b5f 100644 --- a/vim/.vim/after/ftplugin/zsh.vim +++ b/vim/.vim/after/ftplugin/zsh.vim @@ -1,8 +1,11 @@ " Use shfmt as ALE fixer for zsh let b:ale_fixers=[ 'shfmt' ] +let b:undo_ftplugin.='|unlet b:ale_fixers' " Indent with 4 spaces, simplify script, indent switch cases, use Bash variant let b:ale_sh_shfmt_options='-i 4 -s -ci -ln bash' +let b:undo_ftplugin.='|unlet b:ale_sh_shfmt_options' " Use bash dialect explicitly, require explicit empty string test let b:ale_sh_shellcheck_options='-s bash -o avoid-nullary-conditions' +let b:undo_ftplugin.='|unlet b:ale_sh_shellcheck_options'