Vim is as powerful as your power armor but can be extremely lighter! I believe you click in to learn more about it. But here we don’t talk much about plugins. Just some tips I found along daily use of vim …

Vim Ads

Sorry before we jump in, here’s the ads :smile:.

Use Vim Today! Vim Today!

Tips

  • Remap Capslock: For a vim user, capslock can be nightmare. In mac you could easily remap it with Karabiner to something like Esc. In my dotfiles configuration, I remapped it to F10 and make it a prefix key for tmux.
  • Selection: v i t means select within tag. You can visual select in tag or block or word. Also you should arm with Pope’s surround plugin (you need some practices to master power of surround). Similarly working for y d etc. as well.
  • Numbers: when you have some text and number editing e.g. adding increasing number for each line. You could do this in command :put =range(1,10, 2)
  • Tabs: :retab will just remove every tabs into spaces (nice :relieved:)
  • Jump between tags: you could visually select around tag v+a+t and use o to switch.
  • Global variable: sometimes, you’d like to see the tab, and strange non-printable chars in your vim you could do :set list; for some files, you’d like to know the file format by :set ff? and yes this is actually a command to see and set global variables in vim! :set varname or :set varname?
  • Macro: q and then a register name to record it. @ or shift+2 to apply it. It’s simple but extremely useful. There are some complicate macro tricks to do numbers, or incrementally, but since I don’t usually use them and they just overflow, out of my memory :laughing:
  • Bookmark: m + a char to add and ' + the char to jump there and :marks to show all
  • Mysteriuos g: gf to open the file under cursor and gx to open it in xwindow system… ctrl+g to show file path information
  • History of command: q: and for macros we have :registers/:reg or :echo @a for a single register a
  • Window zoom fullscreen: ctrl+w, o
  • ctrl+r in Insert Mode and then = allows you do math or something more powerful e.g. =range(1,10)!
  • % is currentbuffer in ex command e.g. :Remove %.
  • '< and '> are start and end line of visual block. Therefore, for example, to replace extra spaces in your selection, you can do vim’s Regular Expression: '<'>s/\s\s\+/ /g.
  • reverse all lines :g/^/m0 which actually takes reg exp matched lines and then move them to line 0.
  • jumplist: jump to last edit/change location g+; and g+,
  • :vert diffs <tab> to simply vsplit buffer to diff

Reference

I found some really really nice presentation that worth a look: Erik Falor’s “From Vim Muggle to Wizard in 10 Easy Steps”; when you get totally naked in an alien linux server, watch this.