random musings

Vim-multiple-cursors

These days most of the editors have some sort of facility to make same edit in multiple lines. With Visual Studio it is Alt + down-arrow, similarly other decent text editors (sublime-text, atom and brackets) have some built-in support for multiple-cursors.

I was wondering if vim has something of this goodness. Well vim has this support, you just need to check if your copy of vim was built with visualextra option or not.

checking vim information
1
2
3
4
5
6
7
8
9
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec  9 2014 17:36:18)
Included patches: 1-488
Modified by [email protected]
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
-text trimmmed-
+conceal         +libcall         +profile         +visualextra
-text trimmmed-

We are looking for presence of +visualextra option here, if present you can go into visual mode and add multiple cursors. To get this going open a file in vim, and position the cursor from where you want to start doing multiline edits. I would my cursor over to < at first line and then press Ctrl+V (assuming it is not mapped to paste) to move to block selection mode. Then press j key 10 times (i want to comment 10 lines) or press down-arrow key so many times. While doing all this vim will show that i am in VISUAL BLOCK selecion mode:

vim with file multiple-cursors-demo.rb open
1
2
3
4
5
6
7
8
9
10
11
12
13
<book id="bk111">
   <author>O'Brien, Tim</author>
   <title>MSXML3: A Comprehensive Guide</title>
   <genre>Computer</genre>
   <price>36.95</price>
   <publish_date>2000-12-01</publish_date>
   <description>The Microsoft MSXML3 parser is covered in
   detail, with attention to XML DOM interfaces, XSLT processing,
   SAX and more.</description>
</book>
~
~
-- VISUAL BLOCK --                                             1,1           All

Once you have 10 lines highlighted, press I character to go into insert mode (-- VISUAL BLOCK -- should change to -- INSERT --) and enter # character and then hit Esc key. All lines will be commented out, now you can do multiline comment in ruby with =begin and =end, so this was contrived example- but there are many situations where you want to append or prepend some text to existing variable- there it comes handy.

Note: vim can insert multiple cursors anywhere (as you specify with motion commands). That’s all for now

StackOverflow and Vim Wikia are generally pretty handy about such things.

Vim & Cscope

vim

vim what an editor! I am yet to find someone who used this editor but is neutral. Either folks love it or hate it. I think that is sign of a truly remarkable product, in sense it connects to core- evoking emotional reaction. It was not long ago i was in vim WTF camp. But had to spend a few weeks on linux and re-discovered vim. After about a month of usage vim is one of my preferred editors for code browsing- even on windows. :) Learning and getting used to vim took some time- especailly it was learning not to fight normal and insert mode. One my left little finger developed flesh memory of hitting esc key every now and then- life became much better with vim.

The other thing that makes vim awesome is plugin support and number of plugins available. I have been using ctags for quite some time- but started using cscope recently and love it. For mid sized projects it is quite fast and snappy and the code database makes all sorts of queries possible. Now that i found that it integrates well with vim. This post is about getting cscope hooked up in vim.

Notes on Git

Now that I moved my blog to github-pages generated by octopress, using git is the only way to make progress. Rather than digressing about my experiences @migrating from wordpress to octopress- I would rather keep this post as my notes on git

getting started

I find it interesting to learn by jumping-in rather than reading tons of volumes first. To get started you need to let git know that you are going to be setting a repository, this needs to happen in a particular directory- which contains stuff you want to manage. The command is:

1
2
git init .
Initialized empty Git repository in /home/sarangb/learn-git/.git/

Once an empty git repo is initialized now the next step is to add some content for git to track. Lets start by adding a a script that fetches weather information (just for fun). Once I have the script the next step is to let git know about it.

1
2
git add *.sh
git commit -m 'initial commit'

This will add all sh files to git, this is two step process:

  1. git add will add the files to a staging area, more on that shortly
  2. git commit will commit files in git repo

Now that scripts have been added. Say you need to tweak the script and recommit the changes.

1
2
git add *.sh
git commit -m "tweaked scripts"

Adding Extra Swap File on Ubuntu

Installed Ubuntu 15.04 on my low-key laptop and fire a build for llvm project. After a while ubuntu popped up internal error message. When I checked System Monitor- I ran out of RAM and Swap (4GB). So for sure I need more swap space on machine. Canonical as well as askubuntu.com have some good information on how to replace swap-files. Rather than replacing files- I am going to with adding another one. This time 16GB. Here are the steps, you will need superuser access- I prefer sudo to su.

First allocate 16GB memory and mount as 16gb.swap. Also ensure that this file can’t be read by anyone and fill it with zeros

Visual Studio Code Editor

Microsoft jumped into the pool to provide it’s own Cross Platform Code Editor. It is called Visual Studio Code, still in preview, and is available for download here

It looks very consistent with SublimeText look and functionality wise, and is quite snappy as compared to Atom for sure. The functionality is sparse and I expect things would get better from here. I have been a fan of SublimeText and Atom’s fuzzy search feature and VSC also supports the same for file only. Would be good if it would be extensible for searching for symbols.