highlight MyWordUnderCursorHighlight cterm=bold autocmd CursorMoved * call MyHighlightWordUnderCursor() autocmd CursorMovedI * call MyHighlightWordUnderCursor() function! MyHighlightWordUnderCursor() python << endpython import vim # get the character under the cursor row, col = vim.current.window.cursor characterUnderCursor = '' try: characterUnderCursor = vim.current.buffer[row-1][col] except: pass # remove last highlight vim.command("match MyWordUnderCursorHighlight //") # if the cursor is currently located on a real word, move on and highlight it. # we don't want to highlight stars and slashes or other wild things. Just words. if characterUnderCursor.isalpha() or characterUnderCursor.isdigit() or characterUnderCursor is '_': # expand cword (vim special key) to get the word under the cursor wordUnderCursor = vim.eval("expand(\'\')") if wordUnderCursor is None : wordUnderCursor = "" else : wordUnderCursor = "\<" + wordUnderCursor + "\>" currentSearch = vim.eval("@/") if currentSearch != wordUnderCursor : # highlight it, if it is not already the currently searched word vim.command("match MyWordUnderCursorHighlight /\<" + wordUnderCursor + "\>/") endpython endfunction