There's no native mapping command that creates the same mapping in both Normal and Insert modes.
That's perfectly understandable, since the expansion of a Normal-mode mapping will be executed in Normal-mode (interpreted as Normal-mode commands), while an Insert-mode mapping will be expanded in Insert-mode, inserted into the buffer. So it's quite rare that the same mapping will work on both Normal and Insert modes...
There's :map
or :noremap
that will create a mapping for both Normal, Visual and also Select and Operator-pending modes, so that can take care of it for you.
See :help map-modes
for the list of all available mapping modes.
So, assuming you're ok with also covering Operator-pending mode while disabling arrow keys, you could bring this down to only two blocks, one with :noremap
and one with :inoremap
, reducing this snippet from 12 to 8 lines total.
(There's also :map!
and noremap!
which cover Insert and Command-line modes, in case you're interested in disabling these in Command-line too.)
If you really want to do it in a single line, you could do that by defining a function:
function! Map(lhs, rhs, modes)
for m in a:modes
execute m.'noremap' a:lhs a:rhs
endfor
endfunction
And then you could use it as:
call Map('<left>', '<nop>', ['n', 'i', 'v'])
call Map('<down>', '<nop>', ['n', 'i', 'v'])
call Map('<up>', '<nop>', ['n', 'i', 'v'])
call Map('<right>', '<nop>', ['n', 'i', 'v'])
But, since writing the function took you 5 lines, and the mappings are much more harder to read or understand, this is probably not worth it...
noremap
considers Visual and Normal. I see no way consider Visual, Normal and Insert all in one command in:h map-modes
.visual
tag. The tag for visual mode is ... visual-mode. Similarly for the other modes.<nop>
cannot be remapped, simply:map
and:imap
will work okay. However, I feel obliged to add, that the whole idea of remapping cursor keys is a sort of "Vixtremism".