Frage

I code CSS and Python and for CSS I have the following little time saver

inoremap :      :;<Left>

This is great until I start coding in Python. Every time I hit : I get an unwanted ; I should mention that to make editing in Python pleasant with proper indentation I added

~/.vim/ftplugin/python.vim

python.vim contains the following

setlocal tabstop=4
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal textwidth=80
setlocal smarttab
setlocal expandtab  

What code would I put into python.vim to override inoremap : :;<Left> from my .vimrc so that when I press : all I get is a single :?

War es hilfreich?

Lösung 2

You can put this in your python.vim:
   iunmap :

As mentioned by Daan, you can also put the mapping for : in css specific vim file ( for example ~/.vim/syntax/css.vim )

Andere Tipps

All your filetype-specific settings should go into:

~/.vim/after/ftplugin/<language>.vim

With this setup, your settings are "guaranteed" to be applied, cleanly, after any default ftplugin.

Put your Python-specific settings:

setlocal tabstop=4
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal textwidth=80
setlocal smarttab
setlocal expandtab

into this file:

~/.vim/after/ftplugin/python.vim

and your CSS-specific mapping:

inoremap <buffer> : :;<Left>

into this file:

~/.vim/after/ftplugin/css.vim

You can do this with autocommands in your .vimrc

autocmd FileType css inoremap <silent> <buffer> : :;<Left>

This will only take effect when editing a file Vim knows is CSS (:set ft? gives you back CSS)

If you're new to autocommands, the Vim docs on autocommands are a recommended read.

You should check out :help map-local.

You could put this in python.vim:

iunmap <buffer> :

Or alternatively, only put the : mapping in css.vim:

inoremap <buffer> : :;<Left>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top