tags:

views:

265

answers:

5
+1  Q: 

vim mapping

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?

Thanks

+1  A: 

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)

soulmerge
A: 

G'day,

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.

HTH

cheers,

Rob Wells
+4  A: 

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).

Luc Hermitte
+1. Important points that make this answer better: mapping only defined for normal mode and use of "nore".
+1 agreed (15chars15chars15chars)
soulmerge
+2  A: 

Use ftplugins as Luc Hermitte said or add the following to your .vimrc

autocmd filetype java :nnoremap <buffer> ; A;<esc>
Maxim Kim
A: 

Put this in ~/.vim/after/ftplugin/java.vim

nnoremap <buffer> ; A;<Esc>

Now this mapping should be local to java buffers only

Sam

related questions