Hacker News new | ask | show | jobs
by GordonS 2452 days ago
While editing a file in VSCode, I can press CTRL+P, which opens a small command box in which I can type to find a command with autocomplete - like a souped-up version of vim's "colon prompt" (not sure what it's called!) - does that count?
2 comments

QMK (keyboard firmware) calls that feature a "leader key."
No
OK... what is the difference, as you see it?
vim (I can only really speak for vim here) has several modes for editing. The main ones are: normal, insert, visual. Most people I know (incl. myself) spend most of their time in normal mode, which allows you to manipulate text objects using movements. In insert mode, your key strokes are converted to characters which are inserted into the file buffer. Switching to normal mode isn't really the same as summoning a command prompt into which you enter commands, it's a bit more fundamental than that.
The real difference is that in Normal mode, you have a very complete set of commands bound to each key that either move the cursor from an absolute perspective, relative to current position, or relative to syntax structure. There are also commands that create a selection to transition you into Visual mode (which is cursor selection) with a given syntax block already selected. Finally, all of these commands can be multiplied out `4w` to move four words ahead instead just one word ahead.

The real power of these is twofold. First you can build muscle memory that lets you move around a text file, precisely select text, and edit the text as fast as you can think. Secondly, all of the commands used to edit text can be recorded into a macro, letting you systematically and repeatedly edit text in a way more powerful than find and replace with high-level regex support (which vim and emacs also have). An example macro could be jump to the next define keyword, then jump to the next set of parenthesis (which would typically be a function parameter)and then reverse the parameters of the function. This macro can be repeated to reverse the parameters of every function in a file, as well as in many files in your workspace. This is fast editing of the semantic structure and convention in a workspace. While this is a contrived example, This editing functionality is very useful for many tasks like re-arranging the structure of each object in a large JSON document to fit to a new schema, refactoring code as well as any task that requires automating many repeated edits. Other editors and IDEs have macro functionality, but without the composable structural editing commands in vim (these are also in emacs) you don't quite have the same kind of power. These kind of edits would otherwise need to be done by a separate script, but the interactivity of NORMAL mode commands and macros let you know that it works for one case, repeat the macro individually and check each case as you go to make sure that it worked, and then edit the macro if the command macro needs to be modified for new structures.

Edit: I forgot to mention that normal mode is also very fast and simple which is much more convenient than CTRL-P for a command. 'w' for moving to the next word. 'b' for moving to the previous words. The command chaining is also relatively consistent for editing as well with 'ciw' for 'change inner word' to select the entire word the cursor is on delete it and then enter insert mode and 'ci('for the same but selecting all the text within the first set of parenthesis that contain the cursor. Many vim emulation plugins don't even feature these commands and only have basic modes and hjkl cursor movement.

> Other editors and IDEs have macro functionality, but without the composable structural editing commands in vim (these are also in emacs) you don't quite have the same kind of power.

That's the other way around. Modern IDEs don't work on text like vim does, they understand the language. Using e.g. JetBrains IDEs you can do refactoring across an entire code base in a few clicks. Something you can't possibly do because vim (unless you use plugins) doesn't understand the semantics or even the syntax of the language, it's just text.