I'm experimenting with running a sequence of commands on a csv file; doing some replacements, changing some stuff. I open the file in vim and use so! filewithcommands. But gg will never go to the top of the file, always to the second position.
contents of samplefile.csv:
sometext;morechars
nextline;withsomemoredata
areyou;gettingthepoint
contents of filewithcommands:
gg
When I open vim --clean and run :so! filewithcommands the cursor will jump to the second line for some reason. I've tried :0 but the same thing happens. Running Ubuntu with Vim v 9.0.2121.
The commands in your
filewithcommandsare supposed to be Ex commands sogg, a normal mode command, has nothing to do there. Actually, that is what Vim is trying to tell you with:More information is provided by
:help 492:Error messages are a good thing and skipping them is never a good idea. Case in point:
ggis wrong and won't do what you expect no matter what. Adding a!to skip the error message won't makeggmagically do what it can't do. All it will do is deprive you of an opportunity to understand the problem and fix it.The Ex command for moving the cursor to the top of the buffer is:
so that is what you should put in your
filewithcommands:(the
:is not necessary in that context)Alternatively, you can use
:help :normalto execute normal mode commands in an Ex context. Using the following in yourfilewithcommandswill have the same effect as1: