In a compilation log file whenever I get error it shows full path from root directory and line number.

After opening file in vim say following is the content of file,

Dir1/Dir2/src/ipv4.c 1223

In vim in esc mode When I take cursor on above line and type ctrl+wshift+f it will split the window horizontally and open file ipv4.c and take cursor to line number 1223.

go to line of file under cursor in split window. I want to set a small shortcut say gf which should be mapped to ctrl+wshift+f.

So everytime typing ctrl+wshift+f to do so is headache. So I want to map this to some custom shortcut say gf in .vimrc file. So How to do it?

2 Answers 2


A simple mapping could do the trick. Add the following to your ~/.vimrc:

nnoremap gf <c-w>F


  • May want to map <c-w>F to gf so that the functionality is swapped
  • Maybe remap the window key, <c-w>, as that sounds like a pain point. e.g. nnoremap <space> <c-w>
  • Use regular gf and use <c-6> or <c-o> to get back to the log file
  • Set a upper case mark, e.g. mM, so that you can get back to the log file, e.g. `M
  • May want this mapping to only apply to log files. Then add nnoremap <buffer> gf <c-w>gF to ~/.vim/after/ftplugin/python.vim where python is your filetype.

For more help see:

:h gf
:h Ctrl-w_F
:h mapping
:h Ctrl-6
:h Ctrl-o
:h m
:h mark-motions
:h after-directory
:h ftplugin
  • thanks jamessan. I tried "nnoremap gf <c-w>gF" but its opening file in new tab. How to open it in horizontally split window rather than newtab.
    – ypp174
    Mar 12, 2015 at 19:10
  • Thanks I tried "nnoremap gf <C-w>F" and it solved my problem. Thanks all.
    – ypp174
    Mar 12, 2015 at 19:20

This is not a direct answer to your question, because I wonder if Vim might already have a more comprehensive solution for your problem.

Vim has support for running a compilation process, opening the compilation output (in the QuickFix List), and jumping to lines where errors were reported.

Option 1

If you use a GNU Makefile, and you are in the same folder, then all you need to do to compile is type:


Option 2

But if you compile in a different way, you should first tell Vim how:

:set makeprg=gcc\ file.c\ -o\ myapp

" Or to avoid escaping those spaces, you can instead do:

:let &makeprg="gcc file.c -o myapp"

And then you can compile using your specified method, by doing:


Option 3

If you don't want to run the compilation from inside Vim, but you still want to open the logfile in the QuickFix List, then do this:

:cfile my_compilation.log

Viewing the errors

The QuickFix List is useful because it can recognise some error log formats, and help you to navigate them. To step forwards or backwards through errors, use:


To view all the errors, open the QuickFix Window:


In that window you can jump to source of an error by pressing Enter. To open in a newly split window, hit Ctrl+W Enter.

Further information

For more details on the whole process, see:

:help :make
:help 'makeprg'
:help quickfix
:help errorformat
  • 1
    If what the OP really wanted is to look at compilation errors then using :make and the quickfix is the way to go. Also take a look at :compiler for setting common different 'makeprg' and 'errorformat''s (See :h :compiler). I also find it good to have nice mappings for :cn/:cp. I use Tim Pope's unimpaired.vim which provide ]q and [q respectively. Mar 12, 2015 at 23:52

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.