I am using the jedi-vim extension and really don't like pressing ctrl-space to bring up auto-complete. I would like to use tab, but also obviously when coding I need tab for indentation as well.

I know that I will pretty much never press tab with the purpose of indenting when the character before my cursor is not a whitespace character. How can I map tab to ctrl space in this setting?

I only want it to apply in the case of a python file, and only in the current buffer (so if I change buffers the mapping disappears)

  • "but also obvioulsy when coding I need tab for indentation as well" - I don't mean to interfere with your coding habits but ... I actually never press tab for indentation. Ideally, vim should do the indentation for you based on autoindent, smartindent and the like. For cases when it's not working, use =, < and > to indent.
    – Friedrich
    Mar 10 at 9:14

1 Answer 1


Actually looks like I figured something out. Other people porbably know better. But this seems to work for me:

" Map tab to ctrl space in python files when you have something other than
" whitespace
function NoAutoComplete()
    if getline(".")[col(".")-2] == " " || col(".") == 1
        return 1
autocmd FileType python imap <buffer> <expr> <Tab> NoAutoComplete() ? "\<TAB>" : "\<C-@>" 

Note: I believe the map must be recursive to properly map ctrl space to what jedi-vim uses. Furthermore I have these settings for my "normal tab" so that the function only needs to check for spaces:

" show existing tab with 4 spaces width
set tabstop=4

" when indenting with '>', use 4 spaces width
set shiftwidth=4

" On pressing tab, insert 4 spaces
set expandtab
  • So you can mark your problem as solved by accepting your own response (tick on the side.) Welcome vi.SE
    – gildux
    Feb 8 at 20:27
  • 1
    Can't do that until tomorrow it says
    – hshah
    Feb 8 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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