Skip to content

Instantly share code, notes, and snippets.

@Ashkanph
Last active January 19, 2019 07:28
Show Gist options
  • Save Ashkanph/8abbed420b7065523eca5db463cecdb0 to your computer and use it in GitHub Desktop.
Save Ashkanph/8abbed420b7065523eca5db463cecdb0 to your computer and use it in GitHub Desktop.
My standard VIM (with no vim rc) and visual studio code cheatsheet

VIM Cheatshet

installing neovim

sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt-get update
sudo apt-get install neovim

comment uncomment multiple lines

Put your cursor on the first # character, press CtrlV (or CtrlQ for gVim), and go down until the last commented line and press x, that will delete all the # characters vertically.

For commenting a block of text is almost the same:

First, go to the first line you want to comment, press CtrlV. This will put the editor in the VISUAL BLOCK mode.
Then using the arrow key and select until the last line
Now press ShiftI, which will put the editor in INSERT mode and then press #. This will add a hash to the first line.
Then press Esc (give it a second), and it will insert a # character on all other selected lines.
  • vim fileName باز کردن فایل
  • j k l h جابجایی
  • d کات کردن متن انتخاب شده
  • dd رفتن روی یک سطر و زدن این باعث پاک شدن تمام آن سطر میشود
  • :i وارد شدن به مود اینزرت (نوشتن در فایل)
  • :wq خارج شدن از ویم و ذخیره کردن تغییرات اعمال شده - write quit
  • :q! خارج شدن از ویم بدون اعمال تغییرات

Normal mode

  • $ برو آخر خط

  • 0 برو اول خط

  • ^ برو اولین کاراکتر غیر اسپیس خط

  • p پیست متن کپی‌شده

  • ]p پیست کردن متن کپی‌شده با در نظر گرفتن ایندنت

  • going to end of the line and change to i mode A

  • going to begining of the line and change to i mode I

  • going current line to the middle of page z.

  • gd رفتن به تعریف تابع یا متغیر یا غیره

  • gq آنجایی که سلکت شده را ریفلو می‌کند، یعنی تب‌ها و اینترها را پاک می‌کند

  • gb مولتی‌کرسر. در ویم استاندارد نیست

  • :54 رفتن به خط ۵۴

  • hl باز کردن پین جدید

  • hl جابجایی بین پنجره‌های عمودی یا همان پین‌ها

  • dw پاک کردن این کلمه

  • dd پاک کردن و کپی کردن این خط

  • 6x پاک کردن ۶ کاراکتر

  • ciw تغییر کل متن

  • curser in multiple lines at a similar column ctrl + shift + moving cursor up and down

  • shift + v انتخاب تمام خط

  • w رفتن به کلمه بعدی

  • b رفتن به ابتدای کلمه قبلی

  • e رفتن به انتهای کلمه

  • 5w برو پنج کلمه جلوتر

  • 3b برو ابتدای ۳ کلمه عقب‌تر

  • 2e برو انتهای دو کلمه جلوتر

  • 5iAshkanEsc پنج بار بنویس Ashkan

  • } رفتن به یک پاراگراف جلوتر

  • { رفتن به یک پاراگراف عقب‌تر

  • ggvG انتخاب تمام متن

  • = درست کردن ایندنت متن

  • >> شیفت کردن این خط به جلو

  • << شیفت کردن این خط به عقب

  • 5>>.. شیفت کردن پنج خط به اندازه سه کاراکتر به جلو

Search the selected text

viw Select a word

/(ctrl+r)"Enter Open the search and paste the selected word

n Next match

Or add this to your vimrc: vnoremap // y/"

Copy all the page

: % y +

%  to refer the next command to work on all the lines
y  to yank those lines
+  to copy to the system clipboard

Insert mode (Not recommended-Do these in normal mode!)

going to begining of the line: ctrl+o shift+i

going to end of the line: ctrl+o shift+a

going to end of the line: ctrl+o $

go to the first non-whitespace character in the line ctrl+o ^

go to the beginning of the line ctrl+o 0

new line under the current line ctrl+o o

new line above the current line ctrl+o O


Visual Studio Code

  • Cycle through autocomplete suggestions with Ctrl+N/Ctrl+P

  • تغییر نام یک متغیر در تمام کد با رفتن روی کلمه زدن کلید اف۲

  • Code Folding: با زدن کلیدهای زیر می‌توان کد را در کروشه‌ها یا پرانتزها باز و بسته کرد: Ctrl+Shift+چ to fold or press Ctrl+Shift+ج to unfold the ranges at the current cursor position

settings.json

You can put this in ./vscode/settings.json, or put it in .config/User/Code

{
    "window.zoomLevel": 1,
    "workbench.colorTh, eme": "Visual Studio Dark",
    "editor.rulers": [
        80,
        120
    ],
    "editor.tabCompletion": true,
    "editor.quickSuggestions": {
        "other": true,
        "comments": true,
        "strings": true
    },
    "extensions.ignoreRecommendations": false,
    "vim.disableAnnoyingNeovimMessage": true,
    "explorer.confirmDelete": false,
    "workbench.colorTheme": "Monokai"
}
  • settings for vscode vim:
{
    "vim.normalModeKeyBindings": [
        {
            "before": [";"],
            "after": [":"]
        }
    ]
}

keybindings.json

You can put this in .config/User/Code

// Place your key bindings in this file to overwrite the defaults
[
    {
        "key": "ctrl+shift+d down",
        "command": "editor.action.copyLinesDownAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+shift+alt+down",
        "command": "-editor.action.copyLinesDownAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+shift+d up",
        "command": "editor.action.copyLinesUpAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+shift+alt+up",
        "command": "-editor.action.copyLinesUpAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "capslock tab",
        "command": "workbench.view.explorer"
    },
    {
        "key": "ctrl+shift+e",
        "command": "-workbench.view.explorer"
    },
    {
        "key": "tab q",
        "command": "workbench.action.toggleSidebarVisibility"
    },
    {
        "key": "ctrl+b",
        "command": "-workbench.action.toggleSidebarVisibility"
    },
    {
        "key": "[Backquote] q",
        "command": "workbench.action.terminal.toggleTerminal"
    },
    {
        "key": "ctrl+k",
        "command": "cursorUp",
        "when": "textInputFocus"
    },
    {
        "key": "up",
        "command": "-cursorUp",
        "when": "textInputFocus"
    },
    {
        "key": "ctrl+h",
        "command": "cursorLeft",
        "when": "textInputFocus"
    },
    {
        "key": "left",
        "command": "-cursorLeft",
        "when": "textInputFocus"
    },
    {
        "key": "ctrl+l",
        "command": "cursorRight",
        "when": "textInputFocus"
    },
    {
        "key": "right",
        "command": "-cursorRight",
        "when": "textInputFocus"
    },
    {
        "key": "ctrl+j",
        "command": "cursorDown",
        "when": "textInputFocus"
    },
    {
        "key": "down",
        "command": "-cursorDown",
        "when": "textInputFocus"
    },
    {
        "key": "alt+j",
        "command": "editor.action.moveLinesDownAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "alt+down",
        "command": "-editor.action.moveLinesDownAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "alt+k",
        "command": "editor.action.moveLinesUpAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "alt+up",
        "command": "-editor.action.moveLinesUpAction",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "tab",
        "command": "extension.vim_escape",
        "when": "editorTextFocus && vim.active && vim.mode == 'Insert'"
    }
]

My .vimrc

:nnoremap p ]p
:nnoremap <c-p> p
    
vnoremap // y/<C-R>"<CR>   # search the word

noremap cp yap<S-}>p    # Clone Paragraph with cp
    
nnoremap <Tab> <Esc>
vnoremap <Tab> <Esc>gV
onoremap <Tab> <Esc>
cnoremap <Tab> <C-C><Esc>
inoremap <Tab> <Esc>`^
inoremap <Leader><Tab> <Tab>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment