简体   繁体   English

使用Vim掌握CSS和XHTML

[英]Mastering CSS and XHTML with Vim

Please point me to some guides on how to master (X)HTML, CSS with Vim. 请指点我们如何使用Vim掌握(X)HTML,CSS。 I preffer to create web pages by hands and I decided to go with Vim. 我喜欢用手创建网页,我决定和Vim一起去。

Any useful plugins, tips & tricks, tutorials, how-tos, books, articles? 任何有用的插件,提示和技巧,教程,how-tos,书籍,文章?

Thanks! 谢谢!

You'll "master (X)HTML, CSS with Vim" the same way you'd do with any other text editor or language: by working hard, reading books, watching screencasts and keeping up with the news. 你将“使用Vim掌握(X)HTML,CSS”,就像你使用任何其他文本编辑器或语言一样:通过努力工作,阅读书籍,观看截屏视频和跟上新闻。 The editor you choose is totally irrelevant. 您选择的编辑器完全无关紧要。

That said, here are a few native features and plugins that helped me a lot: 也就是说,这里有一些本机功能和插件帮助了我很多:

  • Omnicompletion is Vim's own autocompletion-like feature, except that it's not automatic. Omnicompletion是Vim自己的自动完成功能,除了它不是自动的。

    Hit ctrl p or ctrl n to complete with a word contained elsewhere in your document. 点击ctrl pctrl n以完成文档中其他位置的单词。

    Hit ctrl x ctrl o to display a list of possible completions based on the language. ctrl x ctrl o显示基于语言的可能完成列表。

    BEGIN EDIT 开始编辑

    Another very very useful feature is "file-path completion", start typing the path to a file and hit <Cx><Cf> to display a menu with possible completions. 另一个非常有用的功能是“文件路径完成”,开始键入文件的路径并点击<Cx><Cf>以显示可能完成的菜单。

    Also, the aforementioned features can be automated with plugins, the one I use is AutoComplPop . 此外,上述功能可以使用插件自动化,我使用的是AutoComplPop

    END EDIT 结束编辑

  • Objects allow you to move, select and perform actions on your code in crazy cool ways. 对象允许您以疯狂的方式移动,选择和执行代码操作。

    Say you have <div>word</div> with the cursor on o , d i t will delete word , c i t will delete word and place the cursor between the tags for further editing and so on… 假设你有<div>word</div>把光标放在o ,D I T将删除word ,C I T将删除word ,并将进行进一步的编辑等标签之间的光标...

    If you know what d , c or v mean, that i roughly means inside and a roughly means around and that t means tag you already have a very powerful tool, there. 如果你知道什么是dcv的意思是, i大概的意思是insidea大概的意思是aroundt意味着tag ,你已经有一个非常强大的工具,有。 Vim has other objects very useful for code editing: " , ' , ( , [ , { etc, type :help objects for more. Vim有其他对象对代码编辑非常有用: "'([{ etc,type :help objects for more。

    For me, this feature alone was enough to justify scraping TextMate. 对我来说,仅此功能足以证明抓取TextMate是合理的。

  • Blockwise Selection does what it says. Blockwise Selection完成了它的说法。 :help blockwise-visual for more info. :help blockwise-visual获取更多信息。

  • :normalize or :norm is also very useful to prepend or append something to a group of lines. :normalize:norm对于在一组行之前添加或附加内容也非常有用。

  • SnipMate is a plugin inspired by TextMate's snippets system. SnipMate是一个受TextMate的片段系统启发的插件。 You type form then hit tab to expand to a complete boilerplate <form> element in which you can move by further hitting tab to edit values and attributes. 您键入form然后单击选项卡以展开到一个完整的样板<form>元素,您可以通过进一步按Tab键来编辑值和属性。

  • Surround takes the objects business to another level by making it possible to add tag pairs around your selection, deleting them or changing them. Surround通过在选择周围添加标记对,删除标记对或更改标记对,将对象业务提升到另一个级别。

    If you take the example above, hit c s t <p> to change it in a more correct <p>word</p> . 如果您采用上面的示例,请点击c s t <p>以更正确的<p>word</p>更改它。 To add a pair of tags to word , select it with v then hit S and type the tag you want. 要为word添加一对标签,请使用v选择它,然后按S并键入所需的标签。

Sparkup is a pretty awesome plugin. Sparkup是一个非常棒的插件。 Besides that, I normally use both snipMate and delimitMate , though those are useful for coding in any language. 除此之外,我通常使用snipMatedelimitMate ,尽管这些对于任何语言的编码都很有用。

tl;dr; TL;博士; install this vim setup https://github.com/jameslai/jvim 安装此vim安装程序https://github.com/jameslai/jvim

James Lai wrote an amazing article on Frontend Vim which was 404'ing when I answered this. James Lai写了一篇关于Frontend Vim的惊人文章,当我回答这个问题时,这篇文章是404'。 It has helped me switch from ST2 to VIM so I'm posting it here. 它帮助我从ST2切换到VIM,所以我在这里发布。


Why I Use VIM as My Editor of Choice for Front End Development 为什么我使用VIM作为前端开发的首选编辑

by James Lai 詹姆斯赖

I've been using VIM for years, and I just can't get away from it. 我已经使用VIM多年了,我无法摆脱它。 While many people like to use Sublime Text 2, and I can't help but absolutely encourage that, if you'd like to use an editor that can scale with your knowledge, VIM should be your editor of choice. 虽然许多人喜欢使用Sublime Text 2,但我不禁鼓励,如果您想使用可以随着您的知识扩展的编辑器,VIM应该是您的首选编辑。

Easily edit content within tags 轻松编辑标签内的内容

As FED's, we're constantly editing content within tags. 作为FED,我们不断编辑标签内的内容。 VIM makes this easy with its “tag” text object - t. VIM通过其“标签”文本对象使这很简单 - t。 Here's a common scenario, you have source code that looks like: 这是一个常见的场景,您的源代码如下所示:

<div>Some content within here</div>

In VIM, to replace the content within that tag, you merely need to press cit. 在VIM中,要替换该标记内的内容,您只需要按cit。 This will change the inner tag and you'll be left with this: 这将改变内部标记,你将留下这个:

<div></div>

Easily replace HTML attributes 轻松替换HTML属性

Similar to the above, we deal with content within quotes all the time, often as attributes within our HTML. 与上面类似,我们一直处理引号内的内容,通常作为HTML中的属性。 You may have something that looks like: 您可能会看到以下内容:

<aside class="one-third author box">

In this scenario, just hit ci". Perhaps the neatest part about this trick, if this was the only content on that line, you don't even need your cursor anywhere near the quote itself! VIM is intelligent enough to simply empty out the content of the quote regardless of its position in the line, and you'll be left with: 在这种情况下,只需点击ci“。也许是关于这个技巧的最新部分,如果这是该行上唯一的内容,你甚至不需要你的光标靠近引号本身!VIM足够聪明,可以简单地清空报价的内容,无论其在该行中的位置如何,您将留下:

<aside class="">

Jump back and fourth between where you've edited 在您编辑的位置之间跳回和第四

As FEDs, we are constantly jumping back and fourth between places we've previously edited. 作为美联储,我们不断跳回到我们之前编辑的地方之间的第四位。 VIM maintains a “jump list” which is easily navigated by Ctr+O (jumping to previous locations) and Ctr+I (forward). VIM维护一个“跳转列表”,可以通过Ctr + O(跳转到以前的位置)和Ctr + I(转发)轻松导航。 This makes our routine of editing many files simultaneously incredibly painless. 这使我们同时编辑许多文件的例程非常轻松。

More information on jumps 有关跳跃的更多信息

On a mac? 在Mac上? In VIM, you've got a proper delete key again 在VIM中,您再次获得了正确的删除密钥

Mac keyboards don't come with a normal “delete” key - we essentially have a backspace key but it's labelled delete. Mac键盘没有正常的“删除”键 - 我们基本上有一个退格键,但它标记为删除。 Sure, you could reach for funcdelete, but that function key is sure out the the way. 当然,你可以找到funcdelete,但是这个功能键肯定是顺便提一下。 Instead, hit x! 相反,点击x!

Move CSS like a master 像主人一样移动CSS

Often I'll need to refactor some CSS and move properties between selectors. 通常我需要重构一些CSS并在选择器之间移动属性。 With VIM, I can move content from various lines to my cursor position with a simple: 使用VIM,我可以通过简单的方式将内容从各行移动到我的光标位置:

:<linenumber>,<linenumber>m

Common operations like these are made laughably easy with VIM. 使用VIM可以轻松实现这些常见操作。

Jump to the end or beginning of a line 跳到行的结尾或开头

This is unusually common in my workflow - needing to jump to the end of a line. 这在我的工作流程中非常常见 - 需要跳到一行的末尾。 Perhaps I forgot a semicolon at the end of a CSS property or line of Javascript. 也许我在CSS属性或Javascript行的末尾忘记了一个分号。 To jump to the end of the line, simply hit A and you're in insert mode at the end of the line. 要跳到该行的末尾,只需点击A,您就会在该行的末尾处于插入模式。 Need to edit at the beginning (not counting tabbing)? 需要在开头编辑(不计入标签)? Use I. 使用I.

Edit at the speed of thought 以思想的速度编辑

One of the staple concepts of VIM is to prevent needing to reach for your mouse. VIM的主要概念之一是防止需要触及鼠标。 When I'm in my flow, I never reach for the mouse unless its to interact with a web page I'm working on. 当我在我的流程中时,除非它与我正在处理的网页进行交互,否则我永远不会触及鼠标。 Getting good at VIM means your ability to edit and manipulate text nearly approaches how fast you can think of the problem. 熟悉VIM意味着您编辑和操作文本的能力几乎接近您能够多快地思考问题。 Because of the concept of text objects, thinking “I want to delete this line” becomes a trivial dd, or deleting a word with daw. 由于文本对象的概念,思考“我想删除这一行”变成了一个微不足道的dd,或用daw删除一个单词。 As you think about the problem, you more often then not have a easy command to describe to the editor. 当您考虑问题时,您通常不会轻易地向编辑器描述。 The ability to get into your flow with VIM is, in my opinion, higher than most other editors. 在我看来,使用VIM进入流程的能力比大多数其他编辑更高。

Easy split windows 轻松拆分窗户

Something that completely changed how I developed was learning how to really leverage split windows in VIM. 完全改变我开发方式的东西是学习如何在VIM中真正利用分割窗口。 Yes, VIM has split windows, and they're amazing! 是的,VIM已拆分窗户,它们太棒了! Some editors come with this functionality, but it can be cumbersome to use, or difficult to remember to use. 有些编辑器具有此功能,但使用起来很麻烦,或者难以记住使用。

Spits are powerful because we're often addressing the same item in a number of places. 吐痰是强大的,因为我们经常在许多地方处理相同的项目。 If you're addressing an element, you'll often want the HTML file up. 如果您正在寻址元素,那么您通常会想要HTML文件。 If you're applying styling to it, you'll want the CSS up, and if you're applying behaviors, you'll want the Javascript up as well. 如果你正在应用样式,你会想要CSS,如果你正在应用行为,你也会想要Javascript。 Seeing them all at the same time has saved me literally countless headaches in editing. 同时看到它们在编辑中给我带来了无数令人头痛的问题。 The flow feels very “natural”, not to mention just how awesome your editor will look. 流程感觉非常“自然”,更不用说你的编辑器看起来多么棒了。 Often I'll have at least 4 splits going at any one time. 通常,我任何时候都会至少有4次分裂。

A great way to get started is by typing :Vex. 一个很好的入门方式是键入:Vex。 This opens a Vertical exploration window. 这将打开一个垂直探索窗口。 From here you can browse to whatever file you want to, and that file will appear in the split. 从这里,您可以浏览到您想要的任何文件,该文件将显示在拆分中。 There's also the always salacious :Sex command, which will open a horizontal split explorer window. 还有总是色情的:性别命令,它将打开一个水平分裂的浏览器窗口。

Vertical Split Windows 垂直分割窗口

More information on splits 有关拆分的更多信息

More information on the file explorer 有关文件资源管理器的更多信息

Your setup, anywhere 你的设置,任何地方

Perhaps one of the most compelling features is the ability to have your customized setup very quickly. 也许最引人注目的功能之一就是能够非常快速地进行自定义设置。 I keep my VIM configuration in a GitHub repo , meaning regardless of what machine I'm on, I'm about 2 commands away from having my complete setup ready to go. 我将我的VIM配置保存在GitHub仓库中 ,这意味着无论我使用的是哪台机器,我都要完成两个命令。

…even on remote machines ......甚至在远程机器上

Front end developers will inevitably work on a remote server at some point. 前端开发人员在某些时候将不可避免地在远程服务器上工作。 Heck, many of us have local linux boxes in a VM replicating our server environments. 哎呀,我们中的许多人都在VM中复制我们的服务器环境。 You're going to need an editor, and rather than either fumble around in VIM due to not knowing how to actually make it dance, or using a basic and underpowered editor like nano, getting good at VIM client-side means you're going to be a master server-side. 你需要一个编辑器,而不是因为不知道如何实际跳舞而在VIM中摸索,或者使用像nano这样的基本和动力不足的编辑器,擅长VIM客户端意味着你要去成为主服务器端。

Final thoughts 最后的想法

VIM is an amazing editor, and although you may think it's old, it's actually more than up to the task for today's editing. VIM是一个了不起的编辑器,虽然你可能认为它已经过时了,但它实际上不仅仅是今天编辑的任务。 No matter what new editor hits the market, I may try them out to see what innovations are out there, but in the end, I always come back to VIM for all my editing, and I love it. 无论新编辑如何进入市场,我都可以尝试一下,看看有哪些创新,但最后,我总是回到VIM进行编辑,我喜欢它。

I do it that way. 我这样做。 I haven't found that much support for it, so I wrote a little of my own. 我没有找到那么多的支持,所以我写了一些自己的。 I keep it on Google code hosting . 我将它保留在Google代码托管上 I also use a version of Vim with Python embedded, and use some Python to extend some functionality. 我还使用嵌入了Python的Vim版本,并使用一些Python来扩展一些功能。 That's in the pycopia.vimlib package. 这是在pycopia.vimlib包中。

There is only a little, but hopefully useful stuff. 只有一点,但希望有用的东西。 You can start from there. 你可以从那里开始。

Emmet . 埃米特 Which was called zencoding a long time ago, is a nice plugin for several editors (including vim) with many features that enables you to code html and css very rapidly. 很久以前被称为zencoding,是一个很好的插件,适用于几个编辑器(包括vim),它们具有许多功能,使您能够非常快速地编写html和css代码。

For example, you can type div.some span.other<ctrl+y> ans you'll get: 例如,您可以键入div.some span.other<ctrl+y> ans,您将得到:

<div class="some>
   <span class="other>
      (cursor here) 
   </span>
</div>
  1. Install CSS3 syntax plugin . 安装CSS3语法插件
  2. Install HTML5 syntax plugin . 安装HTML5语法插件
  3. Install Syntastic syntax checker plugin . 安装Syntastic语法检查器插件
    1. You'll also have to install CSS Lint's CLI tool , since the syntax checker uses it. 您还必须安装CSS Lint的CLI工具 ,因为语法检查器使用它。

There are a lot more plugins related to general development, which you can find in several questions scattered around this website, but the ones above a specifically related to help writing better CSS & HTML. 有一些与常规开发相关的插件,你可以在这个网站上散布的几个问题中找到,但上面的那些专门用于帮助编写更好的CSS和HTML。

I use a lot zencoding, so, if you're used with zen-coding try the zenCoding plugin for Vim find it here 我使用了很多zencoding,所以,如果你使用zen-coding尝试使用zenCoding插件为Vim 在这里找到它

If you want to learn more about zen-coding you could read: zen coding vim tutorial 如果你想了解更多关于zen-coding的信息,你可以阅读: zen coding vim tutorial

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM