2017年11月20日 星期一

Vim Plugin Howto: NERDTree





1. NERDTree
  a. ":NERDTree" to open NERD Tree in vim
  b. "Up" : to move up cursor
  c. "Down" : to move down cursor
  d. "Enter" : to open a directory
  e. "o": to open a file
  e. "H" :to show or hide hidden files
  f. "R" : Refresh the tree, useful if files change outside of Vim
  h. "m" : show the NERD Tree menu
  i. "?" : NERD Tree quick help
  j. ":q" : exit 



Refer to:
  https://medium.com/usevim/nerd-tree-guide-bb22c803dcd2



2. CScope
1. Run cscope
cscope -R -b
2. 


 Ctrl-]  : split horizontal pane (editing new buffer)


 Ctrl-w s or ":spit" : split horizontal pane (editing current buffer)
 Ctrl-w v or ":vsplit" : split vertical pane (editing current buffer)





Refer to:









2017年11月17日 星期五

vim plugin manager : vim-plug


1. Automatic Installation (load plug.vim to ~/.vim/autoload/plug.vim )
Place the following code in your .vimrc before plug#begin() call
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
Note that --sync flag is used to block the execution until the installer finishes.

2. Migrating from other plugin managers
Download plug.vim in autoload directory
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
and update your .vimrc as needed.
With Vundle.vimEquivalent vim-plug configuration
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'junegunn/seoul256.vim'
Plugin 'junegunn/goyo.vim'
Plugin 'junegunn/limelight.vim'
call vundle#end()
filetype plugin indent on
syntax enable
call plug#begin('~/.vim/plugged')
Plug 'junegunn/seoul256.vim'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
call plug#end()
vim-plug does not require any extra statement other than plug#begin() and plug#end(). You can remove filetype offfiletype plugin indent on and syntax on from your .vimrc as they are automatically handled by plug#begin() and plug#end().




Refer to:
  https://github.com/junegunn/vim-plug/wiki/faq





Split windows in Vim


1. Splitting panes

 Ctrl-w n  : split horizontal pane (editing new buffer)

 Ctrl-w s or ":spit" : split horizontal pane (editing current buffer)

 Ctrl-w v or ":vsplit" : split vertical pane (editing current buffer)

2. Closing panes

 Ctrl-w c  or ":q": close pane

 Ctrl-w o  : close all panes, only current pane opened


3. Navigating panes

 Ctrl-w w  : switch to next pane
 Ctrl-w p  : switch to previous pane

 Ctrl-w Up  : switch to up pane
 Ctrl-w Down  : switch to down pane

 Ctrl-w Left  : switch to left pane
 Ctrl-w Right  : switch to right pane


Refer to
  http://codeincomplete.com/posts/split-windows-and-tabs-in-vim/




















tmux installation & easy guide

For Ubuntu

tmux installation

sudo apt-get install tmux

Easy Guide

1. Run tmux
tmux
2. All commands in tmux are triggered by a prefix key followed by a command key (quite similar to emacs). By default, tmux uses Ctrl-b as prefix key. Thus Ctrl-b simply means press the Ctrl and b keys at the same time.

3. Splitting panes
 Ctrl-b %  : split horizontal pane

 Ctrl-b "  : split vertical pane

4. Navigating panes
 Ctrl-b Left  : switch to left pane

 Ctrl-b Right  : switch to right pane

 Ctrl-b Up  : switch to up pane

 Ctrl-b Down  : switch to down pane

 Ctrl-b p  : switch to previous pane


 Ctrl-b n  : switch to next pane


5. Adjust pane size
 Ctrl-b Ctrl-Left  : resize horizontal pane

 Ctrl-b Ctrl-Right  : resize horizontal pane

 Ctrl-b Ctrl-Up  : resize vertical pane

 Ctrl-b Ctrl-Down  : resize vertical pane

 Ctrl-b z  : make a pane go full screen or to shrink it back to its previous size


6. Closing panes / window
 Ctrl-b d  or exit : close pane or window



Refer to
  http://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/




















2017年11月15日 星期三

Git, remote: error: inflate: data stream error (incorrect data check)

1. Find a local repository that cloned from a corrupted repository
2. To create a new repository in remote side

git init --bare <new repo>

3. The best thing I can think of would be to pull a local copy, change the origin to the new server, and then push:

git pull --all
git remote rm origin
git remote add origin <new repo address>
git push --all --repo=origin


4. Run "git fsck --full" at remote side. Tar and remove bad_repo if everything is ok. Finally, rename new_repo to bad_repo.

git fsck --full
tar -zcvf bad_repo.tar.gz bad_repo
rm -rf bad_repo
mv new_repo bad_repo

Refer to:
  https://stackoverflow.com/questions/11565882/how-to-move-git-repositories-from-github-to-local-server-running-gitolite/37254780


2017年11月14日 星期二

My favorite Git Setting

For Ubuntu



function git_branch {
    ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
    echo "("${ref#refs/heads/}") ";
}

function git_since_last_commit {
    now=`date +%s`;
    last_commit=$(git log --pretty=format:%at -1 2> /dev/null) || return;
    seconds_since_last_commit=$((now-last_commit));
    minutes_since_last_commit=$((seconds_since_last_commit/60));
    hours_since_last_commit=$((minutes_since_last_commit/60));
    minutes_since_last_commit=$((minutes_since_last_commit%60));
    
    echo "${hours_since_last_commit}h${minutes_since_last_commit}m ";
}

PS1="[\[\033[1;32m\]\w\[\033[0m\]] \[\033[0m\]\[\033[1;36m\]\$(git_branch)\[\033[0;33m\]\$(git_since_last_commit)\[\033[0m\]$ " 



Install git-core & bash-completion

sudo apt-get install -y git-core bash-completion



vim ~/.bash_profile & add
# for bash-completion
#[ -f ~/.git-bash-completion.sh ] && . ~/.git-bash-completion.sh



For CentOS


Refer to:
  1: https://ihower.tw/blog/archives/5436  









2017年11月13日 星期一

Can ping internet and local network, but not gateway


Method:
  1. netstate -rn
  2. ifconfig -a
  3. ping local_machine_ip
  4. pint www.google.com
  5. ping gateway ip
  6. nslookup



Refer to:
  https://www.centos.org/forums/viewtopic.php?t=39617


2017年11月8日 星期三

Missing Icons on Ubuntu



  1.  System Settings / Appearance


  2. Select Wallpapers & Theme, Icons and background of terminal will come back




How to Fix VMware Bridged Network have no Internet Access!


Symptom:
  1. Bridged Network have no Internet Access
  2. NAT Network Manual mode have no Internet Access
  3. NAT Network DHCP mode have Internet Access

Steps to solve --------
  1. VMware / Edit / Virtual Network Editor



  2.  VMnet0 disappeared



  3.  Change Settings & Restore Defaults, VMnet0 come out again



 

Refer to:
  https://www.youtube.com/watch?v=BUdLvzIB9Ag

2017年11月7日 星期二

Disable / Remove thinclient_drives


sudo vim /etc/xrdp/sesman.ini
[SessionVariables]
PULSE_SCRIPT=/etc/xrdp/pulse/default.pa
CHANSRV_LOG_PATH=/tmp



2017年11月3日 星期五

VirtualBox Error: creating process for virtual machine (gui/qt)


很可惜無法確認是哪個步驟有效, 只最後將 host 重新開機, 然後, 開 VM Guest OS 就沒有相關的訊息.

------------------------------------
Kernel driver not installed (rc=1908)

2017年11月2日 星期四

How to mount a NTFS drive on CentOS 7

1. Install NTFS related stuffs


sudo yum install ntfs-3g
sudo yum install fuse
sudo modprobe fuse


2. Run GUI => Applications / Utilities / Disks
Select NTFS drive and play it. It will create a mount point automatically.

3. List disks & partitions


sudo lsblk -f


Refer to:
  1. https://www.phpini.com/linux/rhel-centos-fedora-mount-ntfs-partition