aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-22 16:59:28 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-22 17:06:36 +1200
commit9929ca9ec20867cc910bf6b17839ee20dcd35f46 (patch)
tree9d0803f2fb8401832589d378fbf16cf5567fb63e /vim
parent2c7a5c37dec9b7321c2206c6cadb071eb0e84b20 (diff)
downloaddotfiles-9929ca9ec20867cc910bf6b17839ee20dcd35f46.tar.gz
dotfiles-9929ca9ec20867cc910bf6b17839ee20dcd35f46.zip
Round out and apply alternate filetypes plugin
This is a good one.
Diffstat (limited to 'vim')
-rw-r--r--vim/after/ftplugin/html.vim5
-rw-r--r--vim/after/ftplugin/php.vim11
-rw-r--r--vim/autoload/alternate_filetypes.vim14
-rw-r--r--vim/ftplugin/textarea.vim11
-rw-r--r--vim/plugin/alternate_filetypes.vim13
-rw-r--r--vim/vimrc3
6 files changed, 27 insertions, 30 deletions
diff --git a/vim/after/ftplugin/html.vim b/vim/after/ftplugin/html.vim
index 027fed1f..7866f31b 100644
--- a/vim/after/ftplugin/html.vim
+++ b/vim/after/ftplugin/html.vim
@@ -41,8 +41,3 @@ endif
nnoremap <buffer> <LocalLeader>r
\ :<C-U>call html#UrlLink()<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>r'
-
-" Switch to PHP filetype for templated PHP
-nnoremap <buffer> <LocalLeader>f
- \ :<C-U>setlocal filetype=php<CR>
-let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>f'
diff --git a/vim/after/ftplugin/php.vim b/vim/after/ftplugin/php.vim
index 3b023f9e..c7f77ece 100644
--- a/vim/after/ftplugin/php.vim
+++ b/vim/after/ftplugin/php.vim
@@ -21,12 +21,7 @@ let b:undo_ftplugin .= '|setlocal keywordprg<'
let b:regex_escape_flavor = 'ere'
let b:undo_ftplugin .= '|unlet b:regex_escape_flavor'
-" Stop here if the user doesn't want ftplugin mappings
-if exists('no_plugin_maps') || exists('no_php_maps')
- finish
+" Set HTML as an alternative filetype
+if !exists('b:alternate_filetypes')
+ let b:alternate_filetypes = [&filetype, 'html']
endif
-
-" Switch to HTML filetype for templated PHP
-nnoremap <buffer> <LocalLeader>f
- \ :<C-U>setlocal filetype=html<CR>
-let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>f'
diff --git a/vim/autoload/alternate_filetypes.vim b/vim/autoload/alternate_filetypes.vim
new file mode 100644
index 00000000..26c2a0d5
--- /dev/null
+++ b/vim/autoload/alternate_filetypes.vim
@@ -0,0 +1,14 @@
+function! alternate_filetypes#() abort
+ if exists('b:alternate_filetypes')
+ let filetypes = b:alternate_filetypes
+ let index = index(filetypes, &filetype)
+ if index >= 0
+ let &filetype = filetypes[
+ \ (index + 1) % len(filetypes)
+ \]
+ else
+ unlet b:alternate_filetypes
+ endif
+ endif
+ set filetype?
+endfunction
diff --git a/vim/ftplugin/textarea.vim b/vim/ftplugin/textarea.vim
index 5cdb2bba..4db97b58 100644
--- a/vim/ftplugin/textarea.vim
+++ b/vim/ftplugin/textarea.vim
@@ -1,13 +1,12 @@
+" Set mail message as an alternative filetype
+if !exists('b:alternate_filetypes')
+ let b:alternate_filetypes = [&filetype, 'mail']
+endif
+
" Stop here if the user doesn't want ftplugin mappings
if exists('no_plugin_maps') || exists('no_textarea_maps')
finish
endif
-" Local mapping to switch to mail filetype, just because that's very often the
-" contents of text areas I edit using TextEditorAnywhere
-nnoremap <buffer> <LocalLeader>f
- \ :<C-U>setlocal filetype=mail<CR>
-let b:undo_ftplugin = 'nunmap <buffer> <LocalLeader>f'
-
" #s expands to the #signature tag used in Cerb
inoreabbrev #s #signature
diff --git a/vim/plugin/alternate_filetypes.vim b/vim/plugin/alternate_filetypes.vim
index 6e765feb..d530b874 100644
--- a/vim/plugin/alternate_filetypes.vim
+++ b/vim/plugin/alternate_filetypes.vim
@@ -1,13 +1,4 @@
-function! s:AlternateFileType() abort
- let filetypes = get(b:, 'alternate_filetypes', [&filetype])
- if &filetype !=# filetypes[0]
- let &filetype = filetypes[0]
- endif
- set filetype?
-endfunction
command -bar AlternateFileType
- \ call s:AlternateFileType()
-nnoremap <Plug>(AlternateFileType)
+ \ call alternate_filetypes#()
+nnoremap <silent> <Plug>(AlternateFileType)
\ :<C-U>AlternateFileType<CR>
-nmap <Leader># <Plug>(AlternateFileType)
-nmap <Leader>3 <Leader>#
diff --git a/vim/vimrc b/vim/vimrc
index 79445ea6..7ce683a8 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -1611,6 +1611,9 @@ xmap <Leader>r <Plug>(ReplaceOperator)
nnoremap <Leader>!
\ :<Up><Home><S-Right>!<CR>
nmap <Leader>1 <Leader>!
+"" Leader,#/3 gives me my fortune
+nmap <Leader># <Plug>(AlternateFileType)
+nmap <Leader>3 <Leader>#
"" Leader,$/4 gives me my fortune
nnoremap <Leader>$
\ :<C-U>Fortune<CR>