On 04/09/2021, Marc Chantreux <m...@unistra.fr> wrote: > > :w !tr -cs '[:alnum:]' '\n'|grep -c abc >
Is tr's -s option there to eliminate multiple newlines? If so, is there harm in omitting it, since grep won't count those anyway? :w !tr -c '[:alnum:]' '\n' | grep -c abc I think your one-liner is not bad. I initially thought it was a little, but not dramatically better than mine. It is a few characters shorter than this: :w !<% tr '\n' ' ' | awk '{print gsub(/abc/, "")}' However, then I noticed that your version does not catch multiple occurrences that aren't separated by something else. Again, contrary to your slightly inaccurate subject line (that've now changed), I'm really looking for substrings, which may or may not be separate words. Basically, I'm looking for something as simple as possible that matches what vim's :%s/abc//gn does, but in OpenBSD's (n)vi. The reason I caught that discrepancy is that I wondered why you were matching everything OTHER than [:alnum:] and not just matching [:blank:] like so: :w !tr '[:blank:]' '\n' | grep -c abc However, that's as inaccurate as, or potentially even more inaccurate than your version, at least as far as vim-ilarity is concerned. My awk-ward incantation matches vim's :%s/abc//gn precisely. It would however probably not be a good idea to type that every time if you needed to use this regularly. Stick a ~/bin/ into your PATH, put a chmodded 'ocur' script into that bin, and modify the one-liner so it can be called in a reasonable way, preferably by :w !ocur % or something like that. If ocur is too obscure, count might suit, and it's only five letters. One, two, three, four, FIVE LETTERS, HAR HAR HAR HAR! Honestly, I'm becoming less and less confident there is a better-than-awk-ward option, short of getting sed to work with \n -- see my other email. That's the matter I'm really still baffled by and would love more enlightenment on. > Fair enough. so check the quick ref about windows (:h Q_wi) especially > the ones that makes you feel the nvi way. > > CTRL-W s or :split split window into two parts > :split {file} split window and edit {file} in one of them > CTRL-W ] split window and jump to tag under cursor > CTRL-W f split window and edit file name under the cursor > CTRL-W ^ split window and edit alternate file > CTRL-W j move cursor to window below > CTRL-W k move cursor to window above > CTRL-W CTRL-W move cursor to window below (wrap) > CTRL-W W move cursor to window above (wrap) > CTRL-W t move cursor to top window > CTRL-W b move cursor to bottom window > CTRL-W p move cursor to previous active window Thank you again! :) >> Maybe I'm just not truly ready for vim (though I do use it at times). > > there is no such thing as 'ready for vim'. nowadays, i still find stuff > on the vim help and think 'damn! i missed it since 25 years!' vi (and > vim) is a langage the way english is: lot of experience and vocabulary > helps you to be much more concise and precise but you don't need PhD > to have helpful cheap chats. It's not a perfect metaphor. Unlike English, vi's learning curve is steep at the start. Early on, English is deceptively easy to pick up for native and second-language speakers alike. It is only once you've summited a number of seriously high peaks that you begin to appreciate how much more there is -- even disregarding idioms and varieties, you're looking at a vocabulary three times as large as what comparable languages have. Why? Because, as no perpetually aggrieved gammon would admit, because the English, or should I say the Anglo-Saxons are a defeated people. Trounced by or on behalf of whom? That's right: The French. Hastings 1066. Look it up. And that was the start of English becoming very large and complex, because it had to accommodate the language of the new francophone ruling class. Ironically the linguistic effect of Britannia ruling the waves later on was much the same. Oh the insidiousness of linguistic reverse colonisation! ;) One wonders if l'Académie appreciates that point. It's all very well being the Edo shogunate of modern languages, but it's not what's gotten English to where it is today. But I digress. >> None of the above is intended as throwing anything back in your face >> however, and I thank you very much for your reply. > > I really don't took things personally and i know that vim is an > overbloated vi but some features are really awesome and the UI is > simpler to use (i don't care about the look but vim is more forgiven > and comes with helpful visual signals). On the other hand: nvi is a too > minimal subset of it to be my daily editor but it's really helpful for > simple sysop tasks. It is only once one has seen somebody make the leap from front panel toggle switches to Wozmon and the Apple-1 BASIC prompt, that one can begin to appreciate the revolutionary effect of moving from ed- or ex-like line editing to vi-like screen editing. Everything else is gravy. <https://www.youtube.com/watch?v=bHLt2NrSEuU&t=2m33s> <https://www.youtube.com/watch?v=36NgkpctW6k&t=5m22s> > From time to time, someone starts a new clone to try to reach a new > balance but vim and nvi pleases enough people so those projects are doomed. > > regards, > marc Presumably you remember this? <https://embeddedartistry.com/blog/2017/11/23/an-open-source-koan/> Cheers, Ian