diff --git a/plugin/UltiSnips/Util.py b/plugin/UltiSnips/Util.py index 14fd46f..9eb3d3c 100644 --- a/plugin/UltiSnips/Util.py +++ b/plugin/UltiSnips/Util.py @@ -17,11 +17,21 @@ class IndentUtil(object): self.et = (vim.eval("&expandtab") == "1") self.ts = int(vim.eval("&ts")) - self.tab = self.sts or self.ts + # The amount added when pressing tab in insert mode + self.ind_len = self.sts or self.ts + + def _strip_tabs(self, indent, ts): + new_ind = [] + for ch in indent: + if ch == '\t': + new_ind.append(" " * (ts - (len(new_ind) % ts))) + else: + new_ind.append(ch) + return "".join(new_ind) def indent_to_spaces(self, indent): """ Converts indentation to spaces respecting vim settings. """ - indent = indent.replace(" " * self.ts, "\t") + indent = self._strip_tabs(indent, self.ts) right = (len(indent) - len(indent.rstrip(" "))) * " " indent = indent.replace(" ", "") indent = indent.replace('\t', " " * self.ts) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 37a75d8..cdfb218 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -359,7 +359,7 @@ class Snippet(object): line_ind = "" else: line_ind = indent - line_ind += tabs * self._util.tab * " " + line_ind += tabs * self._util.ind_len * " " line_ind = self._util.indent_to_spaces(line_ind) line_ind = self._util.spaces_to_indent(line_ind) v.append(line_ind + line[tabs:])