工具与资源sanctum.geek.nz
Vim 反模式
Vim Anti-Patterns
2016 — 2019,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇页面列举 Vim 使用中的常见反模式,解释为什么某些看似方便的习惯会拖慢编辑、削弱模态编辑的优势,并给出更符合 Vim 思路的替代做法。它适合希望把 Vim 用得更顺手的读者对照检查。
为什么经久不衰:它把 Vim 的高效技巧转化为一份可对照的坏习惯清单,初学者能少走弯路,老用户也能查漏补缺,因此多年后仍值得读。
HN 评论精选
Vim 的 tab 不应等同于打开文件,应把 tab 当工作区、用 buffer 管理文件。
这些建议都很好,但文中多数反模式更偏向初学者,比如不要用方向键、不要在插入模式里导航。我认为中级甚至高级用户中更常见的问题是误用 tab、window 和 buffer:很多人把每个 tab 当成一个打开的文件,这很像 IDE 的范式,但在 Vim 里其实是反模式。tab 更像是工作区,用来把多个窗口排成想要的布局;每个文件对应一个 buffer,在窗口里查看。多个窗口共享同一个 buffer,或替换某个窗口正在查看的 buffer,都没问题。第一次尝试这种方法时,可在配置里加上 set hidden,避免当前没显示的 buffer 被自动关闭;再配合 fzf.vim,管理大量文件会比一个文件一个 tab 轻松得多。
foob查看英文原文
These are all good tips but most of the anti-patterns seem to skew towards beginners (e.g. don't use the arrow keys, don't navigate in insert mode). One that I think is more common among intermediate, and even advanced, users is the misuse of tabs, windows, and buffers. A lot of people have a tendency to think of each tab as corresponding to a single open file. This is very understandable because it closely matches the paradigm of most IDEs but it's actually an anti-pattern in VIM. Tabs are really meant to be more like workspaces where you arrange multiple windows into a desired layouts. You then have one buffer for each file that you're dealing with and view them in your windows. It's perfectly fine for multiple windows to share a single buffer or to switch out the buffer that is being viewed in any given window. This StackOverflow answer [1] and this blogpost [2] both go into a fair bit more detail. If you're trying out this approach for the first time then you probably want to add `set hidden` to your configuration in order to avoid automatically closing buffers that aren't currently being viewed in a window. Coupling this approach with fzf.vim [3] makes managing very large numbers of files a breeze compared to using one tab per file. [1] - http://stackoverflow.com/a/26710166 [2] - http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/ [3] - https://github.com/junegunn/fzf.vim
用纸片分批练习快捷键、按痛点逐步加插件,是可持续的 Vim 学习法。
我刚开始学 Vim 时用过这个技巧:把 2-3 个快捷键写在纸上贴在屏幕前,用 Vim 写代码,慢慢会发现其中一些有用并开始使用;进入肌肉记忆后就不再需要纸。写代码时留意让自己烦躁的模式,比如跳代码、频繁替换、选文本、Git 集成,把这些观察列成清单,每次挑 2-3 个快捷键贴到屏幕上,再挑 2-3 个插件或功能来增强 Vim。几年后你的 Vim 会高度定制,甚至在其他 IDE 里写代码都不顺手。另外建议用 Git 管理 Vim 配置,并为配置写 README。
csomar查看英文原文
Here is a trick that I used to use when I started learning VIM: - Write down 2-3 tricks/shortcuts in a piece of paper. Put that piece of paper in front of you (ie: tag it to your screen). - Code with Vim. You'll eventually look at the piece of paper and find some of these shortcuts helpful. So you'll use them. - After a while, these shortcuts will get into your muscle memory and you'll no longer need the piece of paper. - When you are coding with VIM, detect annoying patterns: For example, I need to jump code, I need to replace often, I need to be able to select some text this way, I need GIT integration. You get the point. - Put these observations on a list. Pull 2-3 items (shortcuts) from this list and tag another paper to your screen. Pull 2-3 items (plugins/functionality) and enhance your VIM. - After a few years, your VIM will become extremely customized. You'll actually have trouble writing code on any other IDE. - Here is mine: https://github.com/omarabid/vimrc Other bonus tips: - Use GIT to keep track of your VIM configuration. - Write a README file for your configuration. Other things that I should do: Update the README often, and add screenshots. ps: in case you haven't noticed, I'm a die-hard VIM fan.
偏好 Ctrl-C 而非自定义 Escape 映射,因为可移植且不破坏其他编辑器。
Ctrl-[ 是 Escape 的好替代,但并非所有 Vim 实现都支持,比如 Visual Studio 的 Vim 插件可能就不行。把 JJ 绑定为 Escape 也不错,但到了没有自己 vimrc 的机器上,速度会明显下降;所以我尽量不改核心快捷键,这样 ssh 到全新 Linux 用原生 vi 也能和在自己开发机上一样快。我发现 Ctrl-C 是另一个默认的 Escape 替代,在 vi、vim、nvim、gvim、ssh 里的 vim、Visual Studio/IntelliJ 的 Vim 插件上都有效。另一个好处是:在非 vi 编辑器里出于习惯按 Ctrl-C 不会真的做什么,而 Ctrl-[ 可能是那个程序的热键,JJ 则会插入两个不想要的字符。
Assossa查看英文原文
Ctrl-[ is a good replacement for escape but I've found it's not always supported in every vim implementation. If I remember correctly it doesn't work in the visual studio vim plugin. Binding something like JJ to escape is also a good solution, but if you ever have to edit on another machine without your vimrc, your speed will seriously suffer. I try to not change/add any core hotkeys for this exact reason. I can ssh into a brand new Linux install and edit with stock vi at the same speed as on my development machine's vim install. I discovered that Ctrl-C is another default escape alternative. It's worked on everything I've tried so far: vi, vim, nvim, gvim, vim over ssh, vim for visual studio, vim for IntelliJ, etc. This is what I've gotten used to using. Another benefit is if you're using a non-vi editor and try to exit insert mode out of habit, Ctrl-C won't actually do anything, whereas Ctrl-[ could be a hotkey in that program and JJ will obviously insert two unwanted characters in your document.
高频使用的工具值得认真掌握;Vim 能减少手眼切换和上下文切换,长期回报大。
任何需要频繁使用的工具都值得认真学习;更优秀的工具如果会常用,也值得切换过去并学习。如果思维较慢、容易保持想法,手在方向键和主行之间来回移动也许不是大问题;但如果你思维不断奔涌,就需要足够快,在想法消失前表达出来。手移开主行、视线离开屏幕定位再找回,都会带来时间和心理上下文切换成本。花很多时间用某些工具,就没有理由不把它们学好;拒绝学习是选择低效。当然,偶尔才用的工具可能不值得,但很可能还有别的常用工具值得长期投入。如果你编程,Vim 的行为方式在把脑中的东西快速输出到电脑方面很难被击败。
blunte查看英文原文
Any tool you need to use more than a few times is worth learning properly. And any superior tool is worth switching to and learning if you would use it frequently. I suppose it depends on how one's mind works. If the mind moves slowly and holds onto ideas and abstractions easily, then the slower motor movements of moving the hand back and forth from arrow keys to home keys, and to mouse and back, are not really a problem. But if you're like me, and your mind is constantly racing, you need to be fast to get your ideas out before they're gone/replaced. It's not just the time cost of moving the hand from home row down to find the correct cursor key, do the presses, and then move back to typing position - it's also the likely visual/mental cost of looking away from your screen to aid in positioning the hand, then looking back at the screen and finding what you were looking at before. All those movements and recalibrations take time and involve mental context switches. If you're spending a lot of time using a certain set of tools, there is no reason to avoid learning those tools well. Refusing to do so is choosing to be ignorant and subperformant. Now, if you'll only use the tool once in a while, perhaps it's not worth the effort. But chances are, there's some other tool you use often that you could master for your long term benefit. If you program, Vim (behavior) is very difficult to beat for getting whats in your head out and into your computer VERY quickly. As a bonus, using a full featured IDE like one of the JetBrains products, but with the Vim plugin, is win win. You get the code editing speed of vim, plus the project navigation and other benefits of the IDE. Totally worth the time investment.
历次讨论
同类还值得读
直接在浏览器中启动 Linux 内核
Boot a linux kernel right inside your browser.
Fabrice Bellard 的 JSLinux 页面,用 JavaScript 在浏览器里启动一个 Linux 内核,并提供一个可交互的终端环境。
工具与资源上首页 5 次 · 2011–2025bellard.orgHacker News 未公开功能与行为清单(2018)
A List of Hacker News's Undocumented Features and Behaviors (2018)
数据科学家 Max Woolf 整理的 Hacker News 未公开功能与行为清单,涵盖投票机制、排名算法、账号惩罚等社区运作细节。
工具与资源上首页 5 次 · 2019–2025github.comMapSCII:在终端中用盲文和 ASCII 渲染地图
MapSCII – Braille and ASCII map renderer for the console
MapSCII 是一个在命令行终端里渲染地图的开源工具,用盲文字符和 ASCII 字符把地理数据画成可交互浏览的字符地图。
工具与资源上首页 5 次 · 2017–2025github.com顶尖大学的免费在线课程
Free Online Courses from Top Universities
Open Culture 整理的一份免费在线课程合集,汇集了全球顶尖大学(如 MIT、斯坦福、耶鲁等)向公众开放的网络课程资源,涵盖音频、视频等多种形式。
工具与资源上首页 5 次 · 2010–2022openculture.com淘气字符串:容易引发用户输入问题的字符串清单
Naughty Strings: A list of strings likely to cause issues as user-input data
一个 GitHub 仓库,收录了大量容易让程序出问题的用户输入字符串,如特殊字符、emoji、SQL 注入片段、系统命令等,供开发者用于测试输入处理逻辑。
工具与资源上首页 4 次 · 2015–2020github.com