Hot answers tagged

4

Using ex Ex is the command-line successor to the venerable ed, a line-oriented editor. You can access ex-mode from vim by typing Q (unless you have it mapped). gQ gives an improved ex-mode. See :help Ex-mode. You can also start ex from the command line, just like vim: ex {file} Then you type your commands, and ex does them. All the :-style commands ...


3

@D.BenKnoble has already given you a terrific answer explaining all the ins and outs of batch mode, but in case you were looking for a one liner similar to the one you already tried, here's one that I think is a bit simpler than the existing ones in the current answers: ex -sc 'norm!ggy$dd' -c '%norm!i^R0: ' -c 'x' file The first :normal command moves to ...


3

ex -s +'norm! gg"adiwdd' +'exec printf("%%s/^/%s : /", @a)' +'x' ex_txt norm! gg"adiwdd delete black in 1st line to register a, delete first line exec printf("%%s/^/%s : /", @a) add content of register a to start of every line. You can get content of register a via @a or getreg('a') in ex mode . check :h printf() if you have problem with %%. x save and exit ...


1

You can use registers (see :h reg) to store a word of a line. For you particular case, you would have to perform the following set of commands: :norm! gg"zyiw :norm! gg"_dd :%s/^/<C-r>z: / The first command yanks the first word into the register z from the first line The second command deletes the first line into blackhole register. The third command ...


1

Using call you are not able to get the return value of the function, regardless whether range is used or not. Aside from @Karl's answer, you can set some variable instead of using return. Such as function! Range() range abort let toreturn = 'my value' let s:retval = toreturn endfunction


Only top voted, non community-wiki answers of a minimum length are eligible