Automatic Comment Prefixing Revisited

A while back, I wrote about removing Vim’s automatic comment prefixing. This behaviour is turned on by default, and is best shown with an example:

# some comment {cursor here}

If I was to hit o or O, to insert on the line above/below, or be in insert mode and hit enter, Vim would automatically add the comment prefix for me, so it would look like this:

# some comment
# {cursor here in insert mode}

Vim has automatically added the # for me.

I am not a fan of this, and in my original post I advised adding this line to your vimrc to fix it:

set formatoptions-=or

However, that stopped working for me (I’m not sure when – or if it’s related to a new Vim version). Today I managed to figure out the solution. This line does the trick:

autocmd FileType * setlocal formatoptions-=r formatoptions-=o

To be honest, I’m not sure why the original doesn’t work, and if anyone does, please leave a comment, as I’d be really interested to know why. If you’ve had the same problem, try the new line and see if that solves it.

comments powered by Disqus… Click Here

Stop Vim being slow when using rbenv

Note: I have now found a better solution to this problem, which I have documented. I suggest you use that solution over this one.

A lot of people, like me, use rbenv to manage Ruby versions on their machine. When I first set it up, I would see a large lag when opening a Ruby file in Vim. After a bit of Googling, I stumbled upon a solution.

Putting this into my .vimrc sped things up quite a bit:

let g:ruby_path = system('echo $HOME/.rbenv/shims')

If you’ve been struggling with Ruby slowness and are using rbenv, give that a go. If you use RVM, there’s a similar fix:

let g:ruby_path = system('rvm current')

comments powered by Disqus… Click Here

Sorting a selection

Today at work a colleague suggested ordering a hash of key / value pairs alphabetically to provide a bit of order. I agreed and then set about figuring out how to do it in Vim. This was the starting hash:

{
  "foo" =2,
  "bar" =3,
  "baz" =4,
}

Expecting some complex solution involving some form of regex searching, Vim surprised me with its built in sort functionality. All I did was highlight the keys within the object, and then hit :sort u:

{
  "bar" =3,
  "baz" =4,
  "foo" =2,
}

The u means duplicate lines will be removed. :help sorting has a great run down of all the options.

The Vim wiki has some useful other things it can do, too.

comments powered by Disqus… Click Here

Vim Startify

Today I found a handy little Vim plugin called Vim Startify.

It adds a small splash screen to the Vim intro screen that shows recently edited folders and also allows you to add bookmarks for files you commonly edit (your ~/.vimrc, perhaps).

I installed it this morning and so far it’s been really useful. It’s very basic and doesn’t add too much but the ability to hop to recently edited files (I’m forever loading Vim and finding the same file to edit) and also bookmarking files (in particular my Vim and ZSH configuration files).

comments powered by Disqus… Click Here