aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-07-22 23:57:15 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-07-22 23:57:15 +1200
commitaa2d8d9c3a6b5009ababe42a0210fd5389a95d23 (patch)
tree4dbda1822b29d755bf45b24b650860bf308aa1ce
parentAdd plugin in current state (diff)
downloadvim-alternate-filetypes-aa2d8d9c3a6b5009ababe42a0210fd5389a95d23.tar.gz
vim-alternate-filetypes-aa2d8d9c3a6b5009ababe42a0210fd5389a95d23.zip
Add spacing and comments
-rw-r--r--autoload/alternate_filetypes.vim12
-rw-r--r--plugin/alternate_filetypes.vim14
2 files changed, 26 insertions, 0 deletions
diff --git a/autoload/alternate_filetypes.vim b/autoload/alternate_filetypes.vim
index 08ac88d..4bf16f5 100644
--- a/autoload/alternate_filetypes.vim
+++ b/autoload/alternate_filetypes.vim
@@ -1,7 +1,18 @@
+" Switch to next alternate filetype if specified
function! alternate_filetypes#() abort
+
+ " We only have anything to do if there's a list of filetypes ready for us
if exists('b:alternate_filetypes')
+
+ " Get the index of the current filetype in the list of filetypes
let filetypes = b:alternate_filetypes
let index = index(filetypes, &filetype)
+
+ " If the current filetype is in the list of related filetypes, switch to
+ " the next filetype, or the first filetype if the current filetype is the
+ " last in the list; if it's not in there at all, clear the list, as
+ " something has gone wrong
+ "
if index >= 0
let &filetype = filetypes[
\ (index + 1) % len(filetypes)
@@ -10,4 +21,5 @@ function! alternate_filetypes#() abort
unlet b:alternate_filetypes
endif
endif
+
endfunction
diff --git a/plugin/alternate_filetypes.vim b/plugin/alternate_filetypes.vim
index e024c9b..7919b82 100644
--- a/plugin/alternate_filetypes.vim
+++ b/plugin/alternate_filetypes.vim
@@ -1,4 +1,18 @@
+"
+" alternate_filetypes.vim: Switch buffer to related filetypes, e.g. HTML while
+" editing PHP, or AWK/sed while editing shell script.
+"
+" Author: Tom Ryder <tom@sanctum.geek.nz>
+" License: Same as Vim itself
+"
+if exists('loaded_alternate_filetypes') || &compatible
+ finish
+endif
+
+" User command to switch to alternate filetype and display it
command -bar AlternateFileType
\ call alternate_filetypes#() | set filetype?
+
+" Mapping target to run user command
nnoremap <silent> <Plug>(AlternateFileType)
\ :<C-U>AlternateFileType<CR>