Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created March 17, 2016 17:52
Show Gist options
  • Select an option

  • Save ehzawad/22181e09bd4055aa74c2 to your computer and use it in GitHub Desktop.

Select an option

Save ehzawad/22181e09bd4055aa74c2 to your computer and use it in GitHub Desktop.

Two best websites for Vim

http://www.vimcast.org/

http://www.vimgenius.com/

for checking and changing Linux timeZone

sudo dpkg-reconfigure tzdata

date

date -u

// few good websites for learning code http://www.codingfriends.com/

// hard way http://c.learncodethehardway.org/book/

// VIM Clipboard Copy Paste

yanking(coping ) y+"

pasting "+p

" Vim Vundle PLugin manager vim +BundleInstall +qall

" better visual mode Suppose you type visualize a block of a text { .......... } or ( .......... )

to do this suppose ..you are in a function block then put the cursor in { or ( then enter in visual mode and press %

" spliting = for equalizing vim window in buffer

" buffer memory in vim :sb 1 :vert sb 3

but see buffers using :ls

" Xfce terminal theme location file /usr/share/xfce4/terminal/colorschemes/

" go back to previous location Use `` to jump back to the exact position you were in before you searched/jumped, or '' to jump back to the start of the line you were on before you searched/jumped.

CTRL+O and CTRL+I, for jumping back and forward. for more read :h jumplist

remember delete word in insert mode

" hotkey in insert-index ...for more :help inser-index CTRL-H delete the character in front of the cursor (same as ) CTRL-W delete the word in front of the cursor CTRL-U delete all characters in front of the cursor (influenced by the 'backspace' option)

h move cursor left l move cursor right j move cursor down k move cursor up

" hey hey back you to normal then again insert mode ...handy right!!

" Other useful delete word to the left of cursor D delete everything to the right of cursor delete everything to the left of cursor backspace/delete insert newline (easier than reaching for the return key) indent current line un-indent current line

" copying from the register :put [reg]

" open empty buffer in split window :new >>>>> for horizontal :vnew >>>> for vertical

" diff :diffs :difft

" While in insert mode, you can use Ctrl-R {register}, where register can be:

  • for the clipboard,
  • for the X clipboard (last selected text in X), " for the unnamed register (last delete or yank in Vim), or a number of others (see :h registers). Ctrl-R {register} inserts the text as if it were typed.

Ctrl-R Ctrl-O {register} inserts the text with the original indentation.

Ctrl-R Ctrl-P {register} inserts the text and auto-indents it.

Ctrl-O can be used to run any normal mode command before returning to insert mode, so Ctrl-O "+p can also be used, for example.

For more information, view the documentation with :h i_ctrl-r

" ow press the selected word in normal or visual mode * or # for better and quick search

" swipe split window in vim r

" git resources http://cs61.seas.harvard.edu/wiki/2015/Git http://ndpsoftware.com/git-cheatsheet.html#loc=remote_repo

" gitignore files for ignoring unnecessary files Create a local .gitignore

If you create a file in your repository named .gitignore, Git uses it to determine which files and directories to ignore, before you make a commit.

A .gitignore file should be committed into your repository, in order to share the ignore rules with any other users that clone the repository.

GitHub maintains an official list of recommended .gitignore files for many popular operating systems, environments, and languages in the github/gitignore public repository.

In Terminal, navigate to the location of your Git repository. Enter touch .gitignore to create a .gitignore file. The Octocat has a Gist containing some good rules to add to this file.

If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:

git rm --cached Create a global .gitignore

You can also create a global .gitignore file, which is a list of rules for ignoring files in every Git repositories on your computer. For example, you might create the file at ~/.gitignore_global and add some rules to it.

Open Terminal. Run the following command in your terminal: git config --global core.excludesfile ~/.gitignore_global The Octocat has a Gist containing some good rules to add to this file.

Explicit repository excludes

If you don't want to create a .gitignore file to share with others, you can create rules that are not committed with the repository. You can use this technique for locally-generated files that you don't expect other users to generate, such as files created by your editor.

Use your favorite text editor to open the file called .git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.

In Terminal, navigate to the location of your Git repository. Using your favorite text editor, open the file .git/info/exclude. Further Reading

" git special command git remote show git remote show origin

vim COPY-PASTE Functionality For example, you could select the text hello then type "ay to copy "hello" to the a register. Then you could select the text world and type "by to copy "world" to the b register. After moving the cursor to another location, the text could be pasted: type "ap to paste "hello" or "bp to paste "world". These commands paste the text after the cursor. Alternatively, type "aP or "bP to paste before the cursor.

vimcast.org

http://vimcasts.org/episodes/archive/

uppercase and lowercase

~

vim undo branches

g+ g-

swap character

xp in NORMAL Mode

In vim hit to escape from commandWindow

move according to percentage

35% in normal mode to go to the 35 percent in buffer

removing a directory

rmdir only remove an empty directory

to create multiple files

ball.c baz.c hell.c

touch {hell.c,baz.c,ball.c}

what is header file? clang++ -E cpp.cpp > header.cpp

what are compilation process of c and cpp in clang

OPTIONS Stage Selection Options -E Run the preprocessor stage.

   -fsyntax-only
       Run the preprocessor, parser and type checking stages.

   -S  Run the previous stages as well as LLVM generation and optimization stages and target-specific code generation, producing an assembly file.

   -c  Run all of the above, plus the assembler, generating a target ".o" object file.

   no stage selection option
       If no stage selection option is specified, all stages above are run, and the linker is run to combine the results into an executable or shared library.

" vim folding tips zi to toggle the folding " gitter git log git show hash-key git status

to back to head of the git repo

git checkout master

to go to specific log hash

git checkout hash-key

" some useful command of netrw D ---- delete file or directory gb ---- go to previous bookmarked directory gh ---- Quick hide/unhide of dot-files o ---- enter the file/directory in horizontal(default) window p ---- preview the file P ---- Browse in the previously used window qb ---- list bookmarked directories and history qf ---- display the file information r ---- reverse the sorting order R ---- Rename the file or directory s ---- seleting sorting style (name, time, file-size) % ---- create a new file t ---- open file in new Tab d ---- create a new directory You can press <c-w=> to resize all windows to be the same.

lazy mnemonic open file explorer :e. :edit . at current working directory :sp. :split . in split at current working directory :vs. :vsplit . in vertical split at current working directory :Ex :Explore at directory of current file :Se :Sexplore in split at directory of current file :Vex :Vexplore in vertical split at directory of current file

Ctrl-w = tells Vim to resize viewports to be of equal size.

Ctrl-w - reduce active viewport by one line.

Ctrl-w + increase active viewport by one line.

Ctrl-w q will close the active window.

Ctrl-w r will rotate windows to the right.

Ctrl-w R will rotate windows to the left.

to insert text from register in insert mode <C+r>{reg}

cd - " very useful command

/* to read the object file */

objdump -t something.o

http://kickasstorrent.proxyindex.net/

sudo apt-get install update-manager-core sudo do-release-upgrade

" cryptography error when update PHP

GPG error: http://ppa.launchpad.net trusty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6C

gpg --keyserver pgpkeys.mit.edu --recv-keys 4F4EA0AAE5267A6C

gpg -a --export 4F4EA0AAE5267A6C | sudo apt-key add -

" solve dpkg error sudo dpkg --configure -a sudo apt-get -f install

sudo dpkg -i --force-overwrite sudo dpkg -i --force-overwrite /var/cache/apt/archives/apache2_2.4.16-4+deb.sury.org~trusty+4_i386.deb (for example)

hash mismatch error while updating

Just remove all the content of /var/lib/apt/lists directory:

sudo rm -rf /var/lib/apt/lists/* then run: sudo apt-get update

http://www.scs.stanford.edu/11au-cs144/ (Networking)

encryption https://futureboy.us/pgp.html#PublicKeyCrypto

sudo apt-get update sudo apt-get install -y python-software-properties software-properties-common sudo add-apt-repository -y ppa:pi-rho/dev sudo apt-get update sudo apt-get install -y tmux=2.0-1ppa1t now if you do tmux -V it should show tmux 2.0 which is a good version for tmux plugins I verified the above steps on a new digitalocean droplet.

Basically, it's adding the pi-rho/dev repository, updating and then installing tmux from there.

SMYCK theme

/usr/share/xfce4/terminal/colorschemes/

The * register will do this. In Windows, + and * are equivalent. In unix there is a subtle difference between + and *:

Under Windows, the * and + registers are equivalent. For X11 systems, though, they differ. For X11 systems, * is the selection, and + is the cut buffer (like clipboard).

  • is probably what you want most of the time, so I use * because it functions as I expect it to in both environments

" update vim bundle Plugin for command line vim -c VundleUpdate -c quitall

" root sudo su or sudo su - or su

remember.... It is a good choice to select ubuntu main server

" count the number of words in buffer g then " for pattern count :%s/patter//gn or g then

" MYSQL in Command Line mysql -uroot -p

show databases;

ghc HASKELL Compiler

vim >>>> to move start of the previous line use - "OOPs that is dash to move start of the paragraph use { for end use } in normal mode CTRL-R=1*9 CTRL-W delete preceding word in insert mode CTRL-O is useful in insert mode

  • next occurences and # for previous occurences

TYPEDEF (Defining shorthand your own data type) the basic idea is to first define a type in normal way, then alias it to something else

always use....sudo composer selfupdate

In order to set the window's width to let's say exactly 80 columns, use

CTRL+W |

" list of all clang flag clang -cc1 --help

HASH MISMATCH ERROR FIXATION

Just remove all the content of /var/lib/apt/lists directory:

sudo rm -rf /var/lib/apt/lists/*

then run:

sudo apt-get update

vim one single tips

Don't use cw use ciw

if you want to know localhost IP

ip route get 8.8.8.8 | awk '{print $NF; exit}'

Linux third library To find to which package your include file (X11/extensions/XTest.h) belong to, install apt-file and search for it, example:

sudo apt-get install apt-file sudo apt-file update sudo apt-file search "X11/extensions/XTest.h" libxtst-dev: /usr/include/X11/extensions/XTest.h Once you've the package name, install via:

sudo apt-get install libxtst-dev This method is especially useful when there are more similar dependencies like that, so you don't have to guess.

VIm indent tips

Indent using == and = When working with source code it is very nice to work with indented code. To indent the current line issue == in normal mode. Use Shift-V to go into visual mode, select a couple of lines and do = to indent them.

g; and g,

to move (forward, backward) through the changelist.

de Duyuuuelete everything till the end of the word by pressing . at your heart's desire.

ci(xyz[Esc] -- This is a weird one. Here, the 'i' does not mean insert mode. Instead it means inside the parenthesis. So this sequence cuts the text inside parenthesis you're standing in and replaces it with "xyz". It also works inside square and figure brackets -- just do ci[ or ci{ correspondingly. Naturally, you can do di (if you just want to delete all text without typing anything. You can also do a instead of i if you want to delete the parentheses as well and not just text inside them.

ci" - cuts the text in current quotes

ciw - cuts the current word. This works just like the previous one except that ( is replaced with w.

C - cut the rest of the line and switch to insert mode.

ZZ -- save and close current file (WAY faster than Ctrl-F4 to close the current tab!)

ddp - move current line one row down

xp -- move current character one position to the right

U - uppercase, so viwU upercases the word

~ - switches case, so viw~ will reverse casing of entire word

Ctrl+u / Ctrl+d scroll the page half-a-screen up or down. This seems to be more useful than the usual full-screen paging as it makes it easier to see how the two screens relate. For those who still want to scroll entire screen at a time there's Ctrl+f for Forward and Ctrl+b for Backward. Ctrl+Y and Ctrl+E scroll down or up one line at a time.

Crazy but very useful command is zz -- it scrolls the screen to make this line appear in the middle. This is excellent for putting the piece of code you're working on in the center of your attention. Sibling commands -- zt and zb -- make this line the top or the bottom one on the sreen which is not quite as useful.

% finds and jumps to the matching parenthesis.

de -- delete from cursor to the end of the word (you can also do dE to delete until the next space)

bde -- delete the current word, from left to right delimiter

df[space] -- delete up until and including the next space

dt. -- delete until next dot

dd -- delete this entire line

ye (or yE) -- yanks text from here to the end of the word

ce - cuts through the end of the word

bye -- copies current word (makes me wonder what "hi" does!)

yy -- copies the current line

cc -- cuts the current line, you can also do S instead. There's also lower cap s which cuts current character and switches to insert mode.

viwy or viwc. Yank or change current word. Hit w multiple times to keep selecting each subsequent word, use b to move backwards

vi{ - select all text in figure brackets. va{ - select all text including {}s

vi(p - highlight everything inside the ()s and replace with the pasted text

b and e move the cursor word-by-word, similarly to how Ctrl+Arrows normally do. The definition of word is a little different though, as several consecutive delmiters are treated as one word. If you start at the middle of a word, pressing b will always get you to the beginning of the current word, and each consecutive b will jump to the beginning of the next word. Similarly, and easy to remember, e gets the cursor to the end of the current, and each subsequent, word.

similar to b/e, capital B and E move the cursor word-by-word using only whitespaces as delimiters.

MEMORY MANAGEMENT The malloc function allocates space for an object whose size is specified by size and whose value is indeterminate. If you want the values to be set to zero, use calloc instead. calloc is basically just a wrapper function around one call to malloc and one call to memset.

If you want remove all local changes from your working copy, simply stash them:

git stash save --keep-index If you don't need them anymore, you now can drop that stash:

git stash drop

#use rsync for better copy support

GITHUB FOR TEAM

git remote add upstream "TEAMMATE'S repo URL" git pull upstream master

cd ~/.vim/bundle git clone https://github.com/Valloric/YouCompleteMe.git cd YouCompleteMe git submodule update --init --recursive ./install.sh --clang-completer

details more YCM

Ubuntu Linux x64 Installation

Please refer to the full Installation Guide below; the following commands are provided on a best-effort basis and may not work for you.

Make sure you have Vim 7.3.598 with python2 support. Ubuntu 14.04 and later have a Vim that's recent enough. You can see the version of Vim installed by running vim --version . If the version is too old, you may need to compile Vim from source (don't worry, it's easy).

Install YouCompleteMe with Vundle.

Remember: YCM is a plugin with a compiled component. If you update YCM using Vundle and the ycm_support_libs library APIs have changed (happens rarely), YCM will notify you to recompile it. You should then rerun the install process.

Install development tools and CMake: sudo apt-get install build-essential cmake

Make sure you have Python headers installed: sudo apt-get install python-dev .

Compiling YCM with semantic support for C-family languages: cd ~/.vim/bundle/YouCompleteMe ./install.py --clang-completer

Compiling YCM without semantic support for C-family languages: cd ~/.vim/bundle/YouCompleteMe ./install.py

The following additional language support options are available: •C# support: add --omnisharp-completer to ./install.py •Go support: ensure go is installed and add --gocode-completer •TypeScript support: install nodejs and npm then install the TypeScript SDK with npm install -g typescript . •JavaScript support: install nodejs and npm and add --tern-completer to ./install.py •Rust support: install rustc and cargo and add --racer-completer to ./install.py

For example, to install with all language features, ensure npm, go, mono, rust, and typescript API are installed and in your PATH, then: cd ~/.vim/bundle/YouCompleteMe ./install.py --clang-completer --omnisharp-completer --gocode-completer
--tern-completer --racer-completer

That's it. You're done. Refer to the User Guide section on how to use YCM. Don't forget that if you want the C-family semantic completion engine to work, you will need to provide the compilation flags for your project to YCM. It's all in the User Guide.

YCM comes with sane defaults for its options, but you still may want to take a look at what's available for configuration. There are a few interesting options that are conservatively turned off by default that you may want to turn on.

" press captital J for line joining in VIM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment