This is my simple script of vim


%norm f^ID
%norm $i,
%!awk '{ for (i=1;i<=NF;i++ ) printf $i " " }'

The first line delete all after the tab(^I) the second add a "," after every line the third convert line to column. If I used the three separate commands is perfect But when I did

:source myscript.vim

Only the second and third command are applied,the first with tab character no. Why?


If the ^I is the two characters ^ and I, then the first command would look for the character ^ and insert (I) a D at the start of those lines.

You should insert a literal tab character (with Ctrl+V Tab) where you now have ^ and I.

Alternatively, just use (something like)

%!cut -f 1 | awk -v ORS=', ' '{ print }'

This picks out the first tab-delimited column with the cut and then reformats the resulting rows into comma-space-separated columns.

Shorter, but just commas (not comma-space) between the resulting columns:

%!cut -f 1 | tr '\n' ','
  • Works fine,I have also found another alternative solution – elbarna Nov 11 '18 at 22:37

Alternate solution found,instead of enter the ^I, I simply enter ..a tab pressed after f (f+TAB D) So my script now is

#the space after f is not a space,is a tab so press tab

%norm f D
%norm $i,
%!awk '{ for (i=1;i<=NF;i++ ) printf $i " " }'

Tested and works perfectly.

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.