Vim Tip of The Week : +[num] or +/{pat}
First let me start of by saying that if you haven’t yet taken the plunge to use vi/vim you really should. This editor will take you to levels of efficiency that you’ve only dreamed of, and probably beyond. Seriously, take the time to teach yourself some vim tips.
You might want to read a few of my previous posts on vim.
How to pwn your text files with vim
..and for those that want something more, let’s talk a bit about the +[num] and +/{pat} options when launching vim. These options will let you begin editing on a certain line number (+[num]) or at an instance of a certain pattern (+/{pat}). Let me show you a few examples.
If you’d like to begin editing a file on line 45 you could launch vim using a command such as:
vim file +45
If you’d like to begin editing at the last line in the file you could use +[num] without assigning a value:
vim file +
This option is really helpful for things such as trying to fix code or fixing syntax errors in configuration files. If the log displays the line number you could jump right to the line as you open the file. …and you thought the :[num] option was convenient!
vim file +185, vim file +2, vim file +823, etc.. simple ways to begin editing at a certain point.
The +/{pat} option lets you begin editing at the first occurrence of a certain pattern. This means instead of opening the file and beginning your search function you can use the search as you open vim. Some examples:
vim +/foo, vim +/bar, vim +/baz
You can use the :help search-pattern within vim to see available search patterns.
Anyway, I thought I would share this little tidbit of vim-awesomeness today. Hopefully I can continue to do a vim tip of the week. Would the faithful readers like that? Would you like more advanced vim options? Simpler tutorials? Are you happy with gedit and kate and don’t even want to bother? Let me know, I’ll do my best to help.