Skip to content

Commit ea8ff3d

Browse files
committed
Changed column calculations to use screen/virtual columns.
Movements where throw off because they work with screen columns, but not all calculations were done using screen columns. The plugin should now work as expected on lines with tabs, and also multibyte characters. Fixes #1
1 parent ca711dd commit ea8ff3d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

plugin/textobj/word-column.vim

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ if (exists("g:loaded_textobj_word_column"))
33
endif
44

55
function! TextObjWordBasedColumn(textobj)
6-
let cursor_col = col(".")
6+
let cursor_col = virtcol(".")
77
exec "silent normal! v" . a:textobj . "\<Esc>"
8-
let start_col = col("'<")
9-
let stop_col = col("'>")
8+
let start_col = virtcol("'<")
9+
let stop_col = virtcol("'>")
1010
let line_num = line(".")
1111
let indent_level = s:indent_levell(".")
1212
let start_line = s:find_boundary_row(line_num, start_col, indent_level, -1)
@@ -19,7 +19,7 @@ function! TextObjWordBasedColumn(textobj)
1919
let col_bounds = s:find_smart_boundary_cols(start_line, stop_line, cursor_col, a:textobj, whitespace_only)
2020
endif
2121

22-
exec "keepjumps silent normal!" . start_line . "gg" . col_bounds[0] . "|" stop_line . "gg" . col_bounds[1] . "|"
22+
exec "keepjumps silent normal!" . start_line . "gg" . col_bounds[0] . "|" . stop_line . "gg" . col_bounds[1] . "|"
2323
endfunction
2424

2525
function! s:find_smart_boundary_cols(start_line, stop_line, cursor_col, textobj, whitespace_only)
@@ -35,8 +35,8 @@ function! s:find_smart_boundary_cols(start_line, stop_line, cursor_col, textobj,
3535

3636
while index <= a:stop_line
3737
exec "keepjumps silent normal!" index . "gg" . a:cursor_col . "|" . word_start . "v" . a:textobj . "\<Esc>"
38-
let start_col = col("'<")
39-
let stop_col = col("'>")
38+
let start_col = virtcol("'<")
39+
let stop_col = virtcol("'>")
4040
let col_bounds = s:col_bounds_fn(start_col, stop_col, col_bounds)
4141
let index = index + 1
4242
endwhile
@@ -72,8 +72,10 @@ endfunction
7272

7373
function! s:whitespace_column_wanted(start_line, stop_line, cursor_col)
7474
let index = a:start_line
75+
let expanded_tabs = repeat(" ", &tabstop)
7576
while index <= a:stop_line
76-
let char = getline(index)[a:cursor_col - 1]
77+
let line = substitute(getline(index), "\t", expanded_tabs, "g")
78+
let char = line[a:cursor_col - 1]
7779
if char != " " && char != "\t"
7880
return 0
7981
end

0 commit comments

Comments
 (0)