Skip to content

Instantly share code, notes, and snippets.

@rajcspsg
Last active November 8, 2021 05:21
Show Gist options
  • Save rajcspsg/d2a9cbd101aeee0ec0f9b5a61fc30b91 to your computer and use it in GitHub Desktop.
Save rajcspsg/d2a9cbd101aeee0ec0f9b5a61fc30b91 to your computer and use it in GitHub Desktop.
Vim
1. shift + C - to delete from the position of the cursor to the end of the line and then change the mode to insert mode.
2. c-w - to delete from the position of the cursor to the beginning of the word.
3. to delete 4 word from the cursor position - 4 c w
4. to delete the text within tags press cit or c-i-symbol (symbol could be anything like {, < ( etc).
=========================================Copying================================================
yy - cpy the line
y$ - copy from cursor to the end of the line.
y^ - copy from cursor to the beginning of the line.
3yy - copy from current line to next 2 lines.
yw - yank to start of the next word.
y% - yank to next matching charecter.
to cut use the same commands instead of y's use d's.
undo - go the command mode then press u to undo the changes one by one.
redo - go to command mode then press ctrl + r to redo changes one by one.
paste from clipboard
pasting from clipboard sometimes causes weird alignment. we can do `:set paste` in command mode and then enter p command.
don't set paste in vimrc file.
instead use the command `"+p` to paste from clipboard.
use shift J to join current line with next line.
" use vim settings, rather than vi settings
" This must be the first becuse it changes other options as a side effect
set nocompatible
" source ~/.vimrc if it exists
if filereadable(expand("~/.vimrc.before"))
source ~/.vimrc .before
endif
" ===================General Config =====================================
set number relativenumber " line numbers are good
set backspace=indent,eol,start " Allow backspace in insert mode
set history=1000 " Store lots of :cmdline history
set showcmd " Show incomplete commands down the bottom
set showmode " Show currentmode down the bottom
set gcr=a:blickon0 " disable cursor blink
set visualbell " No Sounds
set autoread " Reload files changed outside vim
" This make vim act like all other editors, buffers can
" exist in the background without being in window.
" https://items.sjbach.com/319/configuring-vim-right
set hidden
" turn on syntax highlighting
syntax on
" change leader to comma because the backslash is too far away
" that means all \x commands turn into ,x
" the mapleader has to be set before vundle starts loading all the plugins.
let mapleader=","
set timeout timeoutlen=1500
"========================= Turn Off Swap Files ==============================
set noswapfile
set nobackup
set nowb
" ========================== Persistent Undo =================================
" Keep undo histroty accross sessions, by storing in a file
" Only works all the time
if has('persistent_undo') && !isdirectory(expand('~').'/.vim/backups')
silent !mkdir ~/.vim/backups >/dev/null 2>&1
set undodir=~/.vim/backups
set undofile
endif
"
"============================ Scrolling ======================================
set scrolloff=8 " Start scrolling when we are 8 lines away from margins
set sidescrolloff=15
set sidescroll=1
" ============================ FOlding =======================================
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "don't fold by default
1. To move to the first line of the file - gg
2. to move to the Nth line of the file - Go to Normal Mode and then press :N
3. To move on charecter left H and one charecter right L
4. To move to the end of the line - $
5. To move to the beginning of the line - 0
6. shift I - in normal mode to insert mode and then insert from the beginning of the line.
7. Shift a - in normal mode to insert mode and then insert from the end of the line.
8. b - back one word and W front one word
9. f /char - move to the next charecter in the line
10. shift -h - to top of the file
11. shift g - to the end of the file
1. change from normal mode to visual mode -> v
2. change from normal mode to visual block mode -> ctrl + v
3. Visual Block mode is used to apply cnages from one line to all the selected lines
1. Enter into visual mode
2. Select the lines
3. make your changes to the first line
4. press esc
5. save it to the file
For example, to command the method with single line comment
1. ctrl + v
2. use j to select the lines
3. shift + I then type space then ESC
4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment