Vim 101: How to Start Using the Text Editor for Developers
datastuff.tech
datastuff.tech
You don't have to make that choice and can have "the best of both worlds": For the last few years I've not been using Vim itself, but Vim bindings in VSCode and Intellj. I enjoy the trade-off of this this approach because it
- is trivial to set up (in stark contrast to configuring a untouched Vim/Nvim install from the ground up)
- gives me simple access to powerful extensions
- allows me to use modern editor/IDE features (find usage, refactor) without forgoing "the essence of Vim", rapid code editing through the combination of motions & commands
But I do use VsVim in Visual Studio and also have a guide on how to do that with R#, I use Vim emulation in all the Jetbrains products as it's really well done, also in VSCode, Vimium in all my browsers. Also use AutoHotKey to add Vimish type navigation to windows controls.
Agree on Vimium in Chrome - I have to check whether it's available on Firefox.
I've never heard of R# (and it's hard to Google) - what is it?
[1]: https://addons.mozilla.org/en-GB/firefox/addon/vimium-ff/
[2]: I can slag Tridactyl off as I wrote a lot of it. It's still my favourite one.
This is simply not possible with other browsers where the UI outside the actual website was only designed with a mouse cursor in mind. And that contradicts the idea of not constantly needing to switch to the mouse and back.
Some of this lack of concern for using the cursor is probably because all of the keyboards I use have trackpoints.
Why do you say it's janky? I love it and it feels pretty polished!
The only issue I have is when selecting the HN upvote/downvote arrow links with 'f' the letter hints overlap :D
- `gi` doesn't work reliably on enough pages for it to be useful, ditto for `g;`.
- we outright break a handful of websites unless you `seturl [url] noiframe true`
- our mini-language is dreadfully inconsistent (e.g. `winopen -private` but also `hint -qb`). Corollary: composite commands steal semi-colons from JavaScript.
- most importantly, entering stuff into the command line is not a pleasant experience compared to our competitors due to lag and various things that block input but shouldn't (this is worse on Windows and generally gets worse the bigger and older your Firefox profile is)
I still like it, though. I'm glad you do too!
For your problem, I'd suggest making site specific binds: e.g. `bindurl news.ycombinator.com ;u hint -Jc [title="upvote"]` and, as a guess, `bindurl news.ycombinator.com ;d hint -Jc [title="downvote"]`, but I'm not cool enough to have downvote buttons so I don't actually know if that last one will work.
I attempted to create something like this some years ago: https://github.com/mihaifm/vim.ahk
It's pretty difficult, applications have vastly different behaviour even in regard to simple commands. Still, it was a fun experiment.
Not having to leave the terminal and vim's responsiveness are still a big pluses for me.
I just haven't found anything as responsive as IntelliJ's custom embedded autocomplete/code-formatting/refactoring capabilities yet... everything else is just inferior feeling.
I'd like to have some of the refactoring facilities you find in IDEs, but I'd prefer to have them as separate tools, commands you run, rather than moving everything into one window.
FWIW I'm using vim bindings in VS code.
I don't really feel like I'm too lacking in this department, but maybe the things I do aren't too complex.
https://github.com/sakhnik/nvim-gdb
GDB is also extensible as hell, and I can’t imagine vs code has something gdb doesn’t.
An aside, as another poster noted - Vim's editing keys are the first thing I'd give up for a better Vim. I've tried Vim mode in VS and it's not Vim. Yes, you move with hjkl, but the editing keys and the entire rest of the IDE are two entirely separate worlds. E.g. I can't record a macro that jumps to a symbol definition as part of its execution. In Vim the entire experience is integrated and there is no separation between "editing keys" and "navigation keys", etc. At its core, Vim is a parser for a sequence of keystrokes where each runs a command. Any command can be bound to any keystroke or sequence of keystrokes. The entire system is based on a few basic principles that apply equally across all keystrokes.
Just embedding a Vim editing mode in your IDE is not at all the same as the real thing. It is still better, especially if you need to limit your finger movements due to RSI or other issues, but it doesn't recreate the reason for which I use Vim. To replace Vim, you'll need to do the inverse - rather than have the IDE as a shell and a Vim mode embedded in it, have a Vim interface as the shell and IDE functionality embedded in it.
I press F12 in my IDE and I get dropped into a terminal or I can just open XTerm independently... I don't follow how this is a valid argument against IDE's.
I wasn't really providing advice on what the objectively optimal setup (lol) is, I was just explaining how I work. My point was just that vim keybindings are not a very big part of why I like this environment.
Everyone uses Vim differently but I tend to combo it with tmux. For example I often have 8+ active tmux sessions (1 for each freelance contract I'm working on + personal stuff). Each tmux session has 1 or more Vim instances running, so switching between each session is 1 key stroke away. It's effortless to jump between them and the state of those sessions are always around (even persisting across reboots with tmux-resurrect). It also takes up close to no resources (a few megabytes per Vim instance).
1. Part of the joy of vim is not configuring it. A ton of the plugins out there exist because the creators didn't know that a feature already existed in vim, and many of them break existing keybindings. Beyond a few small configurations, I use vim as my daily editor largely untouched. A big upside to this is that I can log on to almost any server and have an editor that is pretty close to what I use anyway.
2. My configuration process is (assume you're in ~):
git@github.com:kerkeslager/dotfiles.git
cp dotfiles/.* .
This works fine for pretty complicated configurations, but if there's something that can't be configured in a dotfile, I imagine it wouldn't be hard to add a ./configure script that does the rest.If you're talking about traditional UX values like intuitiveness, sure, vim UX is terrible.
But vim features tend to do very simple things, which are composable into very powerful mini programs in a lot of contexts. There's a sort of "discoverability" to them as well, in that if a key does something in one mode, it likely does something intuitively similar in another mode. All this adds up over time. I've got about 9 years using vim every day now, and the combined learning over that time has added up in a way that disposable learning like "how to use the X flavor-of-the-week plugin" would not have.
Another thing here is that the UX improvement of most plugins is only surface-level. vim features tend to be very simple, which means that when you understand it, you understand it. But vim users with a lot of plugins rarely understand what is actually going on when they use a plugin feature, because the features do too much. This means that they can't really use those features in, for example, macros, which loses you a lot of the editor's power.
Maybe for sysadmins that are always doing a ton of text editing on remote servers, but I haven't run into this. Even when I do work on servers though I don't have any problems using vanilla VIM even though my workstation has 70 plugins. I do take care not to override any of the base keybindings though. If you are overriding core bindings you deserve what you get hehe.
Another key thing is the responsiveness. Vim is just more responsive (or it feels that way to me, you may have different experiences).
I am developing Java using vim + tmux at work and it for certain took a lot of time to get tweaked how I want it to be, and there are some things I've had to give up: debugging is a big one (but that's what log messages are for!), but I 've managed to cover quite some ground: I wrote a plugin to automatically add import statements based on dependencies you have listed in your build.gradle
Yeah I know the image (ooo that guy thinks he's sooo l33t because he uses vim and the command-line all the time... doesn't even need intellij installed!), but I know my setup works for me and it allows me to work as fast, if not faster than my peers and get. crap. done.
To each their own - I make sure that new engineers I'm on-boarding have tools they need to get work done and don't fall prey to some tool-cult.
Where I come from, trivial means "of little importance," ex: The Kardashians' drama is frequently over trivial matters.
The way the author explains it above (mechanical) is the way I was initially taught over 20 years ago. However, it wasn't effective for my learning style because it felt random and incoherent. So _why_ does 'h' key move left? And _why_ do I have to press 'i' for "insert" mode when I didn't have to do that in Notepad/MSWord? My UNIX instructor couldn't answer those questions. He just said, "I dunno, it's just the way it is." As a sysadmin, I memorized it but it was a very unsatisfying way to learn vi.
My brain is most receptive to learning when it knows the underlying philosophy of why things are designed the way they are. Previous comment with some links.[0]
Once one knows the design intentions behind vi, the learning feels much less random.
All you basically need to do at the beginning is press F1 as instructed and just read. There's a very nice tutorial included with vim. :)
As an aside, vim has really had a positive impact on my life (no hyperbole). It's the only editor I've ever used where I can regularly reach a state of "flow" during my day. I highly recommend giving it a try beyond learning hjkl, if you haven't already.
I was wondering were that method were to be paired with a tutorial, if that would help ease people into Spacemacs/Emacs more. In other words, each step or lesson in the tutorial enables a new feature and explores it. So perhaps start with basic text editing, saving, opening, recently used files etc. Then add something like git or magit, and explore how that is used, then explore how the git and editing interact. Each new feature discussed would be like adding a new layer to the ~/.spacemacs file.
My biggest problem is that it is SLOW.
Emacs, even without the Spacemacs bloat, would regularly freeze up on me or feel slow and a bit sluggish.
My main reason for sticking with (neo)vim over Jetrains IDEs or VS Code is the incredible responsiveness. Thanks to Coc et al we now get awesome IDE features too, and Vim is easy enough to customize. (though not as much as Emacs, obviously) .
VSCode is great and responsive locally on this macbook pro, and running locally on Windows 10 with a directory open in WSL is also very snappy. Unfortunately some of my work has to be conducted in an Amazon Workspace, which is so slow sometimes as to be unusable. So frustrating, and apropos of nothing, just wanted to rant!
But I think this is also a matter of perspective. Other developers don't understand why Jetbrains IDEs feel sluggish to me and think it might be my machine etc. (I have a very beefy one)
It's just that with (neo)vim, a fast terminal and no blocking plugins everything feels instant and extremely responsive.
My notes on using Doom: https://noelwelsh.com/posts/2019-01-10-doom-emacs.html
And which operations are slow? Emacs's term mode, shell mode, etc, are 100s of times slower than most terminal apps at scrolling thousands of lines at the user, which is a common part of the workflow of some C programmers. Is that where it is slow for you?
* %, which lets you hop back and forth between ()/{} pairs. Extremely useful when working with, say, Flutter.
* F/f/T/t (and ;/,), which let you jump to a specific character in the line, ahead or behind. This greatly sped me up, as I no longer needed to count out "okay, hop 16 characters to the left."
Also, another important thing is that Vim makes editing fast, not necessarily writing. There's not really much you can do to make writing faster in the first place, as you eventually have to type anything you write at least once in some form. But for editing, boy, is it great.
EDIT: Attempt to fix god-awful formatting
Well, that depends. It’s quite a bit like compression.
If you are doing something repetitive, which unfortunately is still necessary in some conditions for good reasons, Vim is good at this (and so are most other modern code editors; multiple cursors are surprisingly powerful.)
On the other hand you can always invent a shorthand. A popularized example would be emmet for writing XML, which is supported via plugin in most code editors.
When you’re SSH’ing into your server, VIM is incredibly efficient to make quick edits.
Making a change to your cookbook/playbook/Dockerfile/<insert other automation verbage>, submitting a PR, waiting on a new build and deploying doesn't always cut it time wise.
Once in a while you need to just get in, make the change, and backfill the code changes in your build pipeline.
I do a lot of WordPress hosting for large-ish non-software clients running one-off webservers that were setup by who knows years ago.
I certainly can and have automated stuff... but when I get a client who already has hosting setup, they just want me to manage it, not rebuild it.
As a sibling comment mentions, a lot of that is troubleshooting...
But making changes to stuff in /etc is an extremely common case where I just ssh in and use vim.
None of these clients have documentation on how the server was setup, much less any sort of way to set one up automatically. So there is a lot of "hey, can you up the max_file_upload for PHP" or "add a link to the hard-coded footer menu in our Drupal install".
And even when they want me to setup new stuff, they prefer me to just deploy a new instance and give them notes on whatever I do to it. Since these are 1-off things (like a server running some video conferencing or file management), there's not a lot of utility in build a script in BASH or ansible or whatever to build the server.
I'm a dev and the only one at the buisness where I work, so I'd be stoked to hear about some better way of doing work. But really, spending time in an SSH and configin stuff with vim seems like the fast, lightweight path for most of the work I do.
Using bash/zsh extensively, and Vim a few times a day, I have been wondering if people treat bash/zsh and Vim as two different worlds when it comes to keybindings, or is it common to use Vi/m keybindings in bash/zsh/other shells? Would love to hear some input on this! :-)
*I have never used them on osx and use a 50% keyboard.
https://www.gnu.org/software/bash/manual/html_node/Readline-...
I've toyed with taking what suckless have done with their libs and implement some alternatives (people still gripe about missing CP/M (DOS) shortcuts)
But... That changed with recent versions of readline, which introduced 'show-mode-in-prompt' [0]. It's somewhat limited - it only prints an indicator at the beginning of the last row of the prompt. You can, however, change what text is displayed. I use it to emit escape codes that change the shape of the cursor (similar to vim itself) [1].
[0] https://www.gnu.org/software/bash/manual/html_node/Readline-...
[1] https://wiki.archlinux.org/index.php/Readline#Editing_mode
also [ CTRL-I and it's siblings N[ CTRL-I
I rarely even use tags any more.
:help [I
> Display all lines that contain the keyword under the cursor. Filenames and line numbers are displayed for the found lines. The search starts at the beginning of the file. :help [_CTRL-I
> Jump to the first line that contains the keyword under the cursor.Both "] I" and "] CTRL-I" will start at the current cursor position instead.
I did not know about these, but now I am wondering how to reverse "] CTRL-I" and go to the previous result, as it seems quite useful.
* https://crash.net.nz/posts/2014/08/configuring-vim-for-sicp/ * https://docs.racket-lang.org/guide/Vim.html
Tons of Linux users use Vim -- and Vim/vi of course has been popular for decades before Macbooks existed...
How many of those Mac users actually "using Unix" in any meaningful sense? Any more than Android users are Linux users?
SXSW hackathon: https://www.sxsw.com/wp-content/uploads/2019/06/2019-Hackath...
TC hackathon: https://techcrunch.com/wp-content/uploads/2011/05/tcdisrupt_...
https://techcrunch.com/wp-content/uploads/2019/03/2747820553...
Haskell (!) conference: https://miro.medium.com/max/1200/1*D8GHt8dceOWwQp0HljYqXg.jp...
MIT student startup program: https://www.3daystartup.org/wp-content/uploads/2013/01/3dsmi...
I've been using vi/vim since about late 1996. I'm no expert by any stretch of the imagination, but it's like an old friend by now. It has been on every single system I've ssh'd into (as vi) and every system I've had configuration control over has installed vim. (recently via Puppet or Ansible, previously via Kickstart or setup script)
I've used vim for a bunch of different things. Most Linux distributions these days have a lot of sensible stuff already enabled to use immediately, and I've found that my customizations work really well across Linux, Mac, and Windows WSL v1 or v2.
Being able to rapidly transform a lot of text in a document through vim's composable commands is incredibly powerful. If you haven't tried it, run through a tutorial.