I have a few functions to help with adding PHP docblock tags. Suppose a block like this:
/**
* Does a thing
*
* |
*/
Where |
is my cursor position. I have a mapping to <localleader>@p
, for instance, to insert an @package
tag:
* @package foo-bar
Function
Here's my basic function:
function! MaybeSetPackage()
if ! exists( "g:php_package" )
let l:package = ''
else
let l:package = g:php_package
endif
execute ':normal! a@package ' . l:package
endfunction
Expectation
When I move to a line in the docblock and type \@p
, this should be the result:
/**
* Does a thing
*
* @package foo-bar
*/
What sometimes happens
If I'm on a line in NORMAL mode, like:
/**
* Does a thing
* |
*/
And hit o
, I'm here:
/**
* Does a thing
*
* |
*/
And then, while still in INSERT mode, I type \@p
, I get this:
/**
* Does a thing
*
*@package foo-bar
*/
However, if I type o
, delete the space after *
, type a new space, and then do \@p
, I get this:
/**
* Does a thing
*
* @package foo-bar
*/
Why?
Why, after hitting o
and getting
* |
does my function seem to remove the automatically inserted space and leave me with
*@package foo-bar
but when I delete the automatically inserted space and add my own, followed by my mapping, I get the expected result of
* @package foo-bar
?
Update
Adding my mapping:
autocmd FileType php inoremap <buffer> <localleader>@p <esc>:call MaybeSetPackage()<CR>
get()
function