Reputation: 365
I need to do python and js program at the same time.
And also, I have some language specific seetings located at the ~/.vim/after/ftplugin/ directory
Here I'll show you the content of these files:
In python.vim
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4
nnoremap Y :Autoformat<CR>
In my javascript.vim
nnoremap Y :call JsBeautify()<CR>
Imagine this scenery:
:split
JsBeautify
even if I'm editing the python fileThat's not what I want
Now I'm wondering if there is a way to make vim work like this:
Autoformat
when I am editing the python file and JsBeautify()
when I am editing the js fileUpvotes: 0
Views: 132
Reputation: 196546
You must make your options and mappings as local as possible.
In ~/.vim/after/ftplugin/python.vim
:
setlocal tabstop=4
setlocal shiftwidth=4
setlocal expandtab
setlocal softtabstop=4
nnoremap <buffer> Y :Autoformat<CR>
In ~/.vim/after/ftplugin/javascript.vim
:
nnoremap <buffer> Y :call JsBeautify()<CR>
As FDinoff wrote in his comment:
:help :setlocal
:help :map-local
Upvotes: 3