Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created May 20, 2015 23:36
Show Gist options
  • Save violetyk/6f3d04c88679810ccea6 to your computer and use it in GitHub Desktop.
Save violetyk/6f3d04c88679810ccea6 to your computer and use it in GitHub Desktop.
setlocal autoindent
setlocal formatoptions=tcroqln
setlocal nofoldenable
setlocal comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,b:-,b:+,b:*
abbreviate td [ ]
abbreviate tl - [ ]
nnoremap <silent><buffer> <Leader><Leader> :call ToggleCheckbox()<CR>
vnoremap <silent><buffer> <Leader><Leader> :call ToggleCheckbox()<CR>
inoremap <silent><buffer> <Tab> <C-o>:call IndentWithTab(1)<CR>
vnoremap <silent><buffer> <Tab> :call IndentWithTab(1)<CR>
inoremap <silent><buffer> <S-Tab> <C-o>:call IndentWithTab(-1)<CR>
vnoremap <silent><buffer> <S-Tab> :call IndentWithTab(-1)<CR>
function! ToggleCheckbox() abort
let l = getline('.')
if l =~ '\-\s\[\s\]'
call setline('.', substitute(l, '\-\s\[\s\]', '- [x]', ''))
elseif l =~ '\-\s\[x\]'
call setline('.', substitute(l, '\-\s\[x\]', '- [ ]', ''))
elseif l =~ '\+\s\[\s\]'
call setline('.', substitute(l, '\+\s\[\s\]', '+ [x]', ''))
elseif l =~ '\+\s\[x\]'
call setline('.', substitute(l, '\+\s\[x\]', '+ [ ]', ''))
elseif l =~ '\*\s\[\s\]'
call setline('.', substitute(l, '\*\s\[\s\]', '* [x]', ''))
elseif l =~ '\*\s\[x\]'
call setline('.', substitute(l, '\*\s\[x\]', '* [ ]', ''))
end
endfunction
function! IndentWithTab(arrow) abort
let l = getline('.')
if l =~ '^\s*[\-\+\*]'
if a:arrow > 0
execute 'normal ' count . '>>'
else
execute 'normal ' count . '<<'
endif
" let c = col('.')
" let col += shiftwidth()
" if strwidth(getline('.')) == c
" let c += 1
" endif
" call cursor(line('.'), c)
end
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment