Index: tools/clang-format/clang-format.py =================================================================== --- tools/clang-format/clang-format.py +++ tools/clang-format/clang-format.py @@ -38,7 +38,10 @@ text = '\n'.join(buf) # Determine range to format. - cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2 + cursor = int(vim.eval('line2byte(line("."))')) # line2byte is 1 based. + if cursor == -1: # -1 is an error, e.g. empty file + return + cursor = (cursor - 1) + vim.current.window.cursor[1] # col is 0 based. lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1) # Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format.