Pages

Tuesday, May 27, 2014

Difference between running multiple bash commands using && vs ;

&& executes the next command only if the current command is successful
echo 'def' && sdaasf && echo 'abs' 
will print:
def
bash: sdaasf: command not found

while ; does not have this resrtiction
echo 'def' ; sdaasf ; echo 'abs'
will print:

def
bash: sdaasf: command not found
abs

Sunday, October 6, 2013

C pointer to const and const pointer

const int * ptr1 --> pointer to a constant. You cannot change the value of integer ptr1 is pointing to but you can change ptr1 to point to something else
int const * ptr2 --> Same thing
int * const ptr3 --> const pointer. You can change the value of integer ptr3 is pointing to but cannot change ptr3 to point to something else
http://duramecho.com/ComputerInformation/WhyHowCppConst.html

Friday, August 2, 2013

Vim cheatsheet

* - search word under cursor
:!time - execute shell command time
~ - change case of character under cursor
0 - goto start of line
$ - goto end of line
Ctrl+f - Page Down
Ctrl+b - Page up
e - forward one token
b - back one token
o - Add blank line after current cursor position and go to insert mode
O - Add blank line before current cursor position and go to insert mode
V1< or V3>: Indent a region
. - Repeat previous actions
df + key - Delete all characters in the line up till and including <key>
Shift+Delete - Delete all characters until end of line

When you don't know how many lines you wish to yank/cut use these commands:
mk - mark line
y'k - yank (copy)
d'k - cut

:e <filename> - open file for editing
:sp - split window horizontally
Ctrl+wv or :vs - split window vertically
Ctrl+ww - switch window
Ctrl+w = - Resize split windows to adjust to screen resolution
Ctrl+w r - Rotate windows in a row

Commenting multiple lines:
Ctrl+v to go into visual mode and select the lines you wish to comment. Pressing : will give you this prompt:
:'<,'> promt which you should extend to :'<,'>s/^/#/
Uncommenting lines:
Ctrl+v to go into visual mode and select the commented characters. Press x to delete them

http://vim.wikia.com/wiki/Cut/copy_and_paste_using_visual_selection
http://vim.wikia.com/wiki/Using_tab_pages