Friday, 24 February 2017

Revert changes in git


(1) How to revert files that are not staged in git?

For a specific file use:
git checkout path/to/file/to/revert

For all unstaged files use:

git checkout -- .
OR:
git checkout  .


(2) How to unstage a staged file?
git reset path/to/file/to/revert

(3) Is there a way to delete staged file completely?
 No, git reset will only unstage the staged files, it won't delete the changes,
if you want to delete it completely, you have to do git checkout in step one.

Thursday, 16 February 2017

42. How to show where the current repo is pulled from?


git remote show origin
* remote origin
  Fetch URL: git@github.ibm.com:llvm/llvm-on-power.git
  Push  URL: git@github.ibm.com:llvm/llvm-on-power.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Sunday, 12 February 2017

emcas replace-rectangle


Command    Key    Purpose
replace-rectangle    【Ctrl+x r t】    Replace text in a selected column.

try change this

 3c21 646f 6374
 6874 6d6c 3e3c
 2063 6861 7273
 202f 3e0a 3c6d
 6965 7770 6f72
 2277 6964 7468

to this

 3c21 cat 6374
 6874 cat 3e3c
 2063 cat 7273
 202f cat 3c6d
 6965 cat 6f72
 2277 cat 7468

    Put your cursor before “646f”.
    Call set-mark-command 【Ctrl+Space】.
    Move cursor to end of “6964”.
    Call replace-rectangle 【Ctrl+x r t】.

Saturday, 11 February 2017

How to Split Windows in Emacs?

How to Split Windows in Emacs?

C-x 2

Split the selected window into two windows, one above the other (split-window-below).
 
C-x 3
Split the selected window into two windows, positioned side by side (split-window-right).



In order to exit splitting windows mode, you have to use:
C-x 0 
 to quit the current window
C-x 1
to quit all the extended window, i.e just leave one copy of the same view.

Friday, 3 February 2017

What is the difference between emacs and vim?

From Stackoverflow:
 http://stackoverflow.com/questions/1430164/differences-between-emacs-and-vim
"With Emacs you are expected to have it open 24/7 and live inside the program, almost everything you do can be done from there. You write your own extensions, use it for note taking, organisation, games, programming, shell access, file access, listening to music, web browsing. It takes weeks and weeks till you will be happy with it and then you will learn new stuff all the time. You will be annoyed when you don't have access to it and constantly change your config. You won't be able to use other peoples emacs versions easily and it won't just be installed. It uses Lisp, which is great. You can make it into anything you want it to be. (anything, at all)
With vim, it's almost always pre-installed. It's fast. You open up a file do a quick edit and then quit. You can work with the basic setup if you are on someone else's machine. It's not quite so editable; but it's still far better than most text editors. It recognises that most of the time you are reading/editing not typing and makes that portion faster. You don't suffer from emacs pinkie. It's not so infuriating. It's easier to learn."

In my opinion:
 Vim mode switch is annoying and also slow. Although emacs need to type more keys for most of the
editing task, but since you don't need to switch between different mode, so it is still faster when you are familiar with it. Also as mentioned here, it is more extendable and can used everywhere (gdb, shell) etc.

Wednesday, 1 February 2017

emacs Erasing Text



DEL
BACKSPACE
Delete the character before point, or the region if it is active (delete-backward-char).
Delete
Delete the character after point, or the region if it is active (delete-forward-char).
C-d
Delete the character after point (delete-char).
C-k
Kill to the end of the line (kill-line).
M-d
Kill forward to the end of the next word (kill-word).
M-DEL
Kill back to the beginning of the previous word (backward-kill-word).

How to copy and past a line in emcas?


down voteaccepted

C-a C-SPACE C-n M-w C-y
which breaks down to
  • C-a: move cursor to start of line
  • C-SPACE: begin a selection ("set mark")
  • C-n: move cursor to next line
  • M-w: copy region
  • C-y: paste ("yank")