Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Not sure this is entirely *nix-specific... – Ignacio Vazquez-Abrams Apr 10 '12 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 '12 at 14:47
Yes, lines 90-99 work fine! I don't get it. – exvance Apr 10 '12 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 '12 at 1:58
up vote 2 down vote accepted

%: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>
share|improve this answer
You rock!! This fixes it. I never would have figured that out. Thanks a lot! – exvance Apr 12 '12 at 16:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.