Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"/ for searching (really, no other editor has made it this simple)" Well, it's really esc-/ which is no easier than ctrl-f. Or am I missing something?

Edit:

Same with "1G to go to the top of the file, G to go to the bottom" - esc-1-shift-g vs ctrl-home. Same with ctrl-end.



Or am I missing something?

Indeed you are. The / command in vim is a motion. This means it can be combined with any command that expects a motion as input. For one example of this, try typing "d/foo<CR>" (excluding quotes). This will delete all text from the cursor to the first occurrence of foo.


I'll have to remember that. Cheers.


I don't really agree about "esc". "Normal mode" is the normal mode as the name indicates. That's where you normally start from. It's the actual writing that's two characters more (start insert mode, write, exit). Unless you're just writing new file from scratch in one go, you're likely to be in normal mode a lot of the time.

Also, shift is not needed for the beginning of the file. It's also "gg" for the first line / "G" for the last.

Regarding the ctrl+home/end, I much prefer not using them. Simply because I switch between 4 different keyboards during the week and I don't know where home/end are without looking. (3 of them being laptops with wildly different layouts) gg/G are on the home row. That's much easier.


"It's the actual writing that's two characters more (start insert mode, write, exit)." Makes sense. Asking for permission to type in a text editor feels counter-intuitive, but I'll give that a try.


Vim really is an editor: It's designed around changing existing text. Inserting new text is just one of the actions you can perform, and you can combine that action with other modifiers, like "5ifoo<esc>" results in foofoofoofoofoo -- 5 repetitions of "insert foo"


This goes better when you know (and have internalized) more of the paths into insert mode.

For instance, ci} will delete everything inside the tightest enclosing braces and switch you to insert mode. This whole thing, then, including what you type, is a single action that you can redo with .


What's ^Home / ^End? If it's moving to the beginning / end of a line there are vi shortcuts for that: ^ and $.


I think you're using the editor's modality wrong.

ESC is not used to exit from Insert mode. ESC is used to switch from any mode back to Command mode. In fact Command mode is also called Normal mode. You should spend 95% of your time in Normal mode and use the other modes when you need them.

I suggest binding `kj` to ESC since it allows you to quickly make a change and continue browsing your code. Take the following session:

* Browse and spot something that needs to be changed

* Type `ci(messages, callbackkj`

* Keep browsing with `hjkl` as you're in Normal mode

While it may seem weird, I've yet to find an occurrence of `kj` in a program in years of using this binding and my hands haven't left the keyboard. The cognitive weight is zero as well (at least after building muscle memory).

Now, I believe it depends on the kind of programmers you are. My coworker is the kind who types in a lot of code and rewrites a lot of stuff. I'm the kind of rewires things and make subtle changes after spending a lot of time reading it. In other words it works well for me but probably wouldn't for him.


Interesting coincidence, I was pasting a production certificate into Vim the other day and it contained "kj", which escaped the editor and ate a few letters until it reached an "i" and continued pasting.

It took production down for 30 minutes until I noticed it. Remember, kids! ":set paste".


> Remember, kids! ":set paste".

Or get used to ctrl-[ which is easier to type than Esc, doesn't skip events(like ctrl-c), and doesn't interfere with anything.


I usually use `paste` but I sometimes catch myself formatting just-pasted chunks of code. I'll watch out for this.


"+p will paste the system clipboard.


Nah. I've had terrible and inconsistent results with this. I literally hate this thing so much that I've stopped using it altogether. It's most likely due to me not figuring out exactly what's going on but I can't be helped at this point.


No way!

I just tried it, it doesn't work :( That's too bad.


That's for GUI Vim. If you're using Terminal VIM you can install this plugin: https://github.com/kana/vim-fakeclip


Thank you, I'll try it right away!


Or :.!xclip -o


Are you on a mac and using the system default vim? If so, Apple cripples it to not be able to directly access the system clipboard -- use homebrew's vim or macvim instead.


No, I'm on Ubuntu, it just looks like this method doesn't work with terminal vim. Your sibling comment looks like it has a solution, though!


I am not sure which version of vim you are on. I have been using clibpoard paste for a long time in Ubunut. Do a ":version" in vim and check if it's compiled with +clipboard. If it is, then it should work.

Also, you can have this in your vimrc:

  set clipboard=unnamedplus
And then your vim copy-paste will be in sync with system clipboard(no need for +p or +y).


Now, I believe it depends on the kind of programmers you are. My coworker is the kind who types in a lot of code and rewrites a lot of stuff. I'm the kind of rewires things and make subtle changes

Interesting, I was thinking something similar - suitability for maintenance vs from scratch.


I use 'jj' rather than 'kj' and except for a pause after I type the first letter of 'join', it works well.


If I may use you as a random Vim power user, how do you quickly switch between project files?


Haven't written many blackjack games?


It sounds like you're assuming that the default is insert mode. If you're in insert mode the majority of the time you're not really using vim correctly.


Or you're typing out a stream-of-consciousness thing. In which case you may be using vim correctly, but vim isn't buying you much.


I disagree with this. You're not normally in insert mode when using vim, you're in normal mode (the one vim starts in).

This means that it really is / for searching, 1G to go to the top of the file, w to go one word forward, f( to go to the next opening paren, and ci" to change everything inside the current "..." etc.

What this also means is that when inserting text you start by pressing i, type the text you want to insert and then immediately press ESC (or CTRL+[) to go back to normal mode.

The reason is that everything that is not directly inserting text is much quicker and faster to do in normal mode compared to insert mode once you learn a few of the commands.

I probably only spend a few percent of my vim-time in insert mode, most of it is spent in normal mode.


> Same with "1G to go to the top of the file, G to go to the bottom" - esc-1-shift-g vs ctrl-home. Same with ctrl-end.

gg beats both (I don't think I've ever used 1G to jump to the top of the file)


I was taught that one by the brother-in-law. He also tried to teach me 1234l (the letter 'l') to go to the end of a line. I figured out a better way pretty quickly on that one.

I didn't find the magical 'g' until much later, and 1G was already burned into my synapses. I'm trying to change. It's a little awkward :)


That's actually kind of an interesting idea. $ for end-of-line always bugs me; for something so common I don't think it should require a chord. '999l' is pretty easy to tap out.

On the other hand, it would probably be easier to rebind something like '-' as end-of-line. I'd do backspace, but I've already changed that to PageUp (backspace/space work great as PageUp/PageDown)


Is it common? It's really rare that I need to go to the end of the line and not switch to insert mode. If I do want to go to the end of the line and switch to insert mode, then what I want is A not $. Of course, there's a chord either way, but I'm surprised if you're finding it easier to type 999l than A.


Oh, no - I use A all the time. My use case is generally more v$ followed by some other movement backwards then c,d or y, or Ctrl-V $ and move upwards/downwards.


Ah, 'k, yeah, I don't do visual selection much.


I've been using vim for 5 years and a student showed me you can do it with commands too.

:10 :25 :1

I tend to use that a lot now and I don't know why. However, you can do some pretty cool command with ranges of lines.


Why is Esc-/ easier than Ctrl-f (or Ctrl-s in Emacs)?

Esc requires you twist your entire left hand sideways up to hit the Esc, whereas Ctrl requires you move only your left pinky to hit the Ctrl.

Ctrl is more efficient.


Efficiency really depends upon the keyboard you're using. If you use a keyboard with thumb clusters, the control and meta keys are under your thumbs and you don't need to twist your pinkies at all.


No need to use 1G at all, gg does the same and is one key less.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: