If I edit an existing .js or .php file it uses a cached version(I'm assuming) of the command before I editted it.
I was under the impression autocmd! would clear any existing commands.
autocmd!
will clear the autocmds in the current augroup, but it will not undo any abbreviation, command, mapping, match, option they installed.
To install your buffer-local abbreviation via your autocmd, you can:
- reload the buffer by executing
:e
- reassign the value of the
'filetype'
option by executing :let &ft=&ft
- apply your autocmd manually by executing
:doautocmd outputs filetype
Additonal troubleshooting: if I run :abbreviate on an existing file it shows the older version of the abbreviation. However, doing :abclear or :unabbreviate sout does not remove the entry on :abbreviate
:abclear
, and :unabbreviate
, will remove global abbreviations.
If you want to remove the buffer-local ones instead, you should use the <buffer>
argument:
" remove all buffer-local abbreviations
:abclear <buffer>
" remove all buffer-local abbreviations in insert mode only (but not in command-line mode)
:iabclear <buffer>
" remove all the 'sout' buffer-local abbreviations
:unabbreviate <buffer> sout
" remove the 'sout' buffer-local abbreviation in insert mode only
:iunabbrev <buffer> sout
If you don't want the rhs of your abbreviation to be affected by mappings, use the non-recursive version of :iabbrev
, i.e. :inoreabbrev
.
In the abbreviations table printed by :abbreviate
, you can check whether an abbreviation is local to a buffer and whether its rhs can be remapped by looking at the symbol(s) between the lhs and rhs.
If you can read @
, it means the abbreviation is local to the buffer.
If you can read *
, it means the rhs of the abbreviation can't be remapped.
You could also move your abbreviations in filetype plugins.
For javascript, you could use ~/.vim/after/ftplugin/javascript.vim
and for php ~/.vim/after/ftplugin/php.vim
.
In a filetype plugin, you don't need autocmds anymore, you can write your abbreviations directly:
inoreabbrev <buffer> sout echo "";
inoreabbrev <buffer> sout console.log();<esc>hi
Also, it would allow you to make Vim remove the abbreviations automatically if you changed the filetype of your buffer.
To do that, you would need to include a command such as :iunabbrev
in b:undo_ftplugin
(see :h undo_ftplugin
):
let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')
\ .(empty(get(b:, 'undo_ftplugin', '')) ? '' : '|')
\ ."
\ exe 'iuna <buffer> sout'
\ | exe 'iuna <buffer> ...'
\ | ...
\ "