by auto · 3y ago · 0 comments
- 'e' and 'k' rapidly, or 'h' and 'b' rapidly to move left and right, or using 'f'/'F' and a target character, with '0' and '$' as needed
- For vertical movement, I tend to use ctrl+'d'/'u' to move the document up and down in chunks, then specific line numbers, as well as marks (usually at most 2-3, with 'a', 'b', and 'c') to hold on to specific areas, or I just end up remembering line numbers and jumping to them.
- Lots of yanking and deleting to specific targets, be it hori or vert
There's plenty more beyond that, but that really is the "crux" of my vim usage, and from what I've seen watching over the shoulders of many programmers over the years, it makes me way faster than most. Programming isn't about typing speed, but my work is often in doing large refactors in enormous codebases. I need to be able to move around as close to the speed of thought as possible, and I have never found a tool that comes anywhere close to providing that ability as vim.
Also, any chance I get to plug the greatest StackExchange answer ever, I will: https://stackoverflow.com/questions/1218390/what-is-your-mos...
- 'j' and 'k' to move up and down, with '{' or '}' or even something like '20j' to move quickly
- 'w' and '$' and '0' to move horizontally, with things like '5w' to move quickly
I also rely heavily on 'v' and ctrl+'v' to select arbitrary shapes of text for yanking/deleting. I'm not sure what the exact takeaway is from comparing our styles, but it's interesting to realize about how much of coding comes down to just navigating up/down/left/right.
I agree with your last couple paragraphs almost verbatim though! That StackOverflow answer is exactly the reason I decided to try vim and stuck with it.
The verb/noun nature of vim makes it so easy to enter a flow state. The text editor fades into muscle memory, and you can surf waves of code with no bottleneck between mind and machine. (To write this comment, I actually had to open a random file and navigate around it while watching my hands — it's been years since I've thought about it!)
I use w b $ and ^ to move horizontally. I like using w and b because then I can hit cw to make a small change. For vertical (I don't really think in terms of horizontal and vertical, I think about it as a streams of "words" and "spaces") I usually do a search (/ or ? to go up or down) or for some files I do 20j like you. Shamefully, I do sometimes use the mouse out of habit from other programs.
I can't remember the last time I used f.
Boy, do I have news for you :) ; will repeat an f/t/F/T motion forwards, and , will move back. Having it separate from n/N means that they have a separate history and you can combine them to repeat motions.
The only issue is (content warning: controversial remap) I have ; nnoremap'd to : and : to ; so it would be awkward to advance multiple matches. I would hate to lose my one key :, but perhaps there is a workaround if f is useful enough (for those unfamiliar, with / or ? you use n to go to the next match).
When I played piano there was a point where I could play a piece without thought but couldn't parse the sheet music or know what my fingers were doing anymore.
As I just learned browsing through the book linked in this thread, there is!
Use ; to go to the next match or , to go to the previous one.
Great find.
df: - delete to the next colon
2f, - move cursor forward to the 2nd comma
I find cause to use f fairly regularly.
ct) (change to) will change everything from the cursor up to, but not including the paren.
But if you're trying to change everything in parens, you can simply use: ci(, regardless of where your cursor is as long as it's somewhere in a matched set. ci{, ci[, etc... also work. I find it pretty useful when working with code that uses a lot of those.
Quite helpful if you have multiple of the same character and you want to go beyond the first one without needing to count.
Muscle memory is a weird thing.
To move horizontally, simple 'f' might be faster quite often (some prefer combining it with leap-like plugins like flit if using nvim).
* Do you want autodetect indent and tab rule in file? Install plugin.
* Do you want to automatically insert matching closing parenthesis - rebind keys (half baked solution) or plugin.
* Vertical scrollbar? Plugin
* Autocomplete code using lsp? Dance with plugins or copy paste literal screens of configs for nvim
* Want nice looking theme? Plugin! (Gruvbox in my case)
* Install and manage plugins? 3rd party Plugin for that too, with init code that will clone it itself from GitHub
* Wrap long lines by whole words if possible? No default setting, I guess I need to search for plugin for that too.
List goes on and on, and it is just I’m looking at my vimrc and recalling why I added or another thing. And there are many things which I decided to just to not care about, because it requires too much time to get it work
Parent mentioned refactorings, but trust me, no matter what typing/navigating speed is, the standard refactorings in modern ides (that I bet cover most of typical refactoring work) will work faster and more correctly than manually doing the same. Even basic things like projectwise method rename or extracting something to parameter.
Almost every quality of life improvement that is standard in modern ides require tinkering with vim.
> Vertical scrollbar? Plugin
If you want scrollbars, the right solution is IMO to use a GUI Vim. I often use MacVim which is great, GVim is the obvious alternative on Linux/Windows, and NeoVim has lots of options (including, arguably, VSCode-NeoVim which is also great).
With MacVim, I can pop around randomly in a terminal and open Vim instances that run in the terminal as usual - and if I start editing something for long, I can type :gui to pop up an actual MacVim GUI window. I believe the same works in GVim.
> * Autocomplete code using lsp? Dance with plugins or copy paste literal screens of configs for nvim
I was annoyed by this as well. I then discovered that ALE (the venerable pre-LSP plugin for async linting) now has full LSP support, and it all “just works”. Doesn’t require NeoVim either. Just install the ALE plugin and put LSP servers in $PATH. ALE will find and use them. (By default, it uses standard Vim bindings like C-x C-o for completion, but you can change it.)
> * Want nice looking theme? Plugin! (Gruvbox in my case)
Vim 9.x (not NeoVim) has added a built-in Gruvbox theme named “retrobox” (both light and dark variants based on your background setting). If you don’t have it yet, you can get it as a plugin from here until your Vim updates: https://github.com/vim/colorschemes
> * Wrap long lines by whole words if possible? No default setting, I guess I need to search for plugin for that too.
There are built-in settings for this, but yeah it requires some initial fiddling to get it nice. (After that initial fiddling, I’ve been annoyed by how word wrap works in any other editor.)
Added: I hate both worlds now. Where’s an editor that is full of modern features and at the same time easily programmable?
What about an editor with
- LSP and treesitter support built-in
- Scriptable with Lua, a common and well-supported embedded language
- Regular and remote plugins can be written in NodeJS, Python and Ruby for starters
- Built-in terminal emulator
- Uses XDG directory layout
- Plugins run as separate processes
- API for accessing core editor features
- UI and core editor are decoupled; all UIs are plugins
- Multiple UI clients can connect to the same editor server
This and a lot more is on the Neovim page [1].
It is probably missed, but I use vim everyday, as text editor for many years. My .vimrc on github is 3 years old, and only because I moved it there from bitbucket and didn't bothered to preserve history. I'm not against it.
It was that original comment that I answered, was saying that vim is effective/better for IDE specific tasks (e.g. large refactorings, that inititial comment that I've replied), and after many years of using vim I strongly believe is rather ignorant and shows not understanding of power and features of modern IDEs.
[1]: https://github.com/neovim/nvim-lspconfig
[2]: https://alpha2phi.medium.com/neovim-for-beginners-lsp-part-1...
An IDE plugin for Vim rather than a Vim plugin for IDEs?
Also, modern IDE layers for Neovim such as LunarVim or AstroVim make managing plugins trivial.
For me personally, the benefits are worth it, because the neovim approach really works well with my way of working with editors. And the "personally" part is really important.
In my early years I have used IDEs and I was never really interested in using Vim in the first place. (I thought it was not very nice looking when I first looked at the empty screen). I only started using it because I found other IDEs (CLion, Visual Studio) and so on not very comfortable. Even now, I have tried quite hard to use VSCode due to its support for remote development which I really like as a feature. However, I keep coming back to Vim it seems.
So, for me, vim is an appropriate tool, but it might not be for you, because we might be thinking about text editing in fundamentally different ways.
We don't need to associate motion style navigating and separation of command and insertion modes as something very vim specific. It is that vim is installed on every machine that I work on in like 99% of cases, and it made sense to me to learn something that is always available. But the shortcomings are very clear.
I can give an analogy of gdb. I feel that anyone who says that text mode gdb is anywhere near convenience that you get using modern IDE is suffering from stockholm syndrome. Yes, obviously it is more powerful in some circumstances, but for day to day use it is just plain inconvenient.
And that's why I said in my first post - I settle on vim as text editor, but I gave up trying to set it as an IDE, so I will never code in it, unless I'm forced to (who knows, weird job that requires vim use etc). Life is too short for that amount of tinkering.
You can also get modern IDE features such as LSP supported renames in Vim, so it's not an either fast typing or good refactoring support, you can get both.
Shift-V:!fmt
Works on all blocks, not only lines.
I was speaking about
set wrap
but because I turn on display invisible symbols, set linebreak
doesn't work. Why? I don't know. Somehow IDEs can do that without issues, but the technology isn't there yet for vim, seems like.It’s just faster when you are connected shell… and unlike vscode - vim is pushing 30 and the shell environment 40, I see very little reason the shell and vim will substantially change in the next 40 years… but I guarantee vscode will look very different… so learn a tool for life that will be just as powerful tomorrow as it is today
Quite true.
Also, partial buffer manipulation can be done with external programs via range constraints. For example, to reverse sort only the first 5 lines of in buffer, one can execute this ex[0] command:
:1,5 !sort -r
0 - https://man.freebsd.org/cgi/man.cgi?query=ex&apropos=0&sekti...!}somecommand
to pipe a paragraph through that command, or
1G!Gsomecommand
to pipe the whole editing buffer through that command, which is also equivalent to
:1,$!somecommand
which I find less obvious as a way to do that, even though it makes sense historically in terms of ed and ex.
You can also, in vim, use u and ^R to undo your pipe transformation and redo it, so you're basically then doing a series of shell pipe transformations with interactive history.
If you need to generate text with a shell command instead of pipe existing text through it, you can use
:r!somecommand
Commands that I like to use in this context include tac, rev, tr, cut, grep, and sed (although using sed this way is a little silly since the substitutions I'm doing are normally also available natively inside of vi itself).
A simple example that I like a lot is
1G!Ggrep .
which removes all empty lines from the current file. ("Line 1 go to line, pipe from here to result of movement go to end of file, command 'grep .' [print lines that match 'any character']")
The classic ed/ex way to do this is
:1,$g/^$/d
which is just as many characters, but which requires lots of explicit thought for me, while the "1G!G grep ." version seems to no longer require explicit thought at all. ("For lines 1 to last line, repeatedly match ^$ [line beginning immediately followed by line end], delete matching lines.")
> :1,5 !sort -r
Interestingly enough, you don't even need an external program for that. You can do the same thing with
:1,5 g/^/ m 0
The g command allows for effectively looping over matching lines as opposed to operating on them all at once. The /^/ matches every line and since I'm using 1,5 for the address, it still only matches the first five lines. The m command moves a line (in this case, 0 which is the beginning of the buffer).Since it executes it one line at a time, it moves the first line to the beginning of the buffer, then the second line (which places it above the first line), then the third line (placing it above the second line) and so on.
:1,5 !tacYou also lose time on double checking typos in the term command (and it's harder to focus since unlike front¢er palette this command is tucked away at the bottom), except you have no additional validation from a preselected set, so you need to remember the full command invocation precisely
And you can add special unique symbols to command names to make search unambiguous
You also get a hint re keyboard shortcut, unlike with the term command, so if you execute it often enough, you might switch to a faster and more predictable method
And a program can be improved even without it being changed substantially.
(that's why you had to add the "substantially" qualifier)
Curious. Unergonomic compared to what? Given your comment about separating commands and input language, I assume you’re using a non-modal editor, which usually rely more on modifiers than Vim.
Personally, I haven’t found any ergonomic non-modal editor, where I by “ergonomic” mean no RSI pain even after heavy usage. For me, the fact that editing in Vim is comfortable is its main selling point (more so than its speed).
> mistakes can lead to destructive consequences
I do often make mistakes, but I can’t remember the last time I accidentally did something so destructive in Vim that I couldn’t just undo it normally.
For example, I'm sometimes transposing characters, e.g. q: instead of :q, or :w! command instead of :w !command, that sort of thing. Undoable, of course, just not with a simple u.
Modifier-based shortcuts in other editors and IDEs appear to be more forgiving.
Vim regex is not the best and there's an option to change but I got used to it. Recommend http://www.vimregex.com/
gv is quite handy when you want to reselect last to rerun a command on it too
Though it's not that it should be the only way to go (plenty of vim pros have adjusted), it's just visual feedback is very powerful, and lack thereof is a legitimate big challenge you shouldn't ignore in the "greatest" answer
This would kinda be the opposite of the idea in Helix/Kakoune: one automatically enters a visual-mode-like state after typing a verb that expects an object.
I’m a veteran, but I run into that every time. I use nvim and pycharm.
Are there new developments that could change my mind? I love the idea of all of this.
Did you check the Vimium extension for Chrome?
https://chrome.google.com/webstore/detail/vimium/dbepggeogba...
https://github.com/philc/vimium/issues/82
anyway, yeah I'm aware of it haha
edit: my fork is still alive! Here's a commit from 2011 that I never filed a PR for that includes a news.yc submission keyboard shortcut for vimium: https://github.com/llimllib/vimium/commit/59e3d7f7aa01bb032d...
I use vscode for editing code without any special keybinds and just a couple of plugins for syntax highlighting. I use vim for everything else in the terminal window (also without plugins). I don't experience any speed difference or difficulty switching between the two.
Yeah I'm going to say something blasphemous... they're about the same. Vim is just slightly jankier, but more mature/capable.
Yes, that StackOverflow answer (which starts with the above line) is one of the best I have ever read, on any subject, not just vim.
(However, I should mention that I have not read, say, thousands of stack overflow answers, only in the range of hundreds, because I was never a heavy StackOverflow or StackExchange user.)
Anyway, FWIW, I think that answer could described as partly explaining the "Zen" of vi(m).
And for people who are intrigued by the benefits of vi(m) mentioned by various commenters in this thread, and would like to start using it, I have a small vi tutorial, which is applicable to vim too.
Those new to vi(m), check this vi quickstart tutorial that I created.
https://gumroad.com/l/vi_quick
From the start of a Twitter subthread I wrote about the tutorial (thread unfortunately deleted later by accident - Twitter should have an undo feature like vim, heh):
[ Those new to vi / vim, hit the ground running with my short vi quickstart tutorial here:
https://gumroad.com/l/vi_quick
I first wrote that tutorial at the request of a couple of Windows system admin friends of mine (at a company where I worked earlier), who were tasked with managing a few Unix boxes, without knowing Unix. They used the tutorial and later told me that it helped them to quickly start using vi to do their work on those boxes, including editing config files, simple shell scripts, etc.
Edit: Since vi is mostly a subset of vim, the tutorial works for vim too. ]
I think I’m only scratching the service with my neovim setup. But besides the plugins that make it a bit more like a full IDE I’m using some set of core commands, heavy use of visual selection and s/foo/bar etc.
I learned a lot from this guide. I didn’t know about the f and t commands. Very cool.
- shift - v - } to select a block, or v - w to select a word. It's not strictly needed but help ensure selecting the right stuff
- ctrl i - ctrl o for navigation
I've never been able to use tabs, buffers, multiple file edition, that's just too much overhead for me. I rely on vscode for that.
That being said, I don't think using vim gives me a competitive advantage. I'm also rather proficient using standard OS shortcut. I like vim out of laziness, it minimizes hand motion, but don't make that big of a difference IMHO.
(also lots of young guys use vim too, some younger guys in my team even refuse to use vscode...)
EDIT: also vi adds a lot of value in the terminal where standard OS shortcuts don't work, at least on MacOS (i'm waiting for comments telling me how to make them work!)
nvim +startinsert -u $HOME/.i3/terminal.init.vim term://bash
A post with more customizations: https://www.balajeerc.info/My-New-Favourite-Terminal-Emulato...
You might consider posting that link a standalone entry on hacker news. That was a very great read well worth additional exposure.
> "cdd" "@c" is effectively a finger macro for me
That is pretty much how I use vi: muscle memory :]
I've been using vim and vim bindings for like 3 years now. I've occasionally ran in to something that the plugin doesn't handle well but I can work around it with a custom binding. This has only happened a handful of times. I'm genuinely curious about what features of vim I've been missing out on!
But there's nothing in VIM that I'm not able to do in VSCode. Especially when you realize you can very very easily bind VSCode commands to keys in VIM. It starts to feel like a superpower.
from my neovim config:
nnoremap <silent> zc <Cmd>call VSCodeNotify('editor.fold')<CR> nnoremap <silent> zo <Cmd>call VSCodeNotify('editor.unfold')<CR>
But there are some things that aren't quite right. It may be down to config, but it's frustrating when you use a key binding you expect to work that doesn't work the way it does in just vim. I can't name any specifics because I only use vscode for debugging sometimes.
The feature of not having your editor made by an evil greedy corporation. Oh, and also startup time and memory usage.