I have these lines in my .vimrc file:

:map <F9> :exe ':!gdbset bp "%:'.line(".").'"'<CR><CR>
:map <F8> :exe ':!gdbset clear bp "%:'.line(".").'"'<CR><CR>

They work great for adding and removing break points in gdb! Only one problem (that I know of)... for some reason line numbers in the 80's don't work. If I put my cursor on line 85 and press F9 then it should put a breakpoint on line 85. If I put my cursor on line 75 and press F9 it should put a breakpoint on line 75.

The resulting breakpoints look like this:

b myfile.cc:5
b myfile.cc:75

Line 85 did not work. I've tested the 80's. None of them work. All other lines seem to work. Why? I'm sure one of you VIM experts can explain this to me. It's almost like the ":8" are being interpreted as some other command or something.

  • Not sure this is entirely *nix-specific... Apr 10, 2012 at 7:54
  • Do lines 90-99 work? If not, maybe the number is being treated as octal instead of decimal. Does it have a leading zero somewhere? You didn't show us the contents of gdbset or how to get it, so it's hard to tell.
    – Mikel
    Apr 10, 2012 at 14:47
  • Yes, lines 90-99 work fine! I don't get it.
    – exvance
    Apr 10, 2012 at 17:21
  • Are lines 80-89 executable? If they're comments, you might not be able to set a breakpoint on those lines. Does gdbset ... on a line in the 80-89 range produce any error when you run it from the command line?
    – Mikel
    Apr 11, 2012 at 1:58

1 Answer 1


%:8 is a valid filename-modifier, so it is being interpreted by Vim as a part of the :! command.

You can use expand('%') to manually expand %, and then properly quote it with shellescape(…,1):

:map <F9> :exe '!gdbset bp'       shellescape(expand('%').':'.line('.'),1)<CR><CR>
:map <F8> :exe '!gdbset clear bp' shellescape(expand('%').':'.line('.'),1)<CR><CR>
  • You rock!! This fixes it. I never would have figured that out. Thanks a lot!
    – exvance
    Apr 12, 2012 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .