Search code examples
vimfile-io

Vim gF should open file and jump to line


I tried out gF and it seems to not behave like mentioned in :help gF

If cursor is positioned on an entry x.c and I type gf the file is opened.

If cursor is positioned on an entry x.c:3 and I type gF I get E447: Can't find file "x.c:3" in path. Whereby :3 should tell vim to jump to line 3.

What do I miss?


Solution

  • Enter :set isfname

    It'll show an OS dependent list of all characters considered being possibly part of a file name. On my system (Windows), the column : appears in the list.

    isfname=@,48-57,/,\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=
    

    Hence it won't be considered by gF as a separator between file name and line number. However if I add a space between them, the behaviour goes as documented.

    Given how no sane person uses : in a file name, if you want to use gF on some compiler's output that says file.c:120, you can add this to your vimrc :

    set isfname-=:
    

    (mind the - before the =)

    If ever one day you need to open a file that has a : in its name, you can always enter :set isfname+=: to restore the column as a valid file name character for the duration of that session.