使用 vim 进行 Ruby 编程(相对于 Notepad++)有哪些优点? (其他语言也是如此,但特别是 Ruby)

发布于 2024-09-06 17:04:14 字数 580 浏览 1 评论 0原文

我使用 Notepad++ 一段时间了;事实上,我什至开始使用 Launchy 来实现“立即将此资源加载到编辑器中”的功能,许多更完整的 IDE(例如 Eclipse)都具有该功能。它具有语法高亮、分割窗口视图、代码折叠、括号(和其他分隔符)配对、自动缩进、块注释。

然而,似乎无论我走到哪里,人们都在使用 vim 来满足他们的编程需求。

我了解 vim 的基础知识;当我在 Linux 机器上时,它是我主要的“基本文本编辑器”;我使用它就像使用 Windows 上的基本记事本一样。我得到了控制、大部分快捷方式、重复消除器等。

我不太理解的是人们所拥护的这些杀手级应用程序。 “在 vim 中调试 Ruby 是一次改变生活的体验”,或者说,使用它时,奇迹是如何发生的。

我是否缺少一些必要的插件?是否存在我没​​有看到的维度?我应该闭嘴并开始使用它看看吗?如何获得语法高亮显示?

我特别指定 Ruby,因为我想为它找到一些插件。请注意,我使用 Rails,答案应该与 Rails 无关。但我也希望了解一些有关其他语言编程的一般 vim 性公案。

谢谢,我希望我的问题不会太含糊,也不会引发任何令人讨厌的编辑之战。

I've been using Notepad++ for a while; in fact, I've even started using Launchy for that "load this resource into the editor right now" functionality that many fuller IDE's like Eclipse has. It has syntax highlighting, split window view, code collapsing, parentheses (and other delimiter) paring, automatic indent, block commenting.

However, it seems that everywhere I go, people are using vim for their programming needs.

I know the basics of vim; it's my main "basic text editor" when I'm on a linux machine; I use it like I'd use the basic Notepad on Windows. I get the controls, most of the shortcuts, the repetition eliminators, etc.

What I'm not quite understanding are these killer apps that people are espousing about. How "debugging Ruby in vim was a life-changing experience", or how, when using it, magic occurs.

Am I missing some essential plug-ins? Is there a dimension I'm not seeing? Should I just shut up and start using it for a bit, to see? How do I get syntax highlighting?

I'm specifying Ruby specifically because I'd like to find some plugins for it. Note that I am not using Rails, and answers should be rails-independent of possible. But I would appreciate some general vim-ness koans about programming in other languages, as well.

Thank you, and I hope my question isn't too vague or inspires any nasty editor wars.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

初见 2024-09-13 17:04:14

我所有的 Ruby 编程都使用 vim,我认为它的可定制性是它的杀手锏。如果您愿意花时间寻找能够实现您想要的功能的插件或自己编写一些脚本,那么使用 vim,您几乎可以完成您能想象到的所有文本操作。

我将列出一些我喜欢 vim 编程的东西(排名不分先后):

  • 语法突出显示

    Ruby 语法高亮非常好。有一件事似乎有些独特,那就是关键字可以根据上下文使用不同的颜色。这并没有像我希望的那样频繁使用,但您可以轻松查看 end 语句是否关闭(例如,if 语句或函数定义)。

    还有一个好处是,由于 vim 知道文本的哪些部分是注释,因此您只能对这些部分进行拼写检查。

  • 自动缩进。

    当你编写代码时,vim 会自动将光标置于正确的缩进级别,因此你不必担心这一点。我还发现自己通过选择一个块并按 = 来自动(重新)缩进我突出显示的所有内容来手动调用此功能。

  • 自动补全

    我使用自动弹出的插件 补全。这些非常通用。他们知道标准库中类的方法,查看您打开的其他文件(适合变量名和类方法),识别您何时键入文件名等。

  • 片段

    有一个名为 snipMate 的插件提供常用文本片段的快捷方式。这对于编写测试等有很大帮助。

  • 代码折叠

  • 脚本化

    正如我所说,vim 的脚本功能非常强大。想要自动删除行尾的无关空格吗?只需编写一行脚本即可。

  • 插件,插件,插件!

    有大量插件可以帮助您处理各种事情。 Git 集成、Rails 集成Rspec 集成, 自动关闭括号,匹配打开块的关键字 {def,do,if,while 等.} 到他们的结束...这个列表实际上是无穷无尽的。

I use vim for all my Ruby programming, and I think its customizability is its killer feature. With vim you can do just about everything to text you can imagine, if you're willing to invest the time to hunt down the plugins that do what you want or write a few scripts yourself.

I'll just list a few things I like about vim for programming (in no particular order):

  • Syntax Highlighting

    The ruby syntax highlighting is very nice. One thing in particular that seems to be somewhat unique is that keywords can be colored differently depending on context. This isn't used as much as I would like, but you can easily see whether that end statement closes, say, an if-statement or a function definition.

    Also nice is that, since vim knows which parts of the text are comments, you get spell checking for these only.

  • Automatic indenting.

    When you're writing code, vim will automatically place the cursor at the right indentation level, so you don't have to worry about that. I also find myself invoking this functionality manually by selecting a block and pressing = to automatically (re-)indent everything I highlighted.

  • Autocompletion

    I use a plugin that automatically pops up completions.These are very versatile. They know the methods of classes from the standard library, look at other files you have open (good for variable names and class methods), recognize when you're typing a filename, etc.

  • Snippets

    There is a plugin called snipMate that provides shortcuts for often used text snippets. It's a big help with writing tests and the like.

  • Code folding

  • Scriptability

    As I said, vim's scripting is very powerful. Want extraneous whitespace at the end of the line deleted automatically? Just write a one-line script.

  • Plugins, Plugins, Plugins!

    There are a ton of plugins that help you with all kinds of things. Git integration, Rails integration, Rspec integration, autoclosing parentheses, matching keywords that open a block {def,do,if,while, etc.} to their end... the list is practically endless.

木森分化 2024-09-13 17:04:14

它是一个开箱即用的非常强大的编辑器,它与版本控制很好地集成,并且有大量可用的优秀附加组件。 (参见脚本页面以及提示 wiki。)这些是考虑 Vim 的充分理由,但是还有很多其他优秀的编辑器可供使用各种平台。 (看,马,没有宗教编辑器战争!)

就 Ruby 特定的附加组件而言,请查看 endwise by Tim Pope。 (它会自动在 doif 等之后插入 end)实际上几乎所有 Tim Pope 的脚本 对 Rubyists 可能有用。

如何获得语法突出显示?

您至少需要一个最小的 .vimrc.gvimrc 来获得语法突出显示和自动缩进(假设您想要)。 Vim 附带了可以帮助您入门的示例,如果您搜索“vimrc”或“gvimrc”,您将获得大量搜索结果。也就是说,以下是我的一些内容可以帮助您入门:

" Most general settings first
set nocompatible            " Set Vim rather than Vi settings; must go first
set noeb                    " Set no audio or visual error beep
set bs=indent,eol,start     " Backspace over everything in insert mode
set history=500             " Keep 50 lines of command line history

" Set items for view @ bottom of windows
set ruler                   " Show the cursor position all the time
set showcmd                 " Display incomplete commands
set showmode                " Display current mode
set ls=2                    " Always show status bar

" Syntax basics
syntax on
filetype indent on
set autoindent
set smartindent
filetype plugin on

" Text basics
set textwidth=80            " Set text to wrap at 80 columns
set expandtab               " Convert tabs to spaces
set tabstop=4               " Tabs = 4 spaces 
set shiftwidth=4            " Indent/outdent 4 spaces
set softtabstop=4           " Tab key indents 
set shiftround              " Indent/outdent to nearest tabstop
set smarttab                " Uses shiftwidth @ start of lines
set fo=trcn

" An exception for Ruby files
autocmd FileType ruby set tabstop=2
autocmd FileType ruby set shiftwidth=2
autocmd FileType ruby set softtabstop=2
autocmd FileType ruby set number    

" Search basics
set incsearch               " Do incremental searching
set showmatch               " Show matching brackets
set hlsearch                " Highlight all matches in a search

" Don't use Ex mode, use Q for formatting
map Q gq

" Pick a colorscheme
colorscheme Dim

It's an exceedingly powerful editor out of the box, it integrates well with version control, and there are bucketloads of good add-ons available. (See the scripts page as well as the tips wiki.) Those are good reasons to consider Vim, but there are plenty of other good editors available for various platforms. (Look, Ma, no religious editor wars!)

In terms of very Ruby-specific add-ons, check out endwise by Tim Pope, as an example. (It automatically inserts end after do, if, etc.) Actually nearly all of Tim Pope's scripts are potentially useful for Rubyists.

How do I get syntax highlighting?

You need at least a minimal .vimrc or .gvimrc to get syntax highlighting and automatic indentation (assuming you want that). Vim ships with examples that can get you started, and if you search for 'vimrc' or 'gvimrc', you will get plenty of hits. That said, here's some of mine to get you started:

" Most general settings first
set nocompatible            " Set Vim rather than Vi settings; must go first
set noeb                    " Set no audio or visual error beep
set bs=indent,eol,start     " Backspace over everything in insert mode
set history=500             " Keep 50 lines of command line history

" Set items for view @ bottom of windows
set ruler                   " Show the cursor position all the time
set showcmd                 " Display incomplete commands
set showmode                " Display current mode
set ls=2                    " Always show status bar

" Syntax basics
syntax on
filetype indent on
set autoindent
set smartindent
filetype plugin on

" Text basics
set textwidth=80            " Set text to wrap at 80 columns
set expandtab               " Convert tabs to spaces
set tabstop=4               " Tabs = 4 spaces 
set shiftwidth=4            " Indent/outdent 4 spaces
set softtabstop=4           " Tab key indents 
set shiftround              " Indent/outdent to nearest tabstop
set smarttab                " Uses shiftwidth @ start of lines
set fo=trcn

" An exception for Ruby files
autocmd FileType ruby set tabstop=2
autocmd FileType ruby set shiftwidth=2
autocmd FileType ruby set softtabstop=2
autocmd FileType ruby set number    

" Search basics
set incsearch               " Do incremental searching
set showmatch               " Show matching brackets
set hlsearch                " Highlight all matches in a search

" Don't use Ex mode, use Q for formatting
map Q gq

" Pick a colorscheme
colorscheme Dim
秋意浓 2024-09-13 17:04:14

我个人认为 vim 的杀手级功能是不起眼的 . 命令。此命令重复当前光标位置处的最后一次编辑。这可以节省大量时间。

My personal killer feature of vim is the humble . command. This command repeats the last edit at the current cursor position. This can save oodles of time.

左岸枫 2024-09-13 17:04:14

对我来说,vim 的“杀手级功能”之一是它的 临时宏。

q 然后输入存储宏的键名称(我经常使用 m 作为宏助记符,但任何字母都可以),您会注意到 底部的录制状态。现在,您按下的任何击键都将被记录,直到您再次按下 q,并且您已在字母 m 中记录了一个宏。现在输入 @m ,您的击键将会从当前光标位置开始回放,及其所有含义。按20@m,您将重播宏 20 次,现在您已经有了一个强大的工具,可以通过编程方式编辑文本,而无需编写更大的程序(或配置文件)。

特别是对于 Ruby,语法突出显示 (:syn on)、自动缩进 (:set cindent) 和括号/括号配对 (% to正如您提到的,将光标移动到匹配的大括号),其他功能可以在其他编辑器中找到。但实际上,vim 中的通用文本处理宏对于任何文本文件来说都是一个很大的优势。

For me, one of the "killer features" of vim is it's ad-hoc macros.

Press q then a key name to store the macro in (I often use m for a macro mnemonic, but any letter is fine) and you'll notice the recording status at the bottom. Now, any key strokes you press will be recorded until you press q again, and you've recorded a macro in the letter m. Now type @m and your keystrokes will be played back, with all their implications, starting from the current cursor position. Press 20@m and you'll replay the macro 20 times, and now you've got a powerful tool for programmatically editing text without the overhead of writing a larger program (or configuration file).

For Ruby specifically, the syntax highlighting (:syn on), automatic indent (:set cindent), and paren/bracket paring (% to move the cursor to the matching brace) and other features can be found in other editors, as you mention. But really, the general text processing macros in vim are a big advantage for any text file.

痴骨ら 2024-09-13 17:04:14

我认为 VIM 的主要优势是它是跨平台的。现在您正在使用记事本++,这是一个很棒的编辑器(即使它没有良好的宏功能)。明天,您可能不得不使用另一个操作系统,并且您应该学习使用另一个文本编辑器。

I think the main advantage VIM has is the fact it's cross platform. Now you're using notepad++, that is a great editor(even if it hasn't good macros capabilities). Tomorrow, you could be obliged to use another OS, and you should learn to use another text editor.

北方。的韩爷 2024-09-13 17:04:14

我知道你从哪里来。我使用 IDE 甚至 notepad++ 的时间比我记得的还要长。如果您仅使用 VIM 进行基本导航,那么您将无法充分发挥它的潜力。虽然有几个非常强大的插件,但我不认为找到合适的插件就能让 VIM 如此强大。

对我来说,它的作用是我的手不会从键盘上移开,它可以让我保持专注。每次我使用鼠标时,总是会导致注意力分散——这对于程序员来说是不可原谅的罪过。

对我来说另一个杀手级功能是使用正则表达式进行搜索和替换。我强烈建议您了解更多相关信息。或者用 Jamis Buck 的话说,“了解你的工具”。

ftp://ftp.vim.org/pub/vim/ doc/book/vimbook-OPL.pdf

是一个很好的入门方式,但如果你想花钱的话,我想我会推荐 O-Reilly 的书而不是这本书。掌握 VIM 基础知识很容易,但掌握它需要时间 - 但回报是巨大的。

I know where you are coming from. I used IDEs and even notepad++ for longer than I care to remember. If all you use VIM for is basic navigation, you aren't going to be using it to its full potential. while there are several very powerful plugins, I don't believe that finding the right plugin is what makes VIM so powerful.

What does it for me is that my hands do not move from the keyboard and it allows me to stay in the zone. Every time I go to the mouse, it invariably leads to a concentration break - which as a programmer is the unforgivable sin.

The other killer feature for me is searching and replacing using regex. I highly recommend learning more about it. Or in the words of Jamis Buck, "Know Thy Tools".

ftp://ftp.vim.org/pub/vim/doc/book/vimbook-OPL.pdf

is a great way to get started, but I think I would recommend the O-Reilly book over this one if you want to spend the money. It is easy to get the basics in VIM, but mastering it takes time - but they payoff is immense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文