davidoc/taskpaper.vim — Issue #27: Fix So That Newline Behavior Works Correctly With Autoindent
Author: jeetsukumaran
Created: 2012-02-20 00:20:56+00:00
State: open

Currently, if autoindent is on (`set ai`), hitting enter results in an extra indent. The following modification to 'after/plugin/taskpaper.vim' fixes this:

" remove autoindent
set noai

" this function figures out and adds the appropriate indent
function! TaskpaperNewline()
let cur_indent_spaces = indent('.')
let cur_indent_tabs = cur_indent_spaces / &tabstop
if cur_indent_tabs == 0
let cur_indent_tabs = 1
endif
let leader = repeat(nr2char(9), cur_indent_tabs)
execute "normal! o" . leader . "- "
startinsert
endfunction

" map carriage return to create new todo entry
autocmd filetype taskpaper :nnoremap :call TaskpaperNewline()
autocmd filetype taskpaper :inoremap :call TaskpaperNewline()