Reputation: 1807
I am trying to set up a vim key mapping that will map the key ';' to A; - i.e. I want to auto append ';' to the end of the line. However I am having difficulty in setting this mapping up. I would also like to limit this to only java files if possible.
Can this be done?
Upvotes: 2
Views: 1081
Reputation: 37133
As a quick implementation, what about:
map ; $a;cntl-vESC
then hit return
I'll have a think about enabling this for Java files only.
Upvotes: 0
Reputation: 15350
Put this in ~/.vim/after/ftplugin/java.vim
nnoremap <buffer> ; A;<Esc>
Now this mapping should be local to java buffers only
Upvotes: 0
Reputation: 6392
Use ftplugins as Luc Hermitte said or add the following to your .vimrc
autocmd filetype java :nnoremap <buffer> ; A;<esc>
Upvotes: 2
Reputation: 32966
If you want to restrict this feature to java buffers, have a look at ftplugins. The mapping then becomes:
nnoremap <buffer> ; A;<esc>
BTW, I would advise against mapping on ';
' as it's a very useful command that may be used in other badly defined mappings (too many vimmers are using :*map
instead of :*noremap
).
Upvotes: 4
Reputation: 75724
The mapping itself is done this way:
:map ; A;<esc>
I would recommend putting this line in your .vimrc and live with it (it should not bother you, since the mapping only works in command mode). If you really must restrict this behaviour to certain files, you need to look into the autocmd
function (:help autocmd
)
Upvotes: 1