- Quick Navigation
- Vs Code Setting
- Markdown Guide
- GIT and GITHUB 🚀🚀
- Creating Snippets 🚀🚀
- Vim
- Unicode
For Editor: FiraCode-Regular.ttf
and FiraCode-Bold.ttf
from:
tonsky/FiraCode
For Terminal: FiraMono NF
from
Nerd Font
You can easily define your own snippets without any extension. To create or edit your own snippets,
- select
User Snippets
underFile > Preferences > User Snippets
orSetting > User Snippets
- then select the language(by typing language identifier) for which the snippets should appear,
- or type
New Global Snippets
file option if they should appear for all languages.
- or type
https://code.visualstudio.com/docs/editor/userdefinedsnippets
- Each snippet is defined under a
snippet name
and has ascope
,prefix
,body
anddescription
. - Add comma separated ids of the languages where the snippet is applicable in the scope field.
"scope": "javascript,typescript"
- If scope is left empty or omitted, the snippet gets applied to all languages.
- The
prefix
is what is used to trigger the snippet and the body will be expanded and inserted.- Possible variables are:
$1
,$2
for tab stops,$0
for the final cursor position, and${1:label}
,${2:another}
for placeholders.- Placeholders with the same ids are connected.
- Possible variables are:
{
"Print to console": {
"scope": "javascript,typescript",
"prefix": "log",
"body": ["for(int i = $1,i<=$2;i++){",
" console.log(\"${3:string}\");",
" console.log(\"${3:string}\");",
"}",
"$0"],
"description": "Log output to console"
}
}
https://snippet-generator.app: !!!To declare a placeholder (ctrl + i): ${1:example}
- Winget Installation:
winget install JanDeDobbeleer.OhMyPosh -s winget
- configure your shell to use Oh My Posh:
- (Optional) make sure to create the profile first:
New-Item -Path $PROFILE -Type File -Force
C:\Users\u\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
file will be created:
- Open PowerShell profile in Notepad with the following command:
notepad $profile
#or
code $profile
Then add the following line:
oh-my-posh init pwsh --config 'them_json_path' | Invoke-Expression
ex: them_json_path
: C:/Users/x/pure.omp.json
Run the following command:
Install-Module PSReadLine -Force
Now, paste the following code in the PowerShell profile:
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Complete PowerShell profile:
oh-my-posh init pwsh --config 'C:/Users/x/star.omp.json' | Invoke-Expression
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Edit Powershell Commad History:
code (Get-PSReadlineOption).HistorySavePath
Clearing duplicate histories:
# remove_duplicates_commad_history.py
input_path = r'C:\Users\x\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt'
output_path = input_path
with open(input_path, 'r') as file:
lines = file.readlines()
unique_lines = list(set(lines))
with open(output_path, 'w') as file:
file.writelines(unique_lines)
<p align="center">
<img src="img/file_name" alt="file_name" width="width00px"/>
</p>
This sentence uses `$` delimiters to show math inline: $\sqrt{3x-1}+(1+x)^2$
This sentence uses $
delimiters to show math inline:
To add a math expression as a block, start a new line and delimit the expression with two dollar symbols $$
.
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
…or create a new repository on the command line
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin <url>
git push -u origin main
…or push an existing repository from the command line 🚀
git remote add origin <url>
git branch -M main
git push -u origin main
git remote -v
# View existing remotes
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL
git remote -v
# Verify new remote URL
# origin https://github.com/user/repo2.git (fetch)
# origin https://github.com/user/repo2.git (push)
Absolutely, I'd be happy to provide you with some common Git branching commands. Branching is an essential aspect of version control in Git, enabling you to work on different features or bug fixes simultaneously. Here are some commands you might find useful:
-
Create a New Branch:
git branch <branch-name>
: Creates a new branch but doesn't switch to it.
-
Switch to a Branch:
git checkout <branch-name>
: Switches to the specified branch.
-
Create and Switch to a New Branch:
git checkout -b <new-branch-name>
: Creates and switches to a new branch in one command.- Alias:
git ckb <new-branch-name>
-
List Branches:
git branch
: Lists all the branches in the repository. The current branch is indicated with an asterisk (*).- Alias:
git b
-
Rename a Branch:
git branch -m <new-branch-name>
: Renames the current branch to the specified new name.git branch -m <old-branch-name> <new-branch-name>
: Renames a specific branch to a new name.
-
Delete a Branch:
git branch -d <branch-name>
: Deletes a branch. The branch must be fully merged into the current branch.git branch -D <branch-name>
: Forces deletion of a branch, even if it's not fully merged.- Alias:
git bd
-
Merge Branches:
git checkout <target-branch>
: Switches to the branch you want to merge into.- Alias:
git ck <target-branch>
- Alias:
git merge <source-branch>
: Merges the changes from the source branch into the target branch.- Alias:
git m <source-branch>
- Alias:
-
Rebase Branches:
git rebase <base-branch>
: Moves the commits from the current branch onto the tip of the base branch, effectively replaying your changes on top of it.
-
View Merge Conflict:
- During a merge or rebase, if conflicts arise, Git will mark the conflicting areas in the files. Use a text editor or specialized tools to resolve these conflicts.
-
Abort Merge or Rebase:
git merge --abort
: Abort a merge that resulted in conflicts and return to the state before the merge.git rebase --abort
: Abort an ongoing rebase and return to the original branch state.
Remember to always commit your changes before performing any branch operations, as Git doesn't allow you to switch branches with uncommitted changes in most cases. It's also a good practice to frequently pull the latest changes from the remote repository to ensure your branches are up to date.
Please exercise caution when using these commands, especially when force-deleting branches or performing rebases, as they can rewrite commit history and cause data loss if not used correctly.
-
Fork the Repository:
- Fork the repository to your GitHub account.
-
Clone the Repository:
- Clone the forked repository to your local machine using
git clone
.
- Clone the forked repository to your local machine using
-
Create a Branch:
- Create a new branch for your changes using
git checkout -b branch-name
.
- Create a new branch for your changes using
-
Make Changes:
- Make the necessary changes to the codebase.
-
Commit Changes:
- Commit your changes using
git commit -m "Descriptive message"
.
- Commit your changes using
-
Push Changes:
- Push your branch to your GitHub repository with
git push origin branch-name
.
- Push your branch to your GitHub repository with
-
Create Pull Request:
- Go to the original repository on GitHub.
- Click on "New Pull Request".
- Select your branch and the branch you want to merge into.
-
Provide Details:
- Write a concise title and description for your pull request.
-
Submit Pull Request:
- Submit your pull request.
-
Review and Merge:
- Await feedback and address any comments.
- Once approved, the maintainers will merge your changes into the main branch.
List All Branches:
- To see local branches, run this command:
git branch
- To see remote branches, run this command:
git branch -r
- To see all local and remote branches, run this command:
git branch -a
- Fetch remote changes:
git fetch
# git fetch origin # we don't need to specify origin here as we used `-u` flag with git push
- Merge remote changes:
git merge origin/main
git pull
# git pull origin
error: Your local changes to the following files would be overwritten by merge:
README.md
Please commit your changes or stash them before you merge.
Aborting
Updating eeac98a..55e0242
In this case, we need to commit our local changes first and then pull. Or we can stash them.
git add -A
git commit -m "commit local changes before pull"
git pull
git stash
# name the stash
git stash save stashing
git stash save "stashing local changes"
git pull
>> git stash list
stash@{0}: On main: stashing
stash@{1}: On main: stashing local changes
- Apply to changes back to the code:
git stash pop
git stash apply 0
- Pull remote changes:
git pull
-
Resolve conflicts using VSCode
-
Commit changes
Remote repo has changes that we do not have locally.
- Pull remote changes:
git pull
- Resolve conflicts using VSCode
- Commit changes
- then push:
git push
git push --force
When working with Git, you may want to add some new lines to your gitignore files.
However, when listing the files to be committed in your staging area, you realize that some of the ignored files are still showing up.
In this case, you may need to clear your Git cache.
The easiest way to clear your Git cache is to use the “git rm” command with
the –cached
option.
git rm --cached filename
Note o not forget the
--cached
option or your file will be deleted from the filesystem.
In some cases, you may want to clear the cache of your entire Git staging area.
This is particularly useful when you added multiple files that you want now to
be ignored via your .gitignore
file.
To clear your entire Git cache, use the "git rm"
command with the "-r"
option for recursive.
- apply below cmd to un-stage all files:
git rm -r --cached .
- add intended file to
.gitignore
- then, get all files back simply by :
git add .
- Change network
Or,
- try increasing the buffer size.
git config http.postBuffer 524288000
Or,
- downgrading version of HTTP from 2 to 1.1:
git config --global http.version HTTP/1.1
After this change, pushing was successful and change HTTP version to 2 again:
git config --global http.version HTTP/2
Setting > Editor > Live Templates > Java
for(int $INDEX$ = 0; $INDEX$ < $LIMIT$; $INDEX$++) {
$END$
}
Install Vim (Enhanced version of vi which is preinstalled)
sudo apt install vim
Configure .vimrc
# search if.vimrc exits
ls -a | grep .vim
# open .vimrc
vim .vimrc
inoremap jj <Esc>
syntax on
set number
Keymap:
imap jj <Esc>
:imap jj <Esc>
Moving Around:
- Move By Char
h
- move left one characterj
- move down one linek
- move up one linel
- move right one character
- Move by Word
w
- move forward one wordb
- move backward one word
- Line
0
- move to the beginning of the lineCtrl+6
- move to the first non-blank character of the lineCtrl+4
- move to the end of the lineG
- move to the last line of the filegg
- move to the first line of the file:n
- Go to the line number
- Page Jump
Ctrl+d
- half page downCtrl+u
- half page upCtrl+f
- page downCtrl+b
- page upH
- move to the top of the visible screenM
- move to the middle of the visible screenL
- move to the bottom of the visible screen
- Match Moving
%
- move to matching parenthesis, bracket, or brace
Editing Text:
-
Insert Mode
i
- insert text before the cursora
- append text after the cursoro
- open a new line below the current lineO
- open a new line above the current line
-
Delete
x
- delete the character under the cursor
-
d
- delete the selected textdw
- delete the current worddd
- delete the current lineD
- delete from the cursor to the end of the line
-
Copy & Paste
y
- yank (copy) the selected textyw
- yank (copy) the current wordyy
- yank (copy) the current linep
- paste the yanked text after the cursorP
- paste the yanked text before the cursor
-
Undo & Redo
u
- undo the last changeCtrl+r
- redo the last undone change
Searching and Replacing:
/pattern
- search for the specified patternn
- find the next occurrence of the patternN
- find the previous occurrence of the pattern:s/old/new/g
- replace all occurrences of "old" with "new" on the current line:%s/old/new/g
- replace all occurrences of "old" with "new" in the entire file:1,10s/old/new/g
- replace all occurrences of "old" with "new" between lines 1 and 10- Replace visually selected text
- select the text in visual mode
- yank the text with
y
:%s/<C-r>0/new_text
(0
is the yank register)
Using Marks for Navigation:
ma
- set a mark at the current position- ``a` - jump back to mark "a"
'a
- jump back to mark "a" in the same line
Here are some examples of combining Vim commands for advanced operations:
-
Combining Movement and Editing:
d2w
- delete the next two wordsci( | di(
- delete the text inside parentheses - (inside)dit | cit
- delete the text between matching html/xml tags - insideyi(
-yank the text inside (parentheses)
-
Using Visual Mode for Complex Edits.
-
viw
- select the inner word -
vap
- select the paragraph -
ggVG
- select the entire file -
For Code block like this:
if (true){ line1 line2 line3 line4 }
V6jd
-visually select the next 6 lines and delete themf{V%d
- find first{
on the current line, visually select to the matching}
, and delete the contentsvi{d
- visually select the contents inside{}
, and delete themva{d
- visually select the contents inside{}
along with the braces, and delete themva{Vd
- visually select the contents inside{}
along with the braces and the line, and delete them
-
Additional Useful Commands:
>
- indent the selected lines , (>>/Shift..
in vs-code )<
- unindent the selected lineszz
- center the current line on the screen.
- repeat the last command3.
- repeat the last command 3 times
Using Macros for Automation:
qa
- start recording a macro in register "a"<actions to record>
q
- stop recording the macro@a
- replay macro "a"
/**
int **p = new int*[2]; <- array of Integer Pointers
┃
▼
┏━━━━━━┓ ┏━━━━━━━━━━━━━━━┓
┃ p[0] ┃----> ┃ new int[n]; ┃
┗━━━━━━┛ ┗━━━━━━━━━━━━━━━┛
┏━━━━━━┓ ┏━━━━━━━━━━━━━━━┓
┃ p[1] ┃----> ┃ new int[n]; ┃
┗━━━━━━┛ ┗━━━━━━━━━━━━━━━┛
┌───┐───┐───┐───┐───┐
│ │ │ │ │ │
└───┘───┘───┘───┘───┘
┌───┐───┐───┐───┐───┐
│ │ │ │ │ │
└───┘───┘───┘───┘───┘
┌───┐───┐───┐───┐───┐
│ │ │ │ │ │
└───┘───┘───┘───┘───┘
┌───┐───┐───┐───┐───┐
│ │ │ │ │ │
└───┘───┘───┘───┘───┘
┌───┐───┐───┐───┐───┐
│ │ │ │ │ │
└───┘───┘───┘───┘───┘
*/