diff --git a/config/plugins/nerdcommenter.vim b/config/plugins/nerdcommenter.vim
index 8507aeb81..5349c2e8e 100644
--- a/config/plugins/nerdcommenter.vim
+++ b/config/plugins/nerdcommenter.vim
@@ -30,3 +30,19 @@ let g:NERDTrimTrailingWhitespace = 1
 " Always use alternative delimiter
 let g:NERD_c_alt_style = 1
 let g:NERDCustomDelimiters = {'c': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }}
+let g:ft = ''
+fu! NERDCommenter_before()
+  if &ft == 'markdown'
+    let g:ft = 'markdown'
+    let cf = context_filetype#get()
+    if cf.filetype !=# 'markdown'
+      exe 'setf ' . cf.filetype
+    endif
+  endif
+endfu
+fu! NERDCommenter_after()
+  if g:ft == 'markdown'
+    setf markdown
+    let g:ft = ''
+  endif
+endfu