स्टीव मॉयर द्वारा प्रदान की जवाब में विधि का उपयोग मैं निम्नलिखित समाधान का उत्पादन करने में सक्षम था। यह एक नहीं बल्कि असजीला हैक मुझे डर लग रहा है और मुझे लगता है कि वहाँ एक neater समाधान होना चाहिए है, लेकिन यह काम करता है, और बस एक बफर में हर बार स्थिति लाइन अद्यतन किया जाता है शब्दों के सभी गिनती की तुलना में बहुत तेजी से होता है। मुझे यह भी ध्यान रखना चाहिए कि यह समाधान मंच स्वतंत्र है और यह नहीं मानता कि एक प्रणाली में 'wc' या कुछ समान है।
मेरे समाधान समय-समय पर बफर को अद्यतन नहीं है, लेकिन माइकल जैनसन द्वारा प्रदान की जवाब यह सुविधा प्रदान करने में सक्षम होगा। मैंने अभी तक एक उदाहरण नहीं पाया है जहां मेरा समाधान सिंक से बाहर हो जाता है। हालांकि मैंने केवल संक्षेप में इसका परीक्षण किया है क्योंकि मेरी ज़रूरतों के लिए एक सटीक लाइव शब्द गणना आवश्यक नहीं है। मिलान करने वाले शब्दों के लिए मैं जिस पैटर्न का उपयोग करता हूं वह भी सरल है और सरल टेक्स्ट दस्तावेज़ों के लिए है। अगर किसी के पास पैटर्न या किसी अन्य सुझाव के लिए बेहतर विचार है, तो कृपया उत्तर पोस्ट करने या इस पोस्ट को संपादित करने के लिए स्वतंत्र महसूस करें।
मेरे समाधान:
"returns the count of how many words are in the entire file excluding the current line
"updates the buffer variable Global_Word_Count to reflect this
fu! OtherLineWordCount()
let data = []
"get lines above and below current line unless current line is first or last
if line(".") > 1
let data = getline(1, line(".")-1)
endif
if line(".") < line("$")
let data = data + getline(line(".")+1, "$")
endif
let count_words = 0
let pattern = "\\<\\(\\w\\|-\\|'\\)\\+\\>"
for str in data
let count_words = count_words + NumPatternsInString(str, pattern)
endfor
let b:Global_Word_Count = count_words
return count_words
endf
"returns the word count for the current line
"updates the buffer variable Current_Line_Number
"updates the buffer variable Current_Line_Word_Count
fu! CurrentLineWordCount()
if b:Current_Line_Number != line(".") "if the line number has changed then add old count
let b:Global_Word_Count = b:Global_Word_Count + b:Current_Line_Word_Count
endif
"calculate number of words on current line
let line = getline(".")
let pattern = "\\<\\(\\w\\|-\\|'\\)\\+\\>"
let count_words = NumPatternsInString(line, pattern)
let b:Current_Line_Word_Count = count_words "update buffer variable with current line count
if b:Current_Line_Number != line(".") "if the line number has changed then subtract current line count
let b:Global_Word_Count = b:Global_Word_Count - b:Current_Line_Word_Count
endif
let b:Current_Line_Number = line(".") "update buffer variable with current line number
return count_words
endf
"returns the word count for the entire file using variables defined in other procedures
"this is the function that is called repeatedly and controls the other word
"count functions.
fu! WordCount()
if exists("b:Global_Word_Count") == 0
let b:Global_Word_Count = 0
let b:Current_Line_Word_Count = 0
let b:Current_Line_Number = line(".")
call OtherLineWordCount()
endif
call CurrentLineWordCount()
return b:Global_Word_Count + b:Current_Line_Word_Count
endf
"returns the number of patterns found in a string
fu! NumPatternsInString(str, pat)
let i = 0
let num = -1
while i != -1
let num = num + 1
let i = matchend(a:str, a:pat, i)
endwhile
return num
endf
यह तब तक स्थिति लाइन में जोड़ा जाता है:
:set statusline=wc:%{WordCount()}
मुझे आशा है कि इस विम में एक जीवित शब्द गणना की तलाश में किसी को भी मदद करता है। यद्यपि वह हमेशा सटीक नहीं है।वैकल्पिक रूप से जी ctrl-g आपको विम की शब्द गणना प्रदान करेगा!
स्रोत
2008-09-23 11:19:05
अपने वर्तमान कार्य क्या है करने के लिए
call airline#extensions#pandoc#init(s:ext)
जोड़ा? –
सामान्य शब्द गणना के लिए यहां आने वाले अन्य लोगों के लिए, 'g Ctrl-g' का उपयोग करें। – naught101