2012-03-21 20 views
5

में मांगपत्र स्तर की गणना एक JavaDoc शैली टिप्पणी जो एक दांतेदार सूची में शामिल हैं (जब expandtab सेट किया गया है और softtabstop=2) लिखने पर विचार कैसे टिप्पणी के बाद अंतरिक्ष की अनदेखी करने के:जब विम

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

वर्तमान में, First line: टाइपिंग और मारने के बाद वापसी, विम सही ढंग से *<space> डालेंगे। हालांकि, जब मैंने दूसरी पंक्ति को इंडेंट करने के लिए टैब पर मारा, तो केवल एक स्थान दो के बजाय स्थान डाला जाएगा।

क्या इसे ठीक करना संभव है, इसलिए * के बाद की जगह इंडेंट गणनाओं के दौरान अनदेखा की जाएगी?

+0

चूंकि आपने 2 अंतरिक्ष के लिए टैब निर्धारित करते हैं, यह ध्यान में पहले एक समय लग जाएगा। मैं आपको वर्तमान सेटिंग्स लेने और फिर एक स्थान जोड़ने का सुझाव देता हूं। एंटर दबाएं, आपको अपनी इच्छित स्थिति (* + 3 रिक्त स्थान) पर रोकना चाहिए। –

उत्तर

1

मैं अभी भी विमस्क्रिप्ट में एक नौसिखिया हूं, लेकिन मैंने इसे आपके लिए पकाया। इसे आज़माएं और मुझे बताएं कि आप क्या सोचते हैं।

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

बहुत बुरा [Prettify] (http://code.google.com/p/google-code-prettify/) विमस्क्रिप्ट का समर्थन नहीं करता है। –