re: What's your favorite Vim trick? VIEW POST

FULL DISCUSSION
 

Here are a number of tricks in core Vim I've found useful over the years:

  • CTRL-p completion - it just completes identifiers in the current file (well, you can enable it to complete more things via the complete option), but often that's good enough!
  • Speaking of completion, there are all of the various completions hanging off of CTRL-x - I use CTRL-x CTRL-f to complete filenames all the time, and I use CTRL-x CTRL-l to complete lines way more often than I probably should =)
  • Using :normal to run Vim commands across an entire file or a selection is really nice - it provides a nice alternative to macros (which are also quite handy)
  • I use :%!command all the time for arbitrary text processing - especially :%!perl.
  • Special registers, especially used in combination with CTRL-r, which inserts a register in insert mode:
    • +/* - clipboard registers
    • " - last yanked text (useful if you want to type some text, paste what you yanked, and then type a little more)
    • . - last inserted text (useful if you want to replace different motions with the same text)
    • = - expression register (useful for things like inserting the current directory with CTRL-r =getcwd())
    • CTRL-w - current word under the cursor (I use this with :Pydoc CTRL-w to look up the documentation for the word under my cursor)
    • / - current search (I will often do a search, and then do /\C<C-r>/ to enable case sensitivity for the current search, or wrap the current search via /\C\<<C-r>\> to search for only the target word and not words containing the search as a substring)
  • CTRL-f in the command line to open a command line editor, which allows you to fix previous command lines using Vim commands
  • g-/g+/:earlier/:later to traverse history by time, rather than undo order
  • Running vim filename +line_num to seek to line_num from the start, and vim filename +/pattern to start searching for pattern from the get-go
  • >'] to indent the last paste (the [ and ] registers contain the start and end locations of the last changed or yanked text)

And it's not technically a Vim trick, per se, but I like running my shell in Vi mode!

code of conduct - report abuse