Skip to content

Commit

Permalink
Merge pull request #354 from codybuell/master
Browse files Browse the repository at this point in the history
Add support to modify default file extension.
  • Loading branch information
shirosaki committed Jan 20, 2018
2 parents f416b35 + 48bf7d8 commit 861e84f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions doc/vim-markdown.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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 ~
Expand Down
10 changes: 8 additions & 2 deletions ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ''
Expand Down

0 comments on commit 861e84f

Please sign in to comment.