Hacker News new | past | comments | ask | show | jobs | submit login

What are the list of those individual "words". And what is the syntax for combining them?



This is the best explanation I've found so far: http://stackoverflow.com/a/1220118/3528


It was a very good read. But not what I was expecting. If vim is indeed speaking a language this is what I would expect a vim tutorial to have.

    1. Basic commands.
    2. Syntax to chain basic commands.
    3. Ability to form other commands from basic commands.
    4. Way to write macros.
Instead most vim tutorials I have read present with a list of several commands to memorize and then a cheat sheet to navigate you through a jungle. Often they are letters, and not meaningful words. So they are difficult to put into ones brain. Couple that with vim's modes. And you are set with a perfect recipe for disaster in case of a new bie.

If vim is indeed speaking a language than manuals and tutorials teaching it, must explain how to speak that language.

This is 2012 and the need to memorize commands, and read cheat sheets to edit text doesn't belong to our times.

What I seem to get is vim aims to provide sed, grep, tr, cut etc kind of tools inside a text editor in form of some interplay of letters and words. How I haven't figured out till today's date.

Every time I've tried to learn vim, I've quit trying to memorize 'yy P...' kind of commands. That happens as I first can't memorize random arrangement of characters. Secondly if its not random, I've not understood how to arrange and use those letters to make meaningful commands.


1. "Basic commands" are what you know after 30 minutes of

    $ vimtutor
2. "Syntax to chain basic commands" is what you get when you think about what you are going to do. Like in any spoken or written language: "copy this line and paste duplicate it 10 times above" would be

    yy  copy this line
    10P paste above, 10 times
You have verbs (yank, paste, delete, join, move down…), direct objects (this word, this line, this html tag, this function, this paragraph…), indirect objects (up to this word, between line y and line x…) and, well… "counts" to do all that multiple times.

Vim's language is a lot more natural and intuitive and efficient than any variant of Cmd+Left - Shift+Ctrl+Right - Right - Cmd+c - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v - Down - Cmd+v

Saying it's too arcane/complex/hard is just lying or being lazy.

3. "Ability to form other commands from basic commands" is achieved by writing small (or big) functions and bind them to your own commands.

4. "Way to write macros" is by not writing macros. You record a sequence of commands/keystrokes and run it later:

    qa   record a macro in register a
    yypj duplicate this line and move to the line below
    q    stop recording
    10@a apply the macro 10 times
No need for a cheat sheet if you are commited and don't rush it.


Yup, you start with #1 there.

#2 doesn't really exist, so no need to learn it.

#3 is just using the commands in sequence. They aren't new commands.

#4 is advanced and I've never had a need for it yet.

Let's pick some apart:

ddp:

dd - delete line

p - paste line below

This swaps a line because when you delete a line, the line below it moves up and you end up on that line. When you paste an entire line, it pastes to the next line.

ddkP:

dd - delete line

k - move up 1 line

P - paste line above. (Shift usually means 'opposite direction', so it pastes above instead.)

I don't think of these as commands as such. I just think, I want to delete this line, and then I want to place it here. He's providing these as commands to show that Vim can handle the same features as Sublime Text, but he's doing it in a non-Vim way, as far as I'm concerned.

You don't memorize non-basic commands. You just use basic commands until you get what you need, and it happens that the advanced commands for most other editors can be done with just the basic commands of Vim.


He's providing these as commands to show that Vim can handle the same features as Sublime Text, but he's doing it in a non-Vim way, as far as I'm concerned.

I'm all ears. What would be the Vim way?


As I said, learning the basic commands and using them. There's no need to remember a key combo for 'swap lines' because it's just 2 basic commands used in succession. I never even think of it as 'swap lines' because what I want to do is remove a line, then place it somewhere else. And that's what the commands are in Vim to make it happen.


That's how I constructed the above list in the first place, but I get what you mean; you shouldn't be learning these as Street Fighter-like combos.


Based on this comment I think it's possible that vim isn't for you and you would probably be better suited to something like Sublime or TextMate.


Why would that be, vim seems to be difficult to use because a good manual that actually teaches how to use vim isn't available yet.

In fact it was surprising to me when I learned vim commands are actually a form of some terse language. Because I was only of an assumption that most vim commands are random string of characters you need to memorize. And when you memorize and practice enough you become productive.

I would be definitely well suited for vim, because I like terse language paradigms in unix like sed, awk, perl. I think if I had known about these aspects of vim a while back. I would have tried to write a few essays myself to understand using vim effectively.

I feel tempted to give vim a try now.


> Why would that be, vim seems to be difficult to use because a good manual that actually teaches how to use vim isn't available yet.

What manuals have you tried? Have you tried `vimtutor`(if vim is installed, just run vimtutor from the sell).

> In fact it was surprising to me when I learned vim commands are actually a form of some terse language. Because I was only of an assumption that most vim commands are random string of characters you need to memorize. And when you memorize and practice enough you become productive.

You need to know a lot of words before you can form intelligible sentences. There is no not-knowing `h,j,k,l,esc,d,x,p,b,w,i,I...`. So yes, you do need to memorize basic operations before you can chain them. Most of the things in this cheatsheet are important to know http://tnerual.eriogerg.free.fr/vimqrc.pdf

And once you have learnt the basic, there is no manual to tell you how to combine them, because there is no syntax to do it - you just run them in sequence. It has already been pointed out in the SO thread, and various other threads here.

> I feel tempted to give vim a try now.

Your temptation will last all of 1 day. If you give up, vim isn't for you. It takes a minimum of 15 days to a month to s top missing whatever editor you are using right now, then another month to actually start liking it.


I am emacs user. The problem isn't patience with vim. The problem really is deciphering the `h,j,k,l,esc,d,x,p,b,w,i,I...` sequence.

So as long I can't make sense of what random stream of characters mean, any amount of practice to put them into finger memory is going to be a exercise in frustration.


> The problem really is deciphering the `h,j,k,l,esc,d,x,p,b,w,i,I...` sequence. > So as long I can't make sense of what random stream of characters mean, any amount of practice to put them into finger memory is going to be a exercise in frustration.

That wasn't a sequence - that was basic movements and operations you need to compose sequences.

h,j,k,l is as intuitive as it gets http://wireless.ictp.trieste.it/school_2003/docs/linux/linux...

Rest of the basic movements are mostly mnemonics

w - move forward a word

b - move back a word

e - move to the end

d - delete followed by movement

You use these to formulate sequences.

d2w - delete 2 words

d2b - delete 2 words backwards

d2w2j - delete 2 words and move 2 lines up

d2w2jp - delete 2 words, move 2 lines up and paste(what was deleted)

d2w2j^p - delete 2 words, move 2 lines up, go to beginning of line(^) and paste(the deleted words)

df)/test$F{p

delete till ) (df)), search forward for test (/test), go to end of line where search is found($), search backward for { (F{), and paste(p)

They aren't random stream of characters if you know basic movements and operations.

As far as emacs goes, I find vim to be superior when it comes to navigation. When I am using emacs, I have a minimal configuration file for a few things I absolutely need:

    ;; General settings.
    (setq transient-mark-mode t)
    (line-number-mode t)
    (column-number-mode t)
    (global-hl-line-mode t)
    (setq-default indent-tabs-mode nil)
    (global-font-lock-mode t)
    (setq-default fill-column 120)
    (setq auto-fill-mode t)

    (define-key global-map "\C-xw" 'what-line)
    (define-key global-map "\C-z" 'undo)
    (define-key global-map "\M-g" 'goto-line)
"M-x goto-line line-number <CR>" is just too much typing for going to a specific line.

What emacs wins at is external tools integration. Vim doesn't support async command integration, and per the developers, never will. Vim developers believe vim is a text editor, and it has no business running shells; a stance I am ok with. But that means there never will be a slime for vim, at least not the way it works for Vim i.e you can't execute chunk of code, and be dropped in a debugger if an exception occurs. And there will never be a debugger which seamlessly integrates with vim. I do miss these things sometimes, but there are decent alternatives - I love my zsh, don't need it in an editor; slime, sans debugger is just configuring vim to send selection to repl etc etc.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: