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.
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.
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.
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.
It took production down for 30 minutes until I noticed it. Remember, kids! ":set paste".
Interesting, I was thinking something similar - suitability for maintenance vs from scratch.
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.
gg beats both (I don't think I've ever used 1G to jump to the top of the file)
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 :)
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.
Oh, and on a side note:
Vim and terminal usage is not a "time sink" and it pains me whenever I hear people who consider them selves "programmers" claim it to be. If you haven't learned how to use the terminal yet (or haven't found a use for it) then you aren't a respectable programmer IMHO. I would not read a book on programming by someone who doesn't know how to use a terminal and I would not take a class on programming taught by a professor who doesn't know how to use a terminal.
I'll never understand the sort of arrogance that leads to posting things like that. do you really believe you're so smart that you figured out the only way anyone should do anything?
Also - can I just ask, as someone who "uses a terminal" but doesn't really get why people talk about it like it's so amazing - what am I doing wrong? What do you use a terminal for that makes it so important?
The terminal is a relatively standardized display with some severe limitations and kludgyness. The DOM of its era.
The shell, which happens to typically live in the terminal, has three things going for it that GUI interfaces frequently lack.
First, composability and automation: any action you can fire off from the shell, you can fire off from a shell script. Any data you're given by a utility, you can operate on and send to any other utility. Any data you're asked to provide can come from anywhere.
Second, narrative structure with history and a sense of place. "I did X, then I did Y, so now I need to Z... wait, what did X say?" is a natural mode of interaction convenient to many sorts of tasks.
Third, extensibility. Write any new utility (whether in the shell or in any language other you choose) and it is quickly a first class piece of your toolset. (This is the most common of the three to find in GUI land, though it often has limitations).
But not the good ones. Would you take a college class on programming from a professor who doesn't know how to use a terminal? I wouldn't.
If you are mocking people and their mothers on HN[1], you aren't a respectful person. Within this entire thread, you are being disrespectful, arrogant, and insulting. This isn't what HN is about.
Correct your tone or leave.
It's true that the comment you linked to was way out of line, but if you're going to ask other users to be civil, please be civil yourself. It takes restraint, but it's necessary.
Anyway today we can just sshfs and use even a random ide for everything so... we can do as we like.
Is that correct?
Sorry if this offends you, but how can you consider your self a programmer when you don't know how to use a terminal?
Say, at a Bash shell prompt in a terminal window, pressing Ctrl+R starts "reverse command search" mode, so that pressing letter keys searches for commands entered in the past, rather than entering a new command. In this mode, up and down move through search results, rather than moving through the entire command history like in "normal" mode.
Lots of software has modes, the unusual thing about Vim is that they have names, and that there is a mode with a focus on navigation.
The keyboard allows you to navigate too, without the need for a mode.
"Normal mode" (the most common mode other than insert mode) uses key bindings that wouldn't be possible in insert mode, rather than using the ctrl/alt/etc. keys for binding. For example, hovering over a word and typing ciw (change-in-word) will delete the word and place you in insert mode. There is a nice grammar and logic to the default key bindings (mostly.)
(IMO) When you are experienced with Vim you will spend most of your time in normal mode. This has a few benefits. For one, undo in Vim is "transactional" as you enter and leave insert mode (its a little more complicated but nevermind.) Everytime I have to use other editors (like VS with the VSVim extension) it drives me batty when I have to undo/redo one-character-at-a-time or with some time based batching that I don't understand. (Plug: the GUndo.vim plugin gives you a usable interface to Vim's undo tree. It's not super common for me to need this, but when I do it is a godsend. (If you've ever done undo, made some edits, and wish you hadn't undone after all, this is for you.)
One measure of effectiveness would be: to count the number of keystrokes needed to do something in vi compared to other editors.
Vi chose _a_ way of working. Turns out, a lot of folks have taken to it over the years. (And a lot haven't. They're nice people, too) :)
EDIT: fixed a typo
It's also not true that it's impossible to make other editors work like vi. evil-mode in Emacs lets you work like vi.
Having modes in a text editor also makes sense; modes provide affordances to get certain things done.
Why should I have to hold down a modifier key for 5 minutes? Just make it toggle.
Take that to its logical extension and you get modes, and they are beautiful.
And (c) about editing. Why type an extra character (i for insert) to let you insert? Why not just type to insert?
For me personally this is the reason I stopped using Vi(m) except for occasional config file editing on unfamiliar servers, and started looking elsewhere (Emacs) for my goto text editor. I'm not looking to switch, but it genuinely interests me how Vi users put up with the constant need to strain their pinky to switch to command mode.
Is it any different from how emacs users put up with Ctrl/Alt?
You aren't looking to switch, but if anybody is, install this https://github.com/tpope/vim-rsi for basic keybinding in insert mode. This is quite a short file. If you want, you can simply copy it to your .vimrc. For non-basic movement/editing, switch to normal mode and edit.
You can also use Ctrl-[ which I believe essentially sends an escape character to whatever program you happen to be running.
Both options should save your pinky!
Ctrl-A = 0x41 - 0x40 = 0x01 = SOH
Ctrl-I = 0x49 - 0x40 = 0x09 = Tab
Ctrl-M = 0x4D - 0x40 = 0x0D = CR
Ctrl-[ = 0x5B - 0x40 = 0x1B = Esc
Ctrl-@ = 0x40 - 0x40 = 0x00 = NULIs using macros' really common? I haven't yet figured out in when and where to use macros during my workflow.
1. Do the same thing 3 times, realize that I'll be done faster if I automate it. 2. qz to record a macro into buffer z. 3. Do the work, taking care to leave myself in a state where the next invocation of the macro will pick up right where I want it to. 4. q to finish recording. 5. :map <M-f12> @z to execute buffer z 6. Hit Alt-f12 over and over until I'm done.
Seems like a lot of steps, but it has saved me tons of time.
Of course, as the other commenter said, some folks don't use the feature. That's ok. There's room for all kinds :)
Or perhaps you're cleaning up a file, and there's a few common changes. Pop each into a macro and go to town. The low friction aspect makes them more common than the name might sound.
I have been wondering the same thing for some time. I always hear how great macros are, but haven't actually found a real world use case in my work.
But I figured it was because I didn't know something.
Everyone uses a slightly different subset of vim, in slightly different ways.
Don't worry about dogmas. Try everything out once, and keep what works for you!
What has been amazing so far is that even after using vim for almost 3 years, I'd been sort of afraid of diving deep into the config system (I made do with copy-pasting some popular vimrc files) and it was good enough, but in the short span of 2 days, I've actually gotten to know more about emacs configuration style than I ever did about vim. And I suspect it will only get better as I start to learn Emacs Lisp.
A few places where I looked for small things here and there:
1. http://www.emacswiki.org/emacs/Evil
2. https://github.com/cofi/evil-leader
3. https://stackoverflow.com/questions/8483182/evil-mode-best-p...
4. https://github.com/mixandgo/emacs.d/blob/master/my-evil.el
5. https://bling.github.io/blog/2013/10/27/emacs-as-my-leader-v...
And I also got ido-vertical-mode so the emacs command buffer looks better.
Here's my setup: https://github.com/mgill25/emacs See user.el
Cheers!
PS: Some of the configuration needs to be set up before you activate certain modes - which is often implicit in plugins, so watch out for that. Eg: To emulate C-u behavior, the functions had to be put ahead of the (require 'evil) call in evil-leader.el
For that matter, getting SLIME w/ vim to work w/ Tidal wouldn't be the hardest thing. It's just that no one has tried.
1. Install emacs. Start emacs. "Alt-x package-install" press enter "evil" press enter.
2. Open your .emacs or .emacs.d/init.el.
(require 'evil)
(evil-mode 1)
Done.I think we should stop trying to rationalize this choice.
Or rather, we should realize that we like text editors because we went through a long training and acquired complex skills which are fun to put in practice. Being a power user of Emacs or Vim is is satisfying, the same way mastering a video game is satisfying.
Weird, I know. But whenever I come back to Vim after straying for any amount of time, I just feel happy. Probably because I can do everything I want to do in the text without having to think about it.
It's like the nostalgia I get when the seasons change, and for a few days I can feel my childhood.
I get the "grass is greener" feeling sometimes, so I go looking to see if anything better has come along.
Then there's just the practical switch. My main job is in .net right now, while my home computers are all linux distros. It's made me search through a lot of editors to find something that runs well and feels good with windows.
I also just like to explore software, you know? A for instance would be Sublime Text. I've said it in a few other threads, but I do dig some of the features in ST2. They really did multiple cursors right. It's a really simple, but intuitive and powerful way to edit things. Using that on ST2 me want it everywhere else, and also made me fall in love with how they set up the command palette. Using emacs for a bit made me really dig how elisp worked. Light Table showed me another take on the integration of a language into the editor itself. So it's a lot of curiosity with that, and to know what's out there.
As an aside, if Neovim delivers it's promises, it'll probably solidify vim even further as my only editor of choice, but I'll still go looking around to see what other people are coming up with.
:wq
I want to like vim's window management but it's pretty quirky, at times it seems to be following the principle of most surprise.
Ideally one could use tabs (that aren't renamed to the buffer name when populating a named tab), splits, and buffers together in such a way that one's layout never, for example, collapses, leaving a single displayed buffer and N hidden ones, or a buffer getting cloned across 2 splits (the latter is pretty disorienting, unless I'm diff'ing versions of a file I don't ever want to see 2 versions of the code consuming visible screen area).
Granted am only 3 days into the vim WM experiment here, lot's to learn...
(It's the same as :wq, but one character shorter.)
As an aside, how does one keep up with Emacs package development? There is lots of stuff that's new to me (e.g. I just found out about company-mode). I'd like to have some way to have this information pushed to me, rather than having to go searching.
Something I would really recommend you: there are a lot of people in vim (like me) that have remaped the ESC key to a combination of keys (in my case jk); that is, by pressing j followed by k you go to normal mode (it's actually way faster than having to reach ESC). In vim, such thing is very easy; in emacs, you need to install the key-chord package, and something like the following would work:
(require 'key-chord) (key-chord-mode 1) (key-chord-define evil-insert-state-map "jk" 'evil-normal-state) (setq key-chord-two-keys-delay 1.0)
Relative numbers are very nice, as well.
By the way, regarding company-mode, I think autocomplete is newer and it's what most people are using nowadays.
I found out about a bunch of plugins through emacs live and prelude (and then switched to my own config). Take a look to other people's config on github :)
Add MELPA to your package sources, then just M-x list-packages here and there and check out anything new that looks cool.
Regular etags called with the emacs bindings worked just fine, but switching contexts from evil mode was a pain.
Many ways to edit a cat.
There's a lot of stuff that I wish were better in vim, but, at the end of the day, it gets my work done better than anything else out there, so I don't have any reason to move away from it. It works amazingly well with tmux (otherwise, I would be using emacs + evil -which I actually use for Clojure-). And I'm pretty excited about neovim :). They are doing an outstanding job.
So you're doing something weird, manually, but I repeat myself because if it was BAU you'd automate the whole process in puppet or similar. The local vim will work more or less like every other vim out there. Can't really say that with emacs.
If you're traveling somewhere weird, vim is a great travel companion. Not because it can be compiled anywhere (lots of editors can be compiled anywhere) but because it works the same anywhere.
In all my exploring of Emacs, I never saw a .emacs that wasn't completely tricked out with custom stuff that only works for that user.
Because of this, I believe you are correct - it's easier to work in a plain vi environment since we don't typically trick out Vim like our fellow Emacs users do with their environment.
My first dedicated text editor was BBedit (when it was still freeware), and for many years had extended experiments with other editors, always eventually returning to BBEdit. Something about it always clicked with me, and I felt like Siegel and co. fundamentally understood both the Mac and the needs of programmers.
These days I keep BBedit around for its excellent diff tool, syntax-highlighted multi-file grep search and replace, and its decent project browsing. But it's mostly a supplement to vim (MacVim), which I use all the time when I'm actually in there editing text.
[0] http://armedbear-j.sourceforge.net/
[1] https://github.com/kevinkrouse/j/tree/master/jBut my days of using straight Vim are over. For a straight text editor, I finally got over the hump with Emacs recently, and I'm not going back.