Fixed formatexpr for insert mode
This commit is contained in:
parent
5e4e8ef3ef
commit
110837e71a
@ -70,8 +70,10 @@ function! vimtex#format#formatexpr() " {{{1
|
|||||||
let l:tries -= 1
|
let l:tries -= 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
" Move cursor to first non-blank of the last formatted line
|
" Set cursor at appropriate position
|
||||||
if mode() !=# 'i'
|
if mode() =~# '[iR]'
|
||||||
|
call cursor(l:bottom, col([l:bottom, '$']))
|
||||||
|
else
|
||||||
execute 'normal!' l:bottom . 'G^'
|
execute 'normal!' l:bottom . 'G^'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -128,10 +130,13 @@ endfunction
|
|||||||
" }}}1
|
" }}}1
|
||||||
function! s:format_build_lines(start, end) " {{{1
|
function! s:format_build_lines(start, end) " {{{1
|
||||||
"
|
"
|
||||||
" Get the desired text to format as a list of words
|
" Get the desired text to format as a list of words, but preserve the ending
|
||||||
|
" line spaces
|
||||||
"
|
"
|
||||||
let l:words = split(join(map(getline(a:start, a:end),
|
let l:text = join(map(getline(a:start, a:end),
|
||||||
\ 'substitute(v:val, ''^\s*'', '''', '''')'), ' '), ' ')
|
\ 'substitute(v:val, ''^\s*'', '''', '''')'), ' ')
|
||||||
|
let l:spaces = matchstr(l:text, '\s*$')
|
||||||
|
let l:words = split(l:text, ' ')
|
||||||
if empty(l:words) | return 0 | endif
|
if empty(l:words) | return 0 | endif
|
||||||
|
|
||||||
"
|
"
|
||||||
@ -152,6 +157,13 @@ function! s:format_build_lines(start, end) " {{{1
|
|||||||
let l:lnum += 1
|
let l:lnum += 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
|
" Append the ending line spaces
|
||||||
|
"
|
||||||
|
if !empty(l:spaces)
|
||||||
|
call setline(l:lnum, getline(l:lnum) . l:spaces)
|
||||||
|
endif
|
||||||
|
|
||||||
"
|
"
|
||||||
" Remove old text
|
" Remove old text
|
||||||
"
|
"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user