Showing posts with label Vim. Show all posts
Showing posts with label Vim. Show all posts

Thursday, August 15, 2013

Vim: Sort the file contents

Lets say you have a file that looks like this

and all you want to do is get the content rearranged in sorted order. Well here is a quickie , enter visual mode by pressing v , press Shift+g to select entire file and then just execute the sort command.
and bang here is the sorted content.

Sunday, August 11, 2013

Vim : Actually numbering the lines

You can always display line numbers inside vim with :set nu , little did I know of a way of actually inserting the line number inside the file .

Here is a cool trick for line numbering

  • Number all the lines in Vim

    • :%! cat -n 

  • Number only a portion of file contents
    • First enter the Vim visual mode by pressing v
    • select the portion that you want to number
    • then :'<,'>!cat -n





Saturday, August 10, 2013

Direct terminal output to vim

  • command | vim  -
  • e.g ls | vim -  and then :save fileName to store it.

Tuesday, August 6, 2013

Word wrap the contents of a file

    • :set wrap
How to open a file in Read Only mode

    • vim -R fileName
Dot Files

Make Vim even better with some dot files ( https://github.com/sontek/dotfiles ).
Handy Vim shortcuts

  • Line Numbers
    • Set line number with
      • :set nu
    • Unset line numbers with
      • :set nonu
    • Set relative line numbers with 
      • :set relativenumber.

  • Copy selected lines from vim visual mode to system clipboard.
    • "+y and then paste it outside vim.

  • Make vim paste the content from outside properly.
    •  :set paste
  • unfold code
    • zo
  •  fold code  
    • zc