在.vue文件中img标签使用autofilename提示引入文件时,会在文件后面插入宽度高度,如下图:

文件后面会自动插入height和width,其实这两玩意儿在大多数时候并没卵用,然后就开始了百度之旅...

一番百度,github之后,并没有找到自己想要的答案,github上说可以配置afn_insert_dimensions,afn_insert_width_first。参考github github

实际实验之后发现被坑得很惨,这两货怎么改变好像都没啥卵用。然后想到了修改插件源码...(本人不懂Python,所以未去查看为啥修改配置不生效的问题)

操作步骤:

1. 首选项>浏览插件目录,在该目录新建文件夹"AutoFileName"(与插件文件一致),

2. 选择当前目录上一级(Sublime Text 3)>Installed Packages找到"AutoFileName.sublime-package",复制一份该文件到任意目录,修改文件后缀为.zip,用软件解压。

3.找到解压目录中"autofilename.py",复制一份到第一步新建的目录AutoFileName中。

4.修改复制的autofilename.py(左侧是源码,右侧是修改之后)

修改之后完整代码:

 import sublime
import sublime_plugin
import os
from .getimageinfo import getImageInfo class AfnShowFilenames(sublime_plugin.TextCommand):
def run(self, edit):
FileNameComplete.is_active = True
self.view.run_command('auto_complete',
{'disable_auto_insert': True,
'next_completion_if_showing': False}) class AfnSettingsPanel(sublime_plugin.WindowCommand):
def run(self):
use_pr = '✗ Stop using project root' if self.get_setting('afn_use_project_root') else '✓ Use Project Root'
use_dim = '✗ Disable HTML Image Dimension insertion' if self.get_setting('afn_insert_dimensions') else '✓ Auto-insert Image Dimensions in HTML'
p_root = self.get_setting('afn_proj_root') menu = [
[use_pr, p_root],
[use_dim, '<img src="_path_" width = "x" height = "y" >']
]
self.window.show_quick_panel(menu, self.on_done) def on_done(self, value):
settings = sublime.load_settings('autofilename.sublime-settings')
if value == 0:
use_pr = settings.get('afn_use_project_root')
settings.set('afn_use_project_root', not use_pr)
if value == 1:
use_dim = settings.get('afn_use_project_root')
settings.set('afn_use_project_root', not use_dim) def get_setting(self,string,view=None):
if view and view.settings().get(string):
return view.settings().get(string)
else:
return sublime.load_settings('autofilename.sublime-settings').get(string) # Used to remove the / or \ when autocompleting a Windows drive (eg. /C:/path)
class AfnDeletePrefixedSlash(sublime_plugin.TextCommand):
def run(self, edit):
sel = self.view.sel()[0].a
reg = sublime.Region(sel-4,sel-3)
self.view.erase(edit, reg) # inserts width and height dimensions into img tags. HTML only
class InsertDimensionsCommand(sublime_plugin.TextCommand):
this_dir = '' def insert_dimension(self,edit,dim,name,tag_scope):
view = self.view
sel = view.sel()[0].a if name in view.substr(tag_scope):
reg = view.find('(?<='+name+'\=)\s*\"\d{1,5}', tag_scope.a)
view.replace(edit, reg, '"'+str(dim))
else:
dimension = str(dim)
view.insert(edit, sel+1, ' '+name+'="'+dimension+'"') def get_setting(self,string,view=None):
if view and view.settings().get(string):
return view.settings().get(string)
else:
return sublime.load_settings('autofilename.sublime-settings').get(string) def insert_dimensions(self, edit, scope, w, h):
view = self.view if self.get_setting('afn_insert_width_first',view):
self.insert_dimension(edit,h,'height', scope)
self.insert_dimension(edit,w,'width', scope)
else:
self.insert_dimension(edit,w,'width', scope)
self.insert_dimension(edit,h,'height', scope) # determines if there is a template tag in a given region. supports HTML and template languages.
def img_tag_in_region(self, region):
view = self.view # handle template languages but template languages like slim may also contain HTML so
# we do a check for that as well
return view.substr(region).strip().startswith('img') | ('<img' in view.substr(region)) def run(self, edit):
view = self.view
view.run_command("commit_completion")
sel = view.sel()[0].a if not 'html' in view.scope_name(sel): return
scope = view.extract_scope(sel-1) # if using a template language, the scope is set to the current line
tag_scope = view.line(sel) if self.get_setting('afn_template_languages',view) else view.extract_scope(scope.a-1) path = view.substr(scope)
if path.startswith(("'","\"","(")):
path = path[1:-1] path = path[path.rfind(FileNameComplete.sep):] if FileNameComplete.sep in path else path
full_path = self.this_dir + path if self.img_tag_in_region(tag_scope) and path.endswith(('.png','.jpg','.jpeg','.gif')):
with open(full_path,'rb') as r:
read_data = r.read() if path.endswith(('.jpg','.jpeg')) else r.read(24)
w, h = getImageInfo(read_data) self.insert_dimensions(edit, tag_scope) # When backspacing through a path, selects the previous path component
class ReloadAutoCompleteCommand(sublime_plugin.TextCommand):
def run(self,edit):
view = self.view
view.run_command('hide_auto_complete')
view.run_command('left_delete')
sel = view.sel()[0].a scope = view.extract_scope(sel-1)
scope_text = view.substr(scope)
slash_pos = scope_text[:sel - scope.a].rfind(FileNameComplete.sep)
slash_pos += 1 if slash_pos < 0 else 0 region = sublime.Region(scope.a+slash_pos+1,sel)
view.sel().add(region) class FileNameComplete(sublime_plugin.EventListener):
def on_activated(self,view):
self.showing_win_drives = False
FileNameComplete.is_active = False
FileNameComplete.sep = '/' def get_drives(self):
# Search through valid drive names and see if they exist. (stolen from Facelessuser)
return [[d+":"+FileNameComplete.sep, d+":"+FileNameComplete.sep] for d in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" if os.path.exists(d + ":")] def on_query_context(self, view, key, operator, operand, match_all):
if key == "afn_insert_dimensions":
return self.get_setting('afn_insert_dimensions',view) == operand
if key == "afn_deleting_slash": # for reloading autocomplete
sel = view.sel()[0]
valid = self.at_path_end(view) and sel.empty() and view.substr(sel.a-1) == FileNameComplete.sep
return valid == operand
if key == "afn_use_keybinding":
return self.get_setting('afn_use_keybinding',view) == operand def at_path_end(self,view):
sel = view.sel()[0]
name = view.scope_name(sel.a)
if sel.empty() and 'string.end' in name:
return True
if '.css' in name and view.substr(sel.a) == ')':
return True
return False def on_modified(self, view):
sel = view.sel()[0].a
txt = view.substr(sublime.Region(sel-4,sel-3))
if (self.showing_win_drives and txt == FileNameComplete.sep):
self.showing_win_drives = False
view.run_command('afn_delete_prefixed_slash') def on_selection_modified_async(self,view):
if not view.window():
return
sel = view.sel()[0]
if sel.empty() and self.at_path_end(view):
scope_contents = view.substr(view.extract_scope(sel.a-1))
p = scope_contents.replace('\r\n', '\n').split('\n')[0]
if('\\' in p and not '/' in p):
FileNameComplete.sep = '\\'
else:
FileNameComplete.sep = '/'
if view.substr(sel.a-1) == FileNameComplete.sep or len(view.extract_scope(sel.a)) < 3:
view.run_command('auto_complete',
{'disable_auto_insert': True,
'next_completion_if_showing': False})
else:
FileNameComplete.is_active = False def fix_dir(self,sdir,fn):
if fn.endswith(('.png','.jpg','.jpeg','.gif')):
path = os.path.join(sdir, fn)
with open(path,'rb') as r:
read_data = r.read() if path.endswith(('.jpg','.jpeg')) else r.read(24)
w, h = getImageInfo(read_data)
return fn+'\t'+'w:'+ str(w) +" h:" + str(h)
return fn def get_cur_path(self,view,sel):
scope_contents = view.substr(view.extract_scope(sel-1)).strip()
cur_path = scope_contents.replace('\r\n', '\n').split('\n')[0]
if cur_path.startswith(("'","\"","(")):
cur_path = cur_path[1:-1] return cur_path[:cur_path.rfind(FileNameComplete.sep)+1] if FileNameComplete.sep in cur_path else '' def get_setting(self,string,view=None):
if view and view.settings().get(string):
return view.settings().get(string)
else:
return sublime.load_settings('autofilename.sublime-settings').get(string) def on_query_completions(self, view, prefix, locations):
is_proj_rel = self.get_setting('afn_use_project_root',view)
valid_scopes = self.get_setting('afn_valid_scopes',view)
blacklist = self.get_setting('afn_blacklist_scopes', view)
uses_keybinding = self.get_setting('afn_use_keybinding', view) sel = view.sel()[0].a
this_dir = ""
completions = [] if uses_keybinding and not FileNameComplete.is_active:
return
if not any(s in view.scope_name(sel) for s in valid_scopes):
return
if any(s in view.scope_name(sel) for s in blacklist):
return cur_path = os.path.expanduser(self.get_cur_path(view, sel)) if cur_path.startswith('/') or cur_path.startswith('\\'):
if is_proj_rel:
proot = self.get_setting('afn_proj_root', view)
if proot:
if not view.file_name() and not os.path.isabs(proot):
proot = "/"
cur_path = os.path.join(proot, cur_path[1:])
else:
for f in sublime.active_window().folders():
if f in view.file_name():
cur_path = f
elif not view.file_name():
return
else:
this_dir = os.path.split(view.file_name())[0]
this_dir = os.path.join(this_dir, cur_path) try:
if sublime.platform() == "windows" and len(view.extract_scope(sel)) < 4 and os.path.isabs(cur_path):
self.showing_win_drives = True
return self.get_drives()
self.showing_win_drives = False
dir_files = os.listdir(this_dir) for d in dir_files:
if d.startswith('.'): continue
if not '.' in d: d += FileNameComplete.sep
completions.append((self.fix_dir(this_dir,d), d))
if completions:
InsertDimensionsCommand.this_dir = this_dir
return completions
return
except OSError:
print("AutoFileName: could not find " + this_dir)
return

注意:修改这里代码之后,将在所有文件里面都不会再插入宽度高度!!!

sublime text 3插件改造之AutoFileName去掉.vue文件中img标签后面的width和height,完全去掉!!的更多相关文章

  1. sublime text 3插件改造之添加从模版新增文件到指定目录

    简介:以前使用ST2里面的Sublime NFFT插件比较顺手,最近安装了ST3,但是Sublime NFFT插件不支持ST3,就下载了SublimeTmpl从模版新建文件插件.在使用时,习惯在侧边栏 ...

  2. 推荐!Sublime Text 最佳插件列表

    本文由 伯乐在线 - 艾凌风 翻译,黄利民 校稿.英文出处:ipestov.com.欢迎加入翻译组. 本文收录了作者辛苦收集的Sublime Text最佳插件,很全. 最佳的Sublime Text ...

  3. Sublime Text 3 插件、主题、配置

    换电脑,Sublime Text 3 重新配置一遍,做个记录 1. 下载:http://www.sublimetext.com/3 2. 插件管理器 Package Control (Ctrl + ` ...

  4. Sublime Text 最佳插件列表

    http://blog.jobbole.com/79326/ 推荐!Sublime Text 最佳插件列表 2014/07/25 · 工具与资源 · 26.1K 阅读 · 2 评论 · Sublime ...

  5. 开发者常用的 Sublime Text 3 插件

    1.官网下载 Sublime Text 3 (已有安装包的,请忽略) Sublime Text 官网下载地址 : http://www.sublimetext.com/ 2.打开 Sublime Te ...

  6. Sublime Text通过插件编译Sass为CSS及中文编译异常解决

    虽然PostCSS才是未来,但是Sass成熟稳定,拥有一大波忠实的使用者,及开源项目,且最近Bootstrap 4 alpha也从Less转到Sass了.所以了解Sass还是非常有必要的. 基于快速开 ...

  7. 开发者最常用的 8 款 Sublime Text 3 插件

    转载于:http://www.itxuexiwang.com/a/liunxjishu/2016/0228/177.html?1456925631Sublime Text作为一个尽为人知的代码编辑器, ...

  8. 安装Sublime Text 3插件的方法

    直接安装 安装Sublime text 3插件很方便,可以直接下载安装包解压缩到Packages目录(菜单->preferences->packages). 使用Package Contr ...

  9. Sublime Text 3 插件安装及Vim 模式设置

    1.安装Sublime Text 3  下载安装:http://www.sublimetext.com/3 Package Control安装:https://sublime.wbond.net/in ...

随机推荐

  1. Unity - 绘制正五边形网格

    本文简述了Unity中绘制正五边形网格的基本方法:计算顶点信息.设置三角形覆盖信息.创建配置mesh 绘制方法 基本思路:计算出五边形顶点坐标信息作为数组,设置三角形包围方式,再创建新的mesh配置v ...

  2. timeout超时时长优化和hystrix dashboard可视化分布式系统

    在生产环境中部署一个短路器,一开始需要将一些关键配置设置的大一些,比如timeout超时时长,线程池大小,或信号量容量 然后逐渐优化这些配置,直到在一个生产系统中运作良好 (1)一开始先不要设置tim ...

  3. 阿里巴巴 Java 开发手册 (十)MySQL 数据库

    (一) 建表规约 1. [强制]表达是与否概念的字段,必须使用 is_xxx 的方式命名,数据类型是 unsigned tinyint ( 1 表示是,0 表示否). 说明:任何字段如果为非负数,必须 ...

  4. 【开发工具】- myeclipse安装主题

    你想用IDEA那样炫酷的符合90后气质的主题吗?废话不多说,按照下边步骤就可以安装像IDEA一样超级炫酷的主题. 下载主题 1.进入插件官网(http://eclipsecolorthemes.org ...

  5. 如何搭建java web的开发环境,以及mysql的安装过程

    1 http协议响应 http响应由三部分组成: 状态行: 响应报头: 响应正文: 1 下载JDK,安装并配置环境变量 2 配置环境变量的步骤: 在系统变量栏中单击新建按钮,新建变量JAVA_HOME ...

  6. 物料管理混乱怎么办?APS系统帮你实现高效运输

    APS系统可以高效地管理.控制分销中心并保证产品可订货.可盈利.能力可用.分销计划帮助企业分析原始信息,然后企业能够确定如何优化分销成本或者根据生产能力和成本提高客户服务水平. 今天成功的企业为了取得 ...

  7. POSIX 使用互斥量和条件变量实现生产者/消费者问题

    boost的mutex,condition_variable非常好用.但是在Linux上,boost实际上做的是对pthread_mutex_t 和pthread_cond_t的一系列的封装.因此通过 ...

  8. docker复制文件到宿主机

    从主机复制到容器 sudo docker cp host_path containerID:container_path 从容器复制到主机 sudo docker cp containerID:con ...

  9. C 语言快速入门,21 个小项目足矣!「不走弯路就是捷径」

    C 语言作为大学理工科专业的必修,是很多同学走进编程世界的第一课.那么怎样才能更好的入门 C 语言呢? 下面整理了 21 个 C 语言练手项目,从基础语法开始,逐步深入,通过一个个练手项目,让你轻松驰 ...

  10. centos7修改IP地址(静态)

    环境如下: 操作系统: CentOS-7-x86_64-DVD-1908.iso 步骤如下: 1. 查看网卡信息 ip a 2.编辑对应网卡的配置文件,我这里网卡是ens33,所以我修改的是文件  i ...