kevinxft / Notebook

个人笔记本
0 stars 0 forks source link

vim学习笔记 #19

Open kevinxft opened 2 years ago

kevinxft commented 2 years ago

操作

移动

配置更方便的滚动(normal,visual)

一些实用的组合

. 点命令

屏幕滚动

插入

复制

可视化模式(可以配合上面的移动,还可以配合插入操作,例如A)

文本对象(i 内部,a 外部)

插件

vim-textobj-aruments (主要是修改函数参数)

vim-textobj-entire

kevinxft commented 2 years ago

搜索

单行

全局

kevinxft commented 2 years ago

vim-easymotion

单词首字符

vim-seank

kevinxft commented 2 years ago

多文件跳转

定位

标记

kevinxft commented 2 years ago

处理包裹的字符的符号

# hello world ! -> "hello world ! "
shift+v S "
kevinxft commented 2 years ago

替换字符串

公式 :[range]s[ubstitute]/{pattern}/{string}/[flags]

# 到尾部 keivn 替换成 fuck ,需要按回车
:$s/kevin/fuck

# 全文keivn 替换成 fuck ,需要按回车
:%s/kevi/fuck

# 基于行,keivn 替换成 fuck ,需要按回车
:10,12s/kevin/fuck

:10,$s/kevin/fuck

# 一行内全部替换,不会遇到第一个匹配就停止
:%s/kevi/fuck/g

# 有确认的替换
:%s/kevi/fuck/c

gb 多选操作

kevinxft commented 2 years ago

窗口切换

利用vscode的快捷键

kevinxft commented 2 years ago

删除一个函数

% 匹配括号

kevinxft commented 2 years ago

可以录制一系列的动作

kevinxft commented 2 years ago

vim 调用vscode的命令

{ "before": ["", "f", "d"], "commands": ["editor.action.formatDocument"] }

- 重命名 f2 or leader + r + n
```json
{
    "before": ["<leader>", "r", "n"],
    "commands": ["editor.action.rename"]
}
kevinxft commented 2 years ago

vscode

编辑区域

搜索

常用操作

git

kevinxft commented 2 years ago

vscode keybindings.josn

[
  {
    "key": "cmd+c",
    "command": "execCopy"
  },
  {
    "key": "shift+left",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "h"]
    }
  },
  {
    "key": "shift+right",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "l"]
    }
  },
  {
    "key": "shift+up",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "k"]
    }
  },
  {
    "key": "shift+down",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "j"]
    }
  },
  {
    "key": "ctrl+cmd+\\",
    "command": "workbench.action.splitEditorUp"
  },
  {
    "key": "ctrl+;",
    "command": "workbench.view.explorer",
    "when": "viewContainer.workbench.view.explorer.enabled"
  },
  {
    "key": "ctrl+'",
    "command": "workbench.action.focusFirstEditorGroup"
  },
  {
    "key": "a",
    "command": "explorer.newFile",
    "when": "filesExplorerFocus && !inputFocus"
  },
  {
    "key": "shift+a",
    "command": "explorer.newFolder",
    "when": "filesExplorerFocus && !inputFocus"
  },
  {
    "key": "r",
    "command": "renameFile",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "d",
    "command": "deleteFile",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceReadonly && !inputFocus"
  }
]
kevinxft commented 2 years ago

lazygit

kevinxft commented 2 years ago

Vimium-C

自定义快捷键

改配置

chrome://lfags 将 extensions-on-chrome-urls 开启

kevinxft commented 2 years ago

chrome

控制台相关

kevinxft commented 2 years ago

iTerm2

分屏

kevinxft commented 2 years ago

zsh-vi-mod

brew install zsh-vi-mode,安装好以后需要在zshrc里面配置source激活

普通用法

高级用法

改键

function jump_start_of_line() { zvm_navigation_handler ^ }

The plugin will auto execute this zvm_after_lazy_keybindings function

function zvm_after_lazy_keybindings() {

Here we define the custom widget

zvm_define_widget jump_end_of_line zvm_define_widget jump_start_of_line

In normal mode, press Ctrl-E to invoke this widget

zvm_bindkey vicmd 'H' jump_start_of_line zvm_bindkey visual 'H' jump_start_of_line zvm_bindkey vicmd 'L' jump_end_of_line zvm_bindkey visual 'L' jump_end_of_line }


#### 修复复制功能
```cmd
# zvm_vi_yank函数增加一样代码
function zvm_vi_yank() {
  zvm_yank
  echo ${CUTBUFFER} | pbcopy # 增加这行
  zvm_exit_visual_mode
}
kevinxft commented 1 year ago

完整seeting.json

{
  "[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[json]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[python]": {
    "editor.formatOnType": true
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "codeium.enableSearch": true,
  "css.validate": false,
  "editor.accessibilitySupport": "off",
  "editor.codeActionsOnSave": {
    "editor.codeLensFontFamily": "monaco",
    "leetcode.workspaceFolder": "/Users/kevin/.leetcode",
    "workbench.editor.enablePreview": false
  },
  "editor.fontFamily": "CodeNewRoman Nerd Font",
  "editor.fontSize": 18,
  "editor.formatOnPaste": true,
  "editor.formatOnSave": true,
  "editor.lineHeight": 30,
  "editor.lineNumbers": "relative",
  "editor.tabSize": 2,
  "editor.unfoldOnClickAfterEndOfLine": true,
  "editor.unicodeHighlight.ambiguousCharacters": false,
  "explorer.confirmDelete": false,
  "explorer.confirmDragAndDrop": false,
  "files.autoSave": "onFocusChange",
  "git.autofetch": true,
  "hardhat.telemetry": true,
  "javascript.updateImportsOnFileMove.enabled": "always",
  "leetcode-problem-rating.workspaceFolder": "/Users/kevin/.leetcode",
  "leetcode.defaultLanguage": "javascript",
  "leetcode.endpoint": "leetcode-cn",
  "leetcode.hint.commandShortcut": false,
  "leetcode.hint.commentDescription": false,
  "leetcode.hint.configWebviewMarkdown": false,
  "leetcode.workspaceFolder": "/Users/kevin/.leetcode",
  "less.validate": false,
  "liveServer.settings.donotShowInfoMsg": true,
  "scss.validate": false,
  "security.workspace.trust.untrustedFiles": "open",
  "solidity.telemetry": true,
  "terminal.external.osxExec": "iTerm.app",
  "terminal.integrated.cursorStyle": "line",
  "terminal.integrated.fontFamily": "Maple Mono SC NF",
  "terminal.integrated.fontSize": 14,
  "vim.easymotion": true,
  "vim.foldfix": true,
  "vim.handleKeys": {},
  "vim.hlsearch": true,
  "vim.incsearch": true,
  "vim.leader": "<Space>",
  "vim.normalModeKeyBindings": [
    {
      "after": ["^"],
      "before": ["H"]
    },
    {
      "after": ["g", "_"],
      "before": ["L"]
    },
    {
      "after": ["5", "j"],
      "before": ["J"]
    },
    {
      "after": ["5", "k"],
      "before": ["K"]
    }
  ],
  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": ["<leader>", "n", "d"],
      "commands": ["explorer.newFolder"]
    },
    {
      "before": ["<leader>", "n", "f"],
      "commands": ["explorer.newFile"]
    },
    {
      "after": ["V", "$", "%", "d"],
      "before": ["<leader>", "d", "f"]
    },
    {
      "after": ["V", "$", "%", "d"],
      "before": ["<leader>", "f"]
    },
    {
      "before": ["<leader>", "w"],
      "commands": ["workbench.action.files.save"]
    },
    {
      "before": ["<leader>", "w", "q"],
      "commands": [
        "workbench.action.files.save",
        "workbench.action.closeActiveEditor"
      ]
    },
    {
      "before": ["<leader>", "f", "d"],
      "commands": ["editor.action.formatDocument"]
    },
    {
      "before": ["<leader>", "r", "n"],
      "commands": ["editor.action.rename"]
    },
    {
      "before": ["<leader>", "["],
      "commands": [
        {
          "command": "editor.fold"
        },
        {
          "args": {
            "after": ["$", "%"]
          },
          "command": "vim.remap"
        }
      ]
    },
    {
      "before": ["<leader>", "]"],
      "commands": [
        {
          "command": "editor.unfold"
        }
      ]
    },
    {
      "before": ["<C-n>"],
      "commands": [":nohl"]
    },
    {
      "before": ["K"],
      "commands": ["lineBreakInsert"],
      "silent": true
    },
    {
      "after": ["s"],
      "before": ["f"]
    },
    {
      "after": ["S"],
      "before": ["F"]
    },
    {
      "after": ["c", "l"],
      "before": ["s"]
    },
    {
      "after": ["^", "C"],
      "before": ["S"]
    },
    {
      "before": ["<leader>", "g", "c", "l"],
      "commands": ["git.clean"]
    },
    {
      "before": ["<leader>", "g", "d", "f"],
      "commands": ["git.openChange"]
    },
    {
      "before": ["<leader>", "g", "c"],
      "commands": ["git.commit"]
    },
    {
      "before": ["<leader>", "g", "g"],
      "commands": ["workbench.view.scm"]
    },
    {
      "before": ["<leader>", "g", "s"],
      "commands": ["git.stage"]
    },
    {
      "before": ["<leader>", "g", "u"],
      "commands": ["git.unstage"]
    },
    {
      "before": ["<leader>", "r", "e"],
      "commands": ["abracadabra.extract"]
    },
    {
      "before": ["<leader>", "v", "v"],
      "commands": ["hocusPocus.createVariable"]
    },
    {
      "before": ["<leader>", "f", "f"],
      "commands": ["hocusPocus.createFunction"]
    },
    {
      "before": ["<leader>", ";"],
      "commands": ["vspacecode.space"]
    }
  ],
  "vim.operatorPendingModeKeyBindings": [
    {
      "after": ["^"],
      "before": ["H"]
    },
    {
      "after": ["g", "_"],
      "before": ["L"]
    },
    {
      "after": ["a", "I"],
      "before": ["a", "i"]
    }
  ],
  "vim.operatorPendingModeKeyBindingsNonRecursive": [
    {
      "after": ["z"],
      "before": ["f"]
    },
    {
      "after": ["Z"],
      "before": ["F"]
    }
  ],
  "vim.sneak": true,
  "vim.useCtrlKeys": true,
  "vim.useSystemClipboard": true,
  "vim.visualModeKeyBindings": [
    {
      "after": ["^"],
      "before": ["H"]
    },
    {
      "after": ["g", "_"],
      "before": ["L"]
    },
    {
      "after": ["5", "j"],
      "before": ["J"]
    },
    {
      "after": ["5", "k"],
      "before": ["K"]
    },
    {
      "after": ["a", "I"],
      "before": ["a", "i"]
    }
  ],
  "vim.visualModeKeyBindingsNonRecursive": [
    {
      "after": ["s"],
      "before": ["f"]
    },
    {
      "before": ["<leader>", ";"],
      "commands": ["vspacecode.space"]
    }
  ],
  "vscode-pets.position": "explorer",
  "vscode-pets.theme": "forest",
  "vsicons.dontShowNewVersionMessage": true,
  "workbench.colorTheme": "Dracula",
  "workbench.iconTheme": "eq-material-theme-icons-light",
  "workbench.startupEditor": "none",
  "terminal.integrated.env.osx": {
    "FIG_NEW_SESSION": "1"
  }
}
kevinxft commented 1 year ago

完整keybindings.json

[
  {
    "key": "cmd+c",
    "command": "execCopy"
  },
  {
    "key": "shift+left",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "h"]
    }
  },
  {
    "key": "shift+right",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "l"]
    }
  },
  {
    "key": "shift+up",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "k"]
    }
  },
  {
    "key": "shift+down",
    "command": "vim.remap",
    "when": "vim.mode == 'Normal'",
    "args": {
      "after": ["<c-w>", "j"]
    }
  },
  {
    "key": "ctrl+cmd+\\",
    "command": "workbench.action.splitEditorUp"
  },
  {
    "key": "ctrl+;",
    "command": "workbench.view.explorer",
    "when": "viewContainer.workbench.view.explorer.enabled"
  },
  {
    "key": "ctrl+'",
    "command": "workbench.action.focusFirstEditorGroup"
  },
  {
    "key": "a",
    "command": "explorer.newFile",
    "when": "filesExplorerFocus && !inputFocus"
  },
  {
    "key": "shift+a",
    "command": "explorer.newFolder",
    "when": "filesExplorerFocus && !inputFocus"
  },
  {
    "key": "r",
    "command": "renameFile",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "d",
    "command": "deleteFile",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "space",
    "command": "vspacecode.space",
    "when": "activeEditorGroupEmpty && focusedView == '' && !whichkeyActive && !inputFocus"
  },
  // Trigger vspacecode when sidebar is in focus
  {
    "key": "space",
    "command": "vspacecode.space",
    "when": "sideBarFocus && !inputFocus && !whichkeyActive"
  },
  {
    "key": "ctrl+,",
    "command": "workbench.action.terminal.toggleTerminal",
    "when": "terminal.active"
  },
  {
    "key": "ctrl+`",
    "command": "-workbench.action.terminal.toggleTerminal",
    "when": "terminal.active"
  },
  {
    "key": "cmd+]",
    "command": "workbench.action.terminal.focusNextPane",
    "when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
  },
  {
    "key": "alt+cmd+right",
    "command": "-workbench.action.terminal.focusNextPane",
    "when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
  },
  {
    "key": "cmd+[",
    "command": "workbench.action.terminal.focusPreviousPane",
    "when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
  },
  {
    "key": "alt+cmd+left",
    "command": "-workbench.action.terminal.focusPreviousPane",
    "when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
  },
  {
    "key": "shift+alt+q",
    "command": "workbench.action.terminal.kill"
  },
  {
    "key": "shift+alt+n",
    "command": "workbench.action.terminal.new",
    "when": "terminalProcessSupported || terminalWebExtensionContributedProfile"
  },
  {
    "key": "ctrl+shift+`",
    "command": "-workbench.action.terminal.new",
    "when": "terminalProcessSupported || terminalWebExtensionContributedProfile"
  },
  {
    "key": "shift+cmd+0",
    "command": "workbench.action.debug.restart",
    "when": "inDebugMode"
  },
  {
    "key": "shift+cmd+f5",
    "command": "-workbench.action.debug.restart",
    "when": "inDebugMode"
  },
  {
    "key": "shift+cmd+9",
    "command": "editor.debug.action.toggleBreakpoint",
    "when": "debuggersAvailable && editorTextFocus"
  },
  {
    "key": "f9",
    "command": "-editor.debug.action.toggleBreakpoint",
    "when": "debuggersAvailable && editorTextFocus"
  },
  {
    "key": "cmd+'",
    "command": "workbench.action.debug.stepOver",
    "when": "debugState == 'stopped'"
  },
  {
    "key": "f10",
    "command": "-workbench.action.debug.stepOver",
    "when": "debugState == 'stopped'"
  },
  {
    "key": "shift+cmd+'",
    "command": "workbench.action.debug.stepInto",
    "when": "debugState != 'inactive'"
  },
  {
    "key": "f11",
    "command": "-workbench.action.debug.stepInto",
    "when": "debugState != 'inactive'"
  },
  {
    "key": "tab",
    "command": "extension.vim_tab",
    "when": "editorFocus && vim.active && !inDebugRepl && vim.mode != 'Insert' && editorLangId != 'magit'"
  },
  {
    "key": "tab",
    "command": "-extension.vim_tab",
    "when": "editorFocus && vim.active && !inDebugRepl && vim.mode != 'Insert'"
  },
  {
    "key": "x",
    "command": "magit.discard-at-point",
    "when": "editorTextFocus && editorLangId == 'magit' && vim.mode =~ /^(?!SearchInProgressMode|CommandlineInProgress).*$/"
  },
  {
    "key": "k",
    "command": "-magit.discard-at-point"
  },
  {
    "key": "-",
    "command": "magit.reverse-at-point",
    "when": "editorTextFocus && editorLangId == 'magit' && vim.mode =~ /^(?!SearchInProgressMode|CommandlineInProgress).*$/"
  },
  {
    "key": "v",
    "command": "-magit.reverse-at-point"
  },
  {
    "key": "shift+-",
    "command": "magit.reverting",
    "when": "editorTextFocus && editorLangId == 'magit' && vim.mode =~ /^(?!SearchInProgressMode|CommandlineInProgress).*$/"
  },
  {
    "key": "shift+v",
    "command": "-magit.reverting"
  },
  {
    "key": "shift+o",
    "command": "magit.resetting",
    "when": "editorTextFocus && editorLangId == 'magit' && vim.mode =~ /^(?!SearchInProgressMode|CommandlineInProgress).*$/"
  },
  {
    "key": "shift+x",
    "command": "-magit.resetting"
  },
  {
    "key": "x",
    "command": "-magit.reset-mixed"
  },
  {
    "key": "ctrl+u x",
    "command": "-magit.reset-hard"
  },
  {
    "key": "y",
    "command": "-magit.show-refs"
  },
  {
    "key": "y",
    "command": "vspacecode.showMagitRefMenu",
    "when": "editorTextFocus && editorLangId == 'magit' && vim.mode == 'Normal'"
  },
  {
    "key": "ctrl+j",
    "command": "workbench.action.quickOpenSelectNext",
    "when": "inQuickOpen"
  },
  {
    "key": "ctrl+k",
    "command": "workbench.action.quickOpenSelectPrevious",
    "when": "inQuickOpen"
  },
  {
    "key": "ctrl+j",
    "command": "selectNextSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+k",
    "command": "selectPrevSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+l",
    "command": "acceptSelectedSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+j",
    "command": "showNextParameterHint",
    "when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
  },
  {
    "key": "ctrl+k",
    "command": "showPrevParameterHint",
    "when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
  },
  {
    "key": "ctrl+j",
    "command": "selectNextCodeAction",
    "when": "codeActionMenuVisible"
  },
  {
    "key": "ctrl+k",
    "command": "selectPrevCodeAction",
    "when": "codeActionMenuVisible"
  },
  {
    "key": "ctrl+l",
    "command": "acceptSelectedCodeAction",
    "when": "codeActionMenuVisible"
  },
  {
    "key": "ctrl+h",
    "command": "file-browser.stepOut",
    "when": "inFileBrowser"
  },
  {
    "key": "ctrl+l",
    "command": "file-browser.stepIn",
    "when": "inFileBrowser"
  }
]