2012-03-20 14:26:57 -04:00
|
|
|
"
|
2012-03-20 13:31:37 -04:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" Double-Tap makes annoying comments go away
|
|
|
|
" Maintainer: Øystein Walle <oystwa@gmail.com>
|
|
|
|
" Version: 0.1
|
|
|
|
" Description: Opening a new line from a comment may insert an unwanted
|
|
|
|
" comment; (re)pressing Enter will clear the line for you. This works if in
|
|
|
|
" insert mode and pressing Enter as well when using o or O in normal mode
|
|
|
|
" Last Change: Tue Mar 20 16:40:28 CET 2012
|
|
|
|
" License: Vim License (see :help license)
|
|
|
|
" Location: plugin/double-tab.vim
|
|
|
|
" Website: https://github.com/osse/double-tap
|
|
|
|
"
|
|
|
|
" See double-tap.txt for help. This can be accessed by doing:
|
|
|
|
"
|
|
|
|
" :helptags ~/.vim/doc
|
|
|
|
" :help doubletap.txt
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
let s:doubletap_version = '0.1'
|
|
|
|
|
|
|
|
" Vimscript Setup: {{{1
|
|
|
|
" Allow use of line continuation.
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
" We need version 7 for <expr> mappings
|
|
|
|
" as well as the user wanting nocompatible
|
|
|
|
if exists("g:loaded_doubletap")
|
2012-03-20 14:26:57 -04:00
|
|
|
\ || !has("comments")
|
2012-03-20 13:31:37 -04:00
|
|
|
\ || v:version < 700
|
|
|
|
\ || &compatible
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_doubletap = 1
|
|
|
|
" }}}
|
|
|
|
|
2015-05-10 10:46:02 -04:00
|
|
|
let s:pattern = '\([b,]\|^\):\zs\([^,]\+\)' " This patterns finds the wanted
|
2012-10-04 17:57:07 -04:00
|
|
|
" item in 'comments'
|
2012-03-20 13:31:37 -04:00
|
|
|
|
|
|
|
let s:commStart = {} " dict to hold the comment starters using
|
|
|
|
" the current filetype as key
|
|
|
|
|
|
|
|
" This function returns a regular <CR> if the current line
|
|
|
|
" is not simply an empty comment. Otherwise it clears the line
|
2012-03-20 13:52:51 -04:00
|
|
|
function! s:Detect_empty_comment()
|
2012-03-20 14:26:57 -04:00
|
|
|
" Do nothing in particular if no filetype is set
|
|
|
|
if empty(&ft)
|
|
|
|
return "\<CR>"
|
|
|
|
endif
|
2012-03-20 13:31:37 -04:00
|
|
|
" Captures the comment starter if necessary; only once per filetype
|
|
|
|
if !has_key(s:commStart, &ft)
|
2012-10-04 17:57:07 -04:00
|
|
|
let s:commStart[&ft] = matchstr(&comments, s:pattern)
|
2012-03-20 13:31:37 -04:00
|
|
|
endif
|
|
|
|
let line = getline('.')
|
2015-09-09 18:32:00 -04:00
|
|
|
if s:commStart[&ft] != '' && line =~ '^\s*\V'. s:commStart[&ft] . '\m\s*$'
|
2012-03-20 13:31:37 -04:00
|
|
|
return "\<C-U>"
|
|
|
|
else
|
|
|
|
return "\<CR>"
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-03-20 13:52:51 -04:00
|
|
|
if !hasmapto('<Plug>DoubletapDetect')
|
2012-11-30 11:29:02 -05:00
|
|
|
silent! imap <unique> <CR> <Plug>DoubletapDetect
|
2012-03-20 13:52:51 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
inoremap <expr> <Plug>DoubletapDetect <SID>Detect_empty_comment()
|
2012-03-20 13:31:37 -04:00
|
|
|
|
|
|
|
" Teardown:{{{1
|
|
|
|
"reset &cpo back to users setting
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
" }}}
|
|
|
|
|
|
|
|
" vim: set sw=2 sts=2 et fdm=marker:
|