From: Hiroshi Shirosaki Date: Sat, 20 Jan 2018 11:56:57 +0000 (+0900) Subject: Merge pull request #354 from codybuell/master X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/861e84fc0bc97be8387e92ac2fc180599dc2b5a3?hp=f416b35dba4505f85dca9cafb984ab7d89e57f96 Merge pull request #354 from codybuell/master Add support to modify default file extension. --- diff --git a/README.md b/README.md index ca7eef2..67d473c 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,14 @@ If you follow a link like this `[link text](link-url)` using the `ge` shortcut, let g:vim_markdown_autowrite = 1 ``` +### Change default file extension + +If you would like to use a file extension other than `.md` you may do so using the `vim_markdown_auto_extension_ext` variable: + +```vim +let g:vim_markdown_auto_extension_ext = 'txt' +``` + ## Mappings The following work on normal and visual modes: diff --git a/doc/vim-markdown.txt b/doc/vim-markdown.txt index 109ffdc..714d3a9 100644 --- a/doc/vim-markdown.txt +++ b/doc/vim-markdown.txt @@ -26,6 +26,7 @@ Contents ~ |vim-markdown-do-not-require-.md-extensions-for-markdown-links| 13. Auto-write when following link |vim-markdown-auto-write-when-following-link| + 14. Change default file extension |vim-markdown-auto-extension-ext| 4. Mappings |vim-markdown-mappings| 5. Commands |vim-markdown-commands| 6. Credits |vim-markdown-credits| @@ -309,6 +310,15 @@ this option will automatically save any edits you made before moving you: > let g:vim_markdown_autowrite = 1 < +------------------------------------------------------------------------------- + *vim-markdown-auto-extension-ext* +Change default file extension ~ + +If you would like to use a file extension other than '.md' you may do so using +the 'vim_markdown_auto_extension_ext' variable: +> + let g:vim_markdown_auto_extension_ext = 'txt' +< =============================================================================== *vim-markdown-mappings* Mappings ~ diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index d7c3777..1078f3d 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -599,10 +599,16 @@ if !exists('*s:EditUrlUnderCursor') endif endif if l:url != '' + let l:ext = '' if get(g:, 'vim_markdown_no_extensions_in_markdown', 0) - let l:url .= '.md' + " use another file extension if preferred + if exists('g:vim_markdown_auto_extension_ext') + let l:ext = '.'.g:vim_markdown_auto_extension_ext + else + let l:ext = '.md' + endif endif - let l:url = fnamemodify(expand('%:h').'/'.l:url, ':.') + let l:url = fnameescape(fnamemodify(expand('%:h').'/'.l:url.l:ext, ':.')) execute 'edit' l:url endif if l:anchor != ''