0

I have the next lines of text in a file:

eslint.vim
flow.vim
jscs.vim
jshint.vim
standard.vim
xo.vim

How can I yank names (without '.vim' part)?

Even better would be to format it to look like this:

'eslint', 'flow', 'jscs', 'jshint', 'standard', 'xo'
1

I think the easiest solution is to use two substitute commands:

First remove the .vim part, join all the lines and add comma between the words:

:'<,'>s/.vim/\n/, /

That will give you this:

eslint, flow, jscs, jshint, standard, xo, 

Then surround the words with quotes:

:s/\w\+/'\0'/g

You'll get:

'eslint', 'flow', 'jscs', 'jshint', 'standard', 'xo', 

Note the last comma that you might need to delete with $x for example.

  • 2
    typo, extra / in first command between vim and \n... the two substitutes can be combined :'<,'>s/\v(\w+)\.vim\n/'\1', /g.... and trailing would be , and space not just , – Sundeep Aug 6 '17 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.