3 ms·
In vim: :'<,'>!awk '{printf("\"\%s\", ",$0)}' or to do the whole file: :%!awk '{printf("\"\%s\", ",$0)}' What I find nice about this approach is tha
by Skunkleton 7y ago
In vim:
:'<,'>!awk '{printf("\"\%s\", ",$0)}'
or to do the whole file:
:%!awk '{printf("\"\%s\", ",$0)}'
What I find nice about this approach is that I can use my knowledge of awk in other non-vim contexts. Similarly I can use my knowledge of other text processing commands to do things in vim, like reformat text into columns (:%!column -t) for example.
Of course you could use vim commands to do the same thing:
0<ctrl-v>GI"<esc>$<ctrl-v>GA", <esc>VGJ
Which would have the benefit of making it more customizable at the expense of....well you can see what you have to type.
- Koshkin 7y ago> I can use my knowledge That’s a great point. On the other hand, truly, “What happens in emacs, stays in emacs.”
- ska 7y agoOf course you can do the same shell thing easily enough with emacs, too.
- catalogia 7y agoThe way I'd do it in vim is to record a macro of doing it interactively by hand once, then play back that macro. I have space bound to @q to make playing back the macro in the q register easy (using the q register because q is also how you start and stop recording a macro.) noremap <Space> @q These days I do this from evil-mode: (define-key evil-normal-state-map " " "@q")
- deleted 7y ago[deleted]
- patrec 7y agoYou can use your knowledge of emacs in other non-emacs contexts as well! Elisp is a reasonably capable, if sprawling, programming language and comes with a lot of useful text and code munging stuff, as well as with cross-platform networking and filesystem support, and more esoteric stuff like calendar and symbolic/aribtrary precision math. And that's before installing any extra packages. I've written shebang scripts with Emacs (rather than say python or bash) on multiple occasions. Prior to windows growing linux support it probably also used to be one of the easier ways to write some unixy-feeling but cross-platform scripts; you can even craft a "shebang line" that works for both windows and unix. Having said that, due to general eco-systems advances, writing scripts in emacs has probably become less attractive than it used to be.
- Skunkleton 7y agoI really dig that about emacs. Having a programming language that is geared toward text processing is super useful. Doubly so when your editor is extensible in the same language.