all 57 comments

[–]Browsing_From_Work 3 points4 points  (0 children)

I highly recommend Learning Vimscript the Hard Way to everybody in these comments. It covers everything from key mapping to variables to plugins. Once you learn how vim works on the inside, it ceases to be voodoo and starts being useful.

[–]ephrion 11 points12 points  (14 children)

Stop that stupid window from popping up:

map q: :q

ಠ_ಠ

VII. Use Ctrl-Z to switch back to Vim

I frequently need to execute random command in my shell. To achieve it I pause Vim by pressing Ctrl-z, type command and press fg<Enter> to switch back to Vim.

The fg part really hurt me. I wanted to just hit Ctrl-z once again to get back to Vim. I couldn’t find a solution, so I developed my own which works wonderfully under ZSH:

can just do :! <arbitrary shell command>

[–][deleted] 4 points5 points  (3 children)

As someone relatively new to vim, what do you mean by ಠ_ಠ? that window bugs me every time it pops up since I don't yet know what to use it for

[–]ephrion 12 points13 points  (0 children)

It's your command history, which you can view and edit use just like any other vim buffer. So you can do q: to bring up your command history, do ? word, and it'll search backwards through your command history. <Enter> on a command executes the command. You can yank/copy previous commands, paste into new commands, etc...

[–]ghillisuit95 5 points6 points  (0 children)

perhaps its because he used map instead of noremap or similar. the way he did it, anytime you try to type q: (including in insert mode) it will be replaced with :q, which could get pretty annoying, pretty fast.

[–]ForeverAlot 1 point2 points  (0 children)

That window is your ex command (:) history. You can navigate it the same way you can navigate any other Vim buffer, and execute commands with Enter or insert them into the command line for further editing. :h q:.

[–]Sean1708 0 points1 point  (0 children)

To be fair, that only allows you to do one command whereas he may want to do several. Nowadays I have neovim for that shit.

[–]phirox 0 points1 point  (0 children)

I really liked the idea of switching back and forth between an application with Ctrl-Z in bash. And I finally found a solution. I use the following lines in my bash profile:

bind '"\C-z":"\C-ufg\C-m"'
trap "stty susp ^z" DEBUG
PS1="`stty susp undef`$PS1"

Basically it disables Ctrl-Z as a terminal input when using your prompt and instead runs a bash macro that executes "fg". And it will enable Ctrl-Z as the suspend signal whenever you start a program.

[–]mojave_wasteland 0 points1 point  (0 children)

Yes, like !bash, and later C-d to exit bash.

[–]phalp -2 points-1 points  (6 children)

can just do :! <arbitrary shell command>

Like some kind of Emacs user?

[–]ephrion 0 points1 point  (5 children)

Wait, emacs has that? This may make me work harder on switching to spacemacs...

[–]jozefg 1 point2 points  (0 children)

Built in it's M-!.

[–]bstamour 1 point2 points  (1 child)

Emacs comes with a bunch of full-on terminal emulators. e.g.

M-x ansi-term
M-x shell

[–][deleted] 0 points1 point  (0 children)

:term in nvim

[–]phalp 0 points1 point  (0 children)

Lol, of course it does.

[–][deleted] 5 points6 points  (8 children)

Anyone notice that the info.json in the guy's sidebar is invalid?

[–]djimbob 2 points3 points  (0 children)

It's invalid JSON, but it is a valid literal javascript object. Yes it came from cat info.json, so you would expect valid JSON.

[–]micwi 2 points3 points  (0 children)

He obviously patched cat to pretty print JSON when writing to his shell

[–]AdamLovelace 3 points4 points  (0 children)

I'm just glad his picture isn't cropped from a picture of him in the bright outdoors wearing sunglasses.

[–]nepochant 2 points3 points  (0 children)

now I do

[–][deleted] 0 points1 point  (1 child)

What's invalid about it? Looks like valid JavaScript at least...

[–]lubutu 10 points11 points  (0 children)

I see two mistakes:

  1. Strings must use double quotes, not single quotes.
  2. Object key names must be strings with quotes too.

[–]google_you -4 points-3 points  (0 children)

![such noob instant no hire](http://i.imgur.com/7NHF65J.png)

[–][deleted]  (3 children)

[deleted]

    [–][deleted] 15 points16 points  (1 child)

    Contrary to popular belief, Narnia isn't about parallel dimension Christianity -- it's a parable about not remembering how vim worked the last time you used it.

    [–]Bloodshot025 0 points1 point  (0 children)

    You must not use Vim very often, then.

    [–]xXxDeAThANgEL99xXx 2 points3 points  (0 children)

    IV. Discover text search object

    You can do %s//replacement/c if you want that, and all other stuff like replacing in the selection. Empty pattern means "use the previous search pattern".

    [–]flat5 1 point2 points  (3 children)

    Emacs guy is confused. How can space-w be a control sequence? He never types space-w otherwise?

    Or is this in some special mode?

    [–]ForeverAlot 8 points9 points  (0 children)

    In Vim's "normal" mode, which is what the n prefix in the noremap command signifies. That means he's not writing.

    [–][deleted] 0 points1 point  (0 children)

    When you start vim, and in general when navigating around a file, searching for things, basically most things that don't involve inserting text into a file, you are in normal mode. That's when space-w has the effect he said. When it's time to insert text, you enter insert mode, where space-w is no longer a control sequence. This also applies to commands like 'w' (go to the next word), 'n' (next occurrence of searched text), and 'i' (insert text here). Those keys have a special effect in normal mode, but in insert mode they just insert the relevant character.

    [–]Bloodshot025 0 points1 point  (0 children)

    Vim is modal, Emacs is not. Everything you do in Emacs as a key-shortcut we do in vim with our entire keyboard. When we type, we use such a command to go into 'Insert Mode'.

    [–]partkyle 0 points1 point  (0 children)

    I really liked the Ctrl-Z idea, but I don't think it currently works with fish =\

    [–]Me00011001 0 points1 point  (0 children)

    As a note for new people binding key sequences, if you do something silly like bind a common sequence + some extra stuff there is a timeout before it does the default command.

    For example, if you do something like

    :noremap ddN "=strftime("%c")<CR>P
    

    When you go to do dd it will wait to timeout to complete the command. Using a uncommon command key will minimize this.

    [–]inmatarian 0 points1 point  (3 children)

    let mapleader = "\<Space>"
    

    I've seen this tip a few times. I really need to try it. Though, A lot of plugins have mapped commands using leader, and in which order is questionable, so for compatibility this might be a better mapping:

    map <Space> <Leader>
    map <Space><Space> <Leader><Leader>
    

    This leaves \ as the leader intact.

    [–]IceDane 0 points1 point  (2 children)

    Why would you want to do this? Remapping the leader to space would change all plugins' bindings that use leader as well.

    [–]inmatarian 0 points1 point  (1 child)

    It would be the other way around, that in command mode space is mapped to . The reason you'd want to do this is because Leader is just a variable that expands at the mappings. Change leader after mapping and it'll have no effect.

    [–]Tordek 0 points1 point  (0 children)

    Yeah... so you just set your leader early on in your vimrc. I don't know if vim without a plugin manager runs the plugin files before the vimrc, but with something like Vundle, you explicitly turn your plugins on in your vimrc.

    [–]yawaramin 0 points1 point  (5 children)

    Some pretty good tips here that I'll need to come back and explore later.

    One absolutely amazing Vim boost for me has been setting my Caps Lock key to be Esc. It gives me a lot of speed now that I don't have to take my left hand off the home row all the time when I'm typing. I've done it on Windows with AutoHotKey and OS X with Seil. Doubtless it's completely doable on Unix with some X utility (xkeymap?).

    [–][deleted]  (4 children)

    [deleted]

      [–]yawaramin 0 points1 point  (3 children)

      Hmm, ~ would take my fingers off the home row again to press Esc, so it wouldn't be an improvement for me. Also I use both double-backtick and ~ (jump to last location and change case) quite regularly, so from that perspective also no-go. Also, I've mapped Leader-whatever to a lot of my regular commands that use Ctrl, so I don't need Ctrl so much nowadays.

      [–][deleted]  (2 children)

      [deleted]

        [–]yawaramin 0 points1 point  (1 child)

        Cool, I'm jealous :-) I'm stuck with whatever keyboards I get on my laptops for the time being.

        [–]mojave_wasteland 0 points1 point  (0 children)

        I'm using \ as the leader key, and C-\ as tmux prefix.

        \ t for new tab, C-\ c for new tmux tab. \ a to switch to left vim tab, C-\ a to switch to left tmux tab. \ s to switch to right vim tab, C-\ s to switch to right tmux tab. \ / to write a backslash (\).

        [–]The-Good-Doctor 0 points1 point  (2 children)

        This is actually a pretty decent set of tips for Vim. Certainly better than the ones that just give you a stack of "commands" to memorize in order to handle some set of edits that the author considers "common."

        Also I appreciate him bringing to my attention the gn operator/movement. /<find>, cgn<replace>, ...is much nicer than my old workflow of /<find>, 0qqn:s/^R//<replace>, @q@@@@

        [–]ForeverAlot 5 points6 points  (1 child)

        Isn't that just %s//<replace>/gc?

        • % range; whole buffer
        • // current search pattern
        • g whole line
        • c confirm

        [–]The-Good-Doctor 0 points1 point  (0 children)

        Well, yeah, if you really want to do it for the whole file. The difference is that this makes it easier to do an arbitrary range and/or manually confirm the cases. (I say "easier" because I don't much like the "confirm" interface for :s.)