Vim: Unterschied zwischen den Versionen

Aus C3D2
Zur Navigation springen Zur Suche springen
(→‎Tab-Completion: format fix)
(automagically close ( [ { and ")
Zeile 1: Zeile 1:
=Automatically close ( [ { and "=
<pre>
imap ( ()<Left>
imap [ []<Left>
imap { {}<Left>
imap " <C-V>"<C-V>"<Left>
</pre>
=Tab-Completion=
=Tab-Completion=
<pre>
<pre>

Version vom 12. Februar 2006, 01:33 Uhr

Automatically close ( [ { and "

imap ( ()<Left>
imap [ []<Left>
imap { {}<Left>
imap " <C-V>"<C-V>"<Left>

Tab-Completion

function InsertTabWrapper(direction)    " automagically decide what to do with <tab>
  let col = col('.') -1                 " <s-tab> in insert mode
  if !col
    return "\<tab>"         " insert Tab at the beginning of the line
  elseif a:direction < 0
    return "\<c-p>"         " insert Backward-Completion
  elseif getline('.')[col - 1] == '<space>'
    return "\<BS>\<TAB>"    " replace <space><tab> with <tab>
  elseif getline('.')[col - 1] !~ '\k'
    return "\<tab>"         " insert Tab if preceding character is not a keyword character
  else  
    return "\<c-n>"         " insert Forward-Completion
endfunction
        
inoremap <tab> <c-r>=InsertTabWrapper(1)<cr>
inoremap <s-tab> <c-r>=InsertTabWrapper(-1)<cr>