my .vimrc file

set nu
set bg=dark

"map the 'v' keystroke to mean 'save file unconditionally'
map v :w!
Advertisements

symlink/hardlink: Win7 or later

https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/ is a 2017 article.

The mklink command can create both hard links (known as “hard links” in Windows) and soft links (known as “symbolic links” in Windows).

On Windows XP, I have used “Junction.exe” for years, because mklink is not available.

c++split string on custom delimiter char

For a longer delimiter, you may need string.find()

ifstream f1(fileName.c_str());
string line;
while(getline(f1, line)){
  for(int i=1; ;++i){
        int pos = line.find_first_of("\t");
        string token = line.substr(0,pos);
        cerr<<i<<" : " <<token<<endl;
        if (line == token) break; //there's no more tab in the line
        line = line.substr(pos + 1);
  }
}

//a shorter method:
istringstream lineStream("denmark;sweden;india;us");
string token;
while (getline(lineStream, token, ';'))
        cout << token << endl;

from within bash script1 get script1’s dirname full path

readlink -f $0 # requires more steps, but takes care of symlinks. Seldom needed.

echo BASH_SOURCE gives "${BASH_SOURCE[0]}"

dirname "${BASH_SOURCE[0]}"
echo .. above dirname is often a relative path

fullpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo fullpath is $fullpath # fairly reliable one-liner, provided the script itself isn't a symlink

## vi (+less) cheatsheet

  • ~~~~ command mode #roughly ranked
  • [3] dt — “dta” delete until the next “a”
  • [2] 9s — wipe out 9 characters (including current) and enter insert-mode. Better than R when you know how many chars (9) to change
    • to delete 5 characters … there is NO simpler keystroke sequence
  • R — Overwrite each character one by one until end of line. Useful if the replacement content is similar to original?
  • Ctrl-R to re-do
  • cw — wipe out from cursor to end of word and puts you into insert mode
    • c2w or 2cw
  • :se list (or nolist) to reveal invisible chars
  • C — wipe out from cursor to END of line and puts you into insert-mode
  • capital O — open new line above cursor
  • A — to append at END of current line
  • from inside q(LESS), type a single “v” to launch vi

–paging commands in vi and less

  • jump to end of file: capital G == in both vi and LESS
  • jump to head of file: 1G == in both vi and LESS
  • page dn: Ctrl-f == in both; LESS also uses space
  • page up: Ctrl-b == in both; LESS also uses b

[3/4] means vi receives 3 keystrokes; we hit 4 keys including shift or ctrl …

vi on multiple files

[3/4] means vi receives 3 keystrokes; we hit 4 keys including shift or ctrl …

–“split” solution by Deepak

vi file1 # load 1st file

  • :sp file2 # to show 2nd file upstairs
  • :vsp file3 # to show 2nd file side by side
  • You end up with  — file2 and file3 side by side upstairs, and file1 downstairs!
  • [2/3] ctrl-ww # To move cursor to the “next” file, until it cycles back

–the q( :e ) solution

vi file1 # load 1st file

  • :e file2 # to put 2nd file on foreground
  • [1/3] ctrl-^ — to switch to “the other file”
  • This solution is non-ideal for moving data between files, since you must save active file before switching and you can’t see both files