2012-03-21 20 views
5

yılında girinti düzeyini hesaplarken yorumlarla sonra boşluk görmezden nasıl First line: yazıp vurduktan sonra, Şubir javadoc tarzı bir girintili listesini içerir yorumunu (<code>expandtab</code> ayarlandığında ve <code>softtabstop=2</code>) yazma düşünün Vim

/** 
* First line: 
* - Indented text 
*/ 

geri, Vim *<space> doğru yerleştirecektir. Ancak, ikinci satırı girmek için sekmesine vurduğumda, iki yerine yalnızca bir alan eklenir.

Bunu düzeltmek mümkün mü, bu nedenle girinti hesaplamaları sırasında * sonrası boşluk göz ardı edilecektir?

+0

Sekmeyi 2 boşluğa ayarladığınızdan, ilk dikkate alınacaktır. Mevcut ayarları almanızı ve bir boşluk eklemenizi öneririm. Enter tuşuna basın, istediğiniz pozisyonda durmalısınız (* + 3 boşluk). –

cevap

1

Hala VimScript'te yeni başlayan biriyim ama bunu sizin için yaptım. Bir deneyin ve ne düşündüğünüzü bana bildirin.

function AdjustSoftTabStop() 
    " Only act if we are in a /* */ comment region 
    if match(getline('.'), '\s*\*') == 0 
     " Compensate for switching out of insert mode sometimes removing lone 
     " final space 
     if match(getline('.'), '\*$') != -1 
      " Put back in the space that was removed 
      substitute/\*$/\*/
      " Adjust position of the cursor accordingly 
      normal l 
     endif 
     " Temporary new value for softtabstop; use the currect column like a 
     " base to extend off of the normal distance 
     let &softtabstop+=col('.') 
    endif 
endfunction 

function ResetSoftTabStop() 
    " Note that you will want to change this if you do not like your tabstop 
    " and softtabstop equal. 
    let &softtabstop=&tabstop 
endfunction 

" Create mapping to call the function when <TAB> is pressed. Note that because 
" this is mapped with inoremap (mapping in insert mode disallowing remapping of 
" character on the RHS), it does not result in infinite recursion. 
inoremap <TAB> <ESC>:call AdjustSoftTabStop()<CR>a<TAB><ESC>:call ResetSoftTabStop()<CR>a 
+1

Çok kötü [Prettify] (http://code.google.com/p/google-code-prettify/) VimScript'i desteklemiyor. –

İlgili konular