Permalink
Browse files

Changes cursor position when typing auto-indented keyword.

  • Loading branch information...
1 parent 64eeb2d commit ff0506e31b674c9a5b720d88d8f3e613865801da @amsardesai amsardesai committed Apr 20, 2015
Showing with 12 additions and 0 deletions.
  1. +12 −0 indent/tex.vim
View
@@ -101,9 +101,21 @@ function! Latexbox_CallIndent()
let window = getpos('.')
call setpos('.', cursor)
+ " Get first non-whitespace character of current line.
+ let line_start_char = matchstr(getline('.'), '\S')
+
+ " Get initial tab position.
+ let initial_tab = stridx(getline('.'), line_start_char)
+
" Execute the command.
execute 'normal! =='
+ " Get tab position difference.
+ let difference = stridx(getline('.'), line_start_char) - initial_tab
+
+ " Set new cursor Y position based on calculated difference.
+ let cursor[2] = cursor[2] + difference
+
" Restore the previous window position.
call setpos('.', window)
normal! zt

0 comments on commit ff0506e

Please sign in to comment.