I frequently use EasyAlign
in my tex files to align tables around the $
delimiter such that this
header1 & header2 & header3 \\
data1 & data2 & data3 \\
becomes this
header1 & header2 & header3 \\
data1 & data2 & data3 \\
As I have EasyAlign
mapped to gA
, my normal-mode keystrokes to achieve this are gAip*$
.
So my first thought was nnoremap <buffer> gT gAip*$
, but this doesn't invoke EasyAlign
.
As I can vip
to select inner paragraph, then :EasyAlign *&
to get the alignment, I tried putting these two in a mapped function in my vimfiles\ftplugin\tex.vim
:
function! EasyAlignTable()
normal! vip
EasyAlign *&
endfunction
nnoremap <buffer> gT :call EasyAlignTable()<cr>
but this somehow doesn't complete: vim
remains in visual-mode, and the alignment is not done.
So how do I write this function incorporating EasyAlign
?
nnoremap
which ignores existing mappings. Trynmap
. This is one of those not-too-common cases where you actually don't want the "noremap" variation.EasyAlign
and a range that is in effect when you select a paragraph. Try'<,'>EasyAlign *&
in your function instead.normal! vip:EasyAlign *&<CR>
nnoremap <buffer> gT :normal gAip*&<CR>
successfully over-mapping defaultgT
.nnoremap gT
mapping in your question which absolutely won't get any mapped keys within. A mapping that uses:normal
(without!
) is a totally different situation.