Sunday, November 13, 2016

Enabling C++11 in Eclipse Kepler/Luna CDT

When you are coding in C++ using eclipse IDE (installing CDT plugin)and if you use newer features of C++11 sometimes you might get errors when compiling. Reason for that might be you haven't enabled C++11 in Eclipse CDT. Lets see how to enable C++11 in Eclipse CDT. These steps are given assuming you are using GCC compiler. But steps are more similar to the other compilers as well.

Step 1 : Set up your compiler

  • Right click your project and click Properties
  • Under C/C++ Build click Settings
  • Under GCC C++ Compiler, click Miscellaneous
  • In the Other Flags box, append "-std=c++11" to the list of tokens
  • Click Apply and OK

Wednesday, November 9, 2016

Comment a code block in gvim


When we are coding we have to comment out some blocks of code and uncomment those time to time. It is easy with IDE like eclipse, netbeens, Visual Studio. I recently moved to vim and here is how to comment and uncomment in gvim. (lets assume character "#" is used for line commenting)

Method 1 

Command mode of vim used for this.
Use this command to comment lines from 10 to 15 with "#"
:10,15s/^/#
Use this command to uncomment lines commented before.
:10,15s/^#/

Method 2

VISUAL BLOCK mode is used for this.
  1. First, move the cursor to the first char of the first line in block code you want to comment. Then press Ctrl + v to enter VISUAL BLOCK mode
  2. Then move cursor with arrow keys to the end of code block that want to comment.
  3.  Then press Shift + i and cursor will come to the begining of code block
  4. The type the commenting character. In this case "#".
  5. Final press Esc and it will comment out the block you marked
To uncomment,

do the same things but instead of type Shift + i, you just type x to remove all # after highlight them in VISUAL BLOCK mode.

Monday, November 7, 2016

Select and replace strings in gvim


Here are some ways to replace strings in gvim.

For replacing a string across a file

:%s/<search_string>/<replace_string>/g

To replace in current line

:s/<search_string>/>replace_string>/

To select and replace words from selective lines in vim(In this example want to replace in line 6 to 10 and 14 to 18).

:6,10s/<search_string>/<replace_string>/g | 14,18&&
The :&& command repeats the last substitution with the same flags. You can supply the additional range(s) to it (and concatenate as many as you like):

If you have many ranges you can use loops as well.

:for range in split('6,10 14,18')| exe range 's/<search_string>/<replace_string>/g' | endfor
This four options can be used in almost any time that we want select and replace in gvim

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...