vim:filetype插件冲突 [英] vim:filetype plugin conflict

查看:152
本文介绍了vim:filetype插件冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要同时做python和js程序.

I need to do python and js program at the same time.

而且,我在〜/.vim/after/ftplugin/目录中有一些特定于语言的现象

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:

在python.vim中

In python.vim

    set tabstop=4
    set shiftwidth=4
    set expandtab
    set softtabstop=4
    nnoremap Y :Autoformat<CR>

在我的javascript.vim

In my javascript.vim

    nnoremap Y :call JsBeautify()<CR>

想象一下这个风景:

  • 使用vim打开python文件
  • 然后使用:split
  • 在新窗口中打开js文件
  • 现在,每当我按 Y
  • 即使我正在编辑python文件,Vim也会调用JsBeautify
  • Open a python file using vim
  • Then open a js file in a new windown using :split
  • Now whenever I press Y
  • Vim will call JsBeautify even if I'm editing the python file

那不是我想要的

现在我想知道是否有一种方法可以使vim像这样工作:

Now I'm wondering if there is a way to make vim work like this:

  • 判断当前窗口的文件类型
  • 并根据〜/.vim/after/ftplugin/目录中的文件类型来获取特定的* .vim文件
  • 然后在上述风景中
  • 当我编辑python文件时它将调用Autoformat,而当我编辑js文件时将调用JsBeautify(). 〜
  • Judge the filetype of the current window
  • And source the specific *.vim file in accordance with the filetype from the ~/.vim/after/ftplugin/ directory
  • Then in the above-mentioned scenery
  • It will call Autoformat when I am editing the python file and JsBeautify() when I am editing the js file
    ~

推荐答案

您必须将选项和映射尽可能地设置为 local .

You must make your options and mappings as local as possible.

~/.vim/after/ftplugin/python.vim中:

setlocal tabstop=4
setlocal shiftwidth=4
setlocal expandtab
setlocal softtabstop=4
nnoremap <buffer> Y :Autoformat<CR>

~/.vim/after/ftplugin/javascript.vim中:

nnoremap <buffer> Y :call JsBeautify()<CR>

FDinoff在评论中写道:

As FDinoff wrote in his comment:

:help :setlocal
:help :map-local

这篇关于vim:filetype插件冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆