Live data from Hacker News

Ten Years of Vim

matthias-endler.de

71–80 of 123 posts

Re: Ten Years of Vim

#71
post #37

I use (Vim IMproved - not vi) vim all the time. I find it interesting to see what features other people tend to use in vim, there seems to be some minor differences in their workflows, but it's not clear who "wins" the productivity battle. I only use a very small number of it's features: * `:tabe` Create a new tab * `:e .` Start browsing files in that tab * `:w` Write the file * `:q` Quit the file (`:q!`, seriously,…

Most of those are plain vi ( and ed ) commands. All of my machines have the vim-tiny package to stay as close to stock vi as possible. I open and close the editor dozens of times a day to make simple changes and I don't tolerate any lag. I can see that vim would be great for long-form programming but plain old vi was just fine for most admin tasks.

Okay, so I've come across `vim.tiny` a few times now, what's the difference?

Plain `vi` I can't seem to work out, the shortcuts I usually use all seem to be different?

Re: Ten Years of Vim

#73
post #37

I use (Vim IMproved - not vi) vim all the time. I find it interesting to see what features other people tend to use in vim, there seems to be some minor differences in their workflows, but it's not clear who "wins" the productivity battle. I only use a very small number of it's features: * `:tabe` Create a new tab * `:e .` Start browsing files in that tab * `:w` Write the file * `:q` Quit the file (`:q!`, seriously,…

That's a solid set and will take you far. I did eventually start peppering in a few pattern matching command things that don't require much regex. * `:g` Global command, executes an Ex command on every line that matches via the pattern `:[range]g/pattern/cmd` One common use I have for using `:g` is to delete all lines that match or do not match a pattern, like when I've removed an attribute from some data structure a…

Very interesting.

>To delete patterns that do not match, useful for debugging: `:g!/pattern/d`

This is something I would normally use something like grep to achieve, nice to know it exists in vim as well.

>* `:norm` this thing motivated me to use more of the movement commands like `A`, `o`, `D`, `f`, `cw`, and `ci`. Used `:[range]norm cmd`, it acts like each key in the command is run on every line in range. I usually use it with a selection, for example to add a comma to the end of every line in range with `A`, or insert at the end of line: `:norm A,`

In this specific case, I would tend to (maybe in gvim) run a replace on `\n` -> `,\n` to achieve this. That's kind of what I'm looking for in terms of string replacement.

The rest is certainly interesting, but for my work flow I like to generally keep things as simple as possible (bad memory). I've never found myself thinking "I wish there were more movement commands" for example.

Re: Ten Years of Vim

#74
post #45

I read an article a few years ago, the name of which escapes me. It was something like “Idiomatic Vim” or “Linguistic Vim”. I would love to find that article again, if anyone happens to know based on the sparse info I’ve just provided, I would greatly appreciate it. One of the things I learned was that you can do things like yank to a character. In other words, if your cursor is at the beginning of “The quick brown f…

You wouldn't happen to be referring to "Your problem with Vim is that you don't grok vi", would you?

https://gist.github.com/nifl/1178878

Re: Ten Years of Vim

#75

I know you said that you like maintaining a super minimal .vimrc, but fwiw there's a couple of plugins that really helped me with the workflow issues you mentioned struggling with: > Jumping around in longer texts: I know the basics, like searching (/), jumping to a matching bracket (%) or jumping to specific lines (for line 10, type 10G), but I still could use symbols more often for navigation. vim-sneak is real nic…

OP here. Thanks for the tips. I've used vim-sneak for quite a while (it's even built into Visual Studio Code's Vim plugin), but it just didn't work with me. I'm more of an easymotion (https://github.com/easymotion/vim-easymotion) type of guy. But even easymotion vanished from my workflow, because `/` works almost equally well for me and easymotion is not available on every system I use.

I guess what I'm trying to say is that I became more and more conservative about what external dependencies to rely on, because as soon as they become part of my workflow, I can't easily go back because they become part of muscle memory.

For vim-move I use `V` + `j,k` for the selection followed by `d` to delete and `p` for paste. Works quite well for me. The problem that I have with visual selections is, that I often want to "grow" a selection from inside of my current position. Say my cursor is inside parentheses, I'd like to hit a key repeatedly to select an ever growing region of text: first the entire content inside the parentheses, then including the parenthesis, then the entire line, then the entire function and so on. Is there a plugin for that?

Thanks for your article on buffers. Looks like a great workflow. What I'd like to have on top of that is a way to open a buffer based on the contents of a file. Say I have a file somewhere that contains a specific function, `myFunction()`. I'd love to just start typing `myFu` and vim would suggest the correct file to open. Bonus points for handling typos, e.g. `ymFu` should also work.

Re: Ten Years of Vim

#76
post #37

I use (Vim IMproved - not vi) vim all the time. I find it interesting to see what features other people tend to use in vim, there seems to be some minor differences in their workflows, but it's not clear who "wins" the productivity battle. I only use a very small number of it's features: * `:tabe` Create a new tab * `:e .` Start browsing files in that tab * `:w` Write the file * `:q` Quit the file (`:q!`, seriously,…

Most of those are plain vi ( and ed ) commands. All of my machines have the vim-tiny package to stay as close to stock vi as possible. I open and close the editor dozens of times a day to make simple changes and I don't tolerate any lag. I can see that vim would be great for long-form programming but plain old vi was just fine for most admin tasks.

Use Plug to load the plugins that you only need for a specific file. For example, this only load this plugins if I'm working wiht LESS/SCSS/CSS or Vue files :

Plug 'groenewege/vim-less', { 'for': ['less']} Plug 'cakebaker/scss-syntax.vim', { 'for': ['scss'] } Plug 'othree/csscomplete.vim', { 'for': ['less', 'scss', 'css', 'vue'] }

Re: Ten Years of Vim

#77
post #37

I use (Vim IMproved - not vi) vim all the time. I find it interesting to see what features other people tend to use in vim, there seems to be some minor differences in their workflows, but it's not clear who "wins" the productivity battle. I only use a very small number of it's features: * `:tabe` Create a new tab * `:e .` Start browsing files in that tab * `:w` Write the file * `:q` Quit the file (`:q!`, seriously,…

Regarding the replace thing:

If you are used to sed it should be easy, as it is pretty much the same. I keep using this pattern over and over again:

  :%s/search/replace/gc
The '%' is some sort of reference to the file you are currently editing and therefore you are doing a replace on the whole file. You can see the difference in combination with some visual selection. When you select some text and press ':' it opens as ":'"

  :%        # replace in the whole file
  :'    # replace in the current selection
The 'gc' flags at the end are:

  g=global to replace multiple times per line
  c=confirm to let vim ask you about every replacement
Sometimes its just easier to let vim ask you a few times than to spend 5 minutes to figure out the 100% correct regex.

Re: Ten Years of Vim

#78
post #10

After using vim for a few years now, I noticed how I changed from thinking about text as characters to thinking about text as lines, which lets me create much cleaner code (independently from pretty printers). When I selected code via mouse in the past, I selected it from character to character. In vim I tend to think line-wise so I can yank, paste, delete code per line which makes sense in many scenarios.

For mutating programs (as opposed to general text-editing), this text-centrism seems to me like a limitation. I use a combination of IntelliJ & emacs, and the former's deeper model of the programming language syntax definitely leads me to me thinking in terms of a syntax tree units rather than 'text', such that programming in emacs feels like going down a cognitive-abstraction step. The gap can probably be bridged wi…

In general, I agree that a syntax-tree would make more sense, but I think the text centrism is some sort of greatest common denominator as that approach works for many languages (more or less). A syntax tree on the other hand, would work better but probably required some sort of training for every new language :-/

Re: Ten Years of Vim

#79
post #69

Earlier quoted context omitted.

I'm guessing you mean "dd" and "yy" to delete/yank lines. "x" deletes a single character, what you mean extract a line? If you learn "w", which just means advance by a word, you can combine them with your existing knowledge for much better use. So "dw" becomes delete a word, or "d3w" means delete next 3 words. "v" is also useful in conjunction with "w" / "b".

I would either: * SHIFT+V to highlight a line, `d` to delete * `:d` to delete the current line Not experimented with `dd` (or `yy`).

SHIFT+V + 'd' is a longer way of doing 'dd'. SHIFT+V + 'y' is a longer way of doing 'yy'.

You can also delete and yank multiple lines by using 'd2d' (delete two lines) or similar. You can also delete lines upwards by using a movement command like 'dk' (or 'd2k' if you want to delete the two lines above).

Re: Ten Years of Vim

#80
post #28

> I don't use arrow keys to move around in text anymore but forced myself to use h, j, k, l. Many people say that this is faster. After trying this for a few years, I don't think that is true (at least for me). I now just stick to it out of habit. Sounds like he's not a touch-typist. And as a general note; learning and mastering vim can hardly be a pleasant activity for non touch-typists, or otherwise typing heroes.

I don't see why that means he's not a touch typist?

I actually use both hjkl and the arrow keys. Arrow keys are useful for moving the cursor in insert mode.

Post reply on HN