मेरे अनुभव में यह करने के लिए सबसे अच्छा तरीका है एक कस्टम समारोह के साथ है अन्य पात्रों के बाद। यह मानता है कि 'ts' सही ढंग से सेट है। फ़ाइलों को आप कुछ इस तरह करने से बेहतर गलत संरेखित कर रहे हैं बनाने के लिए एक लंबा रास्ता तय कर सकते हैं:
:set ts=8 " Or whatever makes the file looks like right
:set et " Switch to 'space mode'
:retab " This makes everything spaces
:set noet " Switch back to 'tab mode'
:RetabIndents " Change indentation (not alignment) to tabs
:set ts=4 " Or whatever your coding convention says it should be
आप एक फ़ाइल जहां सभी प्रमुख खाली स्थान के टैब ताकि लोगों को जो कुछ भी प्रारूप में इसे देख सकते हैं के साथ खत्म हो जाएगा वे चाहते हैं, लेकिन जहां सभी पिछला सफेद स्थान रिक्त स्थान है ताकि सभी अंतराल की टिप्पणियां, टेबल आदि किसी भी टैब चौड़ाई के साथ ठीक से लाइन हो जाएं।
संपादित
'exe' लाइन का स्पष्टीकरण:
execute '%[email protected]^\(\{'.&ts.'}\)\[email protected]\=repeat("\t", len(submatch(0))/'.&ts.')@'
" Execute the result of joining a few strings together:
%s " Search and replace over the whole file
@[email protected]@ " Delimiters for search and replace
^ " Start of line
\(...\) " Match group
\{...} " Match a space the number of times in the curly braces
&ts " The current value of 'tabstop' option, so:
" 'string'.&ts.'string' becomes 'string4string' if tabstop is 4
" Thus the bracket bit becomes \(\{4}\)
\+ " Match one or more of the groups of 'tabstop' spaces (so if
" tabstop is 4, match 4, 8, 12, 16 etc spaces
@ " The middle delimiter
\= " Replace with the result of an expression:
repeat(s,c) " Make a string that is c copies of s, so repeat('xy',4) is 'xyxyxyxy'
"\t" " String consisting of a single tab character
submatch(0) " String that was matched by the first part (a number of multiples
" of tabstop spaces)
len(submatch(0)) " The length of the match
/'.&ts.' " This adds the string "/4" onto the expression (if tabstop is 4),
" resulting in len(submatch(0))/4 which gives the number of tabs that
" the line has been indented by
) " The end of the repeat() function call
@ " End delimiter
बढ़िया जवाब। मुझे उस 'निष्पादन' कथन में खोदना होगा क्योंकि यह कुछ गहरे अंधेरे जादूगरों की तरह दिखता है। –
खुशी है कि यह सहायक है। मैंने 'execute' कथन क्या कर रहा है इसका एक स्पष्टीकरण जोड़ा है। – DrAl
मुझे इस फ़ंक्शन का उपयोग करके कोई सफलता नहीं मिली है। जब मैं इसका उपयोग कर चलाता हूं: RetabIndents, मुझे मिलता है: फ़ंक्शन प्रोसेसिंग करते समय त्रुटि मिली: लाइन 2: ई 486: पैटर्न नहीं मिला:^\ (\ {4} \) \ + –