- VIM
- grok VIM
- VIM Regular Expressions
- VIM Script
- for C family support:
./install.py --clang-completer- optional
--system-libclangUse the libclang that comes with mac, but generally the version is relatively old and there will be problems
- optional
- C# support:
--cs-completerbrew install mono
- NOTE: [YCMD] brew mono only shipped with limited .Net framework.
$ ls /usr/local/opt/mono/lib/mono/ 2.0-api 4.6.1-api gac 3.5-api 4.8-api lldb
- to make YCM work, you may need add
<TargetFrameworkVersion>in you .csproj<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
- to make YCM work, you may need add
- NOTE: [viminspect]
- https://dotnet.microsoft.com/en-us/download/dotnet
- brew dotnet can not manage multiple SDKs
- NOTE: [YCMD] brew mono only shipped with limited .Net framework.
- Go support: install Go and add
--go-completer - JavaScript and TypeScript support: install nodejs and add
--ts-completer- NOTE: TSServer relies on the jsconfig.json for javascript and tsconfig.json for typescript to analyze your project. Ensure the file exists at the root of your project.
- PS: ycm will look up
jsconfig.jsonup to the top parent directory, and think the final directory asrootand parse all .js files under it, it may break ycm ... So do NOT put ajsconfig.jsonfile outside of your project.
- PS: ycm will look up
- Example: To get diagnostics in JavaScript, set the checkJs option to true in your jsconfig.json file:
{ "compilerOptions": { "checkJs": true } }- to support ES6, you can also add compilerOptions:
"target": "es6" - useful example
{ "compilerOptions": { "baseUrl": "./", "paths": { "@/*": ["src/*"] }, "checkJs": true, // 如果你使用的是 ESM 或 Node.js 18+ 的项目结构,可以加上: "module": "CommonJS", "moduleResolution": "node" }, "exclude": ["node_modules", "dist"] } - to support ES6, you can also add compilerOptions:
- NOTE: TSServer relies on the jsconfig.json for javascript and tsconfig.json for typescript to analyze your project. Ensure the file exists at the root of your project.
- Rust support: install Rust and add
--rust-completer- put
~/.cargo/binin you $PATH ?# rust export PATH=$HOME/.cargo/bin:$PATH
- put
- Java support: install JDK8 (version 8 required) and add
--java-completer - for common using
./install.py --clangd-completer --cs-completer --go-completer \ --ts-completer --java-completer --rust-completer- or
# CAVEAT: it will also add --js-completer and then use tern server which is deprecated # to disable tern server, manually delete `third_party/ycmd/third_party/tern_runtime/node_modules` ./install.py --all
- for Ubuntu,
sudo apt install build-essentialis needed
- YCM will look up the .ycm_extra_conf.py configuration file layer by layer
- official example: https://github.com/ycm-core/ycmd/blob/master/.ycm_extra_conf.py
- and you normally need do some modification for c-project
# THIS IS IMPORTANT! Without the '-x' flag, Clang won't know which language to # use when compiling headers. So it will guess. Badly. So C++ headers will be # compiled as C headers. You don't want that so ALWAYS specify the '-x' flag. # For a C project, you would set this to 'c' instead of 'c++'. '-x', 'c', '-std=c99', '-isystem', # OSX c headers '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/', '-isystem', './program/include/' , # you project headers ...
- you should provide either
- a
build.gradlefile- e.g. for an existing project
gradle init --type java-applicationvi build.gradleapply plugin: 'java' // include local jar dependencies ./libs ./jars dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'jars', include: ['*.jar']) } // NOTE: if LSP server loading local .jar failed, // it may be caused by the impatience of target java version // between the .jar and the gradle setting
- e.g. for an existing project
- or a
pom.xmlfile
- a
- Tagbar requires ctags to be installed
-
brew install ctags- for golang, you also need gotags
brew install gotags
- for golang, you also need gotags
- python syntax check
-
pip install flake8 - vim diagnosis
:YcmDebugInfo
- vim check logs
YcmToggleLogs
- output log to file
- running vim with the -V[N] option will do a pretty hefty runtime log, here N is the debug level.
vim -V9myVim.log
- would create a log of debug level 9 in the current directory with the filename myVim.log
- running vim with the -V[N] option will do a pretty hefty runtime log, here N is the debug level.
- pyenv : ERROR: found static Python library … but a dynamic one is required.
$ export PYTHON_CONFIGURE_OPTS="--enable-framework" $ pyenv install 3.10.3
- pyenv: BUILD FAILED (OS X 14.7 using python-build 20180424)
- make: [sharedinstall] Error 71
brew uninstall --ignore-dependencies openssl@1.1 env CONFIGURE_OPTS='--enable-optimizations' pyenv install 3.12.0 # brew install openssl@1.1 # disabled since 2024.10.24
-
chrome plugin : Markdown Preview Plus
-
visit
chrome://extensions/, Check “Allow access to file URLs” in the settings page -
copy as html 问题
- chrome api 修改,导致 copy as html 失效
- 解决方案,在 console 执行以下代码,然后速度点击 preview 页面以获取focus
setTimeout(() => { const html = document.documentElement.outerHTML; navigator.clipboard.writeText(html) .then(() => console.log("Copied HTML OK")) .catch(e => console.error(e)); }, 2000);
- see
.vimspector.jsonexamples- in
~/.vim/bundle/vimspector/support/test/ - or official page
- in
- launch app in inspect mode
nodemon --config nodemon.json --async-stack-traces --exec 'node --inspect[=port] app.js'
node --inspect[=port] app.js # or node --inspect-brk[=port] app.js # to break at the beginning of app.js
- 设置mark
mXX的说明:
| mark | 设置者 | 使用 |
|---|---|---|
| a-z | 用户 | 仅对当前的一个文件生效,也就意味着只可以在当前文件中跳转 |
| A-Z | 用户 | 全局标注,可以作用于不同文件。大写标注也称为「文件标注」。跳转时有可能会切换到另一个缓冲区 |
| 0-9 | viminfo | 0 代表 viminfo 最后一次被写入的位置。实际使用中,就代表 Vim 进程最后一次结束的位置。1 代表 Vim 进程倒数第二次结束的位置,以此类推 |
- mark 命令小结
m ——创建标记 ' ——移动到标记的文本行首 ` ——移动到标记的光标位置 :marks ——列示所有标记 :delmarks ——删除指定标记 :delmarks! ——删除所有标记
-
check vim compile features
vim --version
-
clear a register
# set register `i` empty qiq # or remove register `i` :exec setreg('i', [])
-
open files in tab
vim -p file1 file2 file3 ...
-
save&restore session
:makesession sessionname.vim$ vim -S sessionname.vim
- 每一个通过 shell 命令传递给 Vim 的文件名都被记录在一个参数列表中。
- 可以有多个参数列表:
- 默认情况下所有参数都被放在全局参数列表下,但是你可以使用 :arglocal 命令去创建一个新的本地窗口的参数列表。
- 使用 :args 命令可以列出当前参数
- 参数列表在有些情况下被大量使用:批处理
- 使用 :argdo! 一个简单的重构例子:
:args **/*.[ch] :argdo /word # 查找 :argdo %s/foo/NEW/ge | update # 查找“foo”,并用“bar”代替
- 反向肯定搜索 lookbehind
- 搜索 exp2, start with exp1 .
\(exp1\)\@<=exp2
- 前向肯定搜索 lookahead
- 搜索 exp1, followed by exp2
exp1\(exp2\)\@=
- 搜索 带
/的字符串,比如 URL:?URL
vimgrep /pattern/gj path- 参数:
- g: 一行中出现多次,只显示一次
- j: 只列出匹配的行
- path
./*.c当前文件夹下 c 文件中查找**/*.*包括子文件夹下 所有文件
- 搜索完毕 copen 或 cw 查看搜索列表
- 光标置与第一行行首, ctrl-v 进入 VISUAL BLOCK
- 向下移动光标 选中所有行
- shift i 进入多行插入模式, 编辑 , esc
- 等 1秒钟, 修改完成
- note: v 以字元为单位,V 以行为单位,ctrl-v 以列为单位
- 和上边的 多行行首插入 类似,只是 第三步进行修改
- Press $ to extend the visual block to the end of each line.
- Press A ,进入行尾编辑
- 编辑 , esc
:%s/.*/& &/.*means everything- & copies everything that was matched
& &means whole line twice, separate by a space
- use
vto select the range of lines you want to work on - useing either of the following command to delete all empty lines:
:g/^$/d :v/./d
# record
qa0I"escA",esc0jq // ( 0I 0j to correct position )
@a
8@@use \r instead.
:6t. // copy line:6 to current postion
:6,8t. // copy lines:6-8 to current postion
:6m. // move line:6 to current postion
:6,8m. // move lines:6-8 to current postion
:-3t. // copy line:-3 to current postion - move to line:9
9G " or :9
- handle long text
- gj/gk/gh/gl g$,g0
- move on a visual line, not vim line
- gj/gk/gh/gl g$,g0
- gq (useful when you work with markdown )
- format whole line in sperate lines
- capitalization
- cap, uncap
- gu, gU, g~
- open file by filename where your cursor on
- gf
- reselect (jump back to you last visual selection)
- gv
- visual select something, go to another place and do some other job,
gvto reselect the visual text
- conjoin lines, but without leaving space between them ( unlike J )
- gJ
- jump back to last edit position
- g;
- jump back to the previous position where a change was made in the current buffer.
- The "Zen" of vi is that you're speaking a language.
yy- The initial y is a verb.
- The statement yy is a synonym for y_. The y is doubled up to make it easier to type.
- the verb can take any movements as their "subject."
- vi has 26 "marks" and 26 "registers." ( lower case characters)
masets the 'a' mark to the current location- use
'a(single quote) to jump the beginning of the LINE has 'a' mark - use
`a(backquote) to jump the precise location of the 'a' mark.-
markdown tips: use a space infront and surrounded by doulbe backquote to display single backquote.
-
similarly, use space infront and surrounded by single backquote to display double backquote.
``a
-
- more special mark jumping
``,'', to jump back to where jumped from`0, jump to position in last file edited (when exited Vim)`1, like`0, but the previous file (also`2etc)
- Because these are "movements" they can also be used as subjects for other "statements."
d`ato delete the content from current location to 'a' mark
- So, one way to cut an arbitrary selection of text would be to drop a mark.
- this is one way to cut or copy text. However, it is only one of many.
- Frequently we can more succinctly describe the range of text without moving our cursor around and dropping a mark.
- For example if I'm in a paragraph of text I can use { and } movements to the beginning or end of the paragraph respectively.
- So, to move a paragraph of text I cut it using
{ d}(4 keystrokes).
- Searching forwards or backwards are movements in vi. Thus they can also be used as "subjects" in our "statements."
d/abc, delete the content from current location to the next matchedabcy?abc, yark the content from current locationthe most recent (previous) matchedabd
- In addition to "verbs" and "subjects" vi also has "objects".
- So far I've only described the use of the anonymous register.
- However, I can use any of the 26 "named" registers by prefixing the "object" reference with " (the double quote modifier).
- Thus if I use
"addI'm cutting the current line into the 'a' register. - To paste from a register I simply prefix the paste with the same modifier sequence:
"appastes a copy of the 'a' register's contents. - This notion of "prefixes" is something like "adjectives" / "adverbs".
- Most commands (verbs) and movement (verbs or objects, depending on context) can also take numeric prefixes.
- Thus
3Jmeans "join the next three lines" - and
d5}means "delete from the current line through the end of the fifth paragraph down from here."
- Thus
- This is all intermediate level vi.
| part of speech | action | function | comments |
|---|---|---|---|
| verb | d | delete | |
| y | yank | ||
| c | change | ||
| f | find | ||
| r | replace (char) | then in enter mode | |
| s | Substitute (char) | then in insert mode | |
| noun | b | bracket () |
|
| s | sentence | ||
| p | paragraph | ||
| w | word | ||
| adj/prep. | i | in | |
| a | all |
example
| commands | function | comments |
|---|---|---|
| dib | delete content within (...) |
|
| dap | delete entire paragraph | |
| yap | yank entire paragraph | |
| caw | change a word | same effect as ciw |
| cas | change all sentense | |
| ci) | change in bracket | |
| c5w | change 5 words from current postion | |
| df, | delete from current position up to and including the next , |
|
| d/foo | delete from current postion up to the next pattern foo |
|
| d?foo | delete from current postion up to and including the previous pattern foo (backward find) |
|
| dt, | delete from current postion until the next , |
|
| y'a | yank lines, from current line up to the marked lines ('a) | |
| {d} | Jump to beginning of a paragraph, then delete it |
- There are a number of
:commands, most notably the:% s/foo/bar/gglobal substitution technique:commands normally operate over lines of text. The whole : set of commands was historically inherited by vi's previous incarnations ,ed and ex, very elder.- So the syntax of most
:commands includes an address or range of addresses (line number) followed by a command. :127,215 s/foo/barto change the first occurrence of "foo" into "bar" on each line between 127 and 215- One could also use some abbreviations such as
.or$for current and last line respectively - One could also use relative prefixes
+and-to refer to offsets after or before the curent line, - Thus,
:.,$jmeaning "from the current line to the last line, join them all into one line". - NOTE:
:%is synonymous with:1,$(all the lines).
- The
:...gand:...vcommands are incredibly powerful.:...gis a prefix for "globally" applying a subsequent command to current line which match a pattern (regular expression)- while
:...vapplies such a command to current line which do NOT match the given pattern ("v" from "conVerse"). - Thus
:.,+21g/foo/dmeans "delete any lines containing the string "foo" from the current one through the next 21 lines" - while
:.,$v/bar/dmeans "from here to the end of the file, delete any lines which DON'T contain the string "bar." -
It's interesting that the common Unix command grep is named after this way. The command
:g/re/pwas the way how to "globally" "print" lines containing a "regular expression" (re). - Note that
:% g/.../dor (its reVerse/conVerse counterpart::% v/.../dare the most common usage patterns.:g/.../d同样效果?
- In
:command, we can usemto move lines around, andjto join lines.- if you have a list and you want to separate all the stuff matching without deleting them, (or conversely NOT matching some pattern)
- then you can use something like:
:% g/foo/m$ ...and all the "foo" lines will have been moved to the end of the file. - Note the other tip about using the end of your file as a scratch space
- then you can use something like:
:% g/Another/-1j, for every matching line, go up one line and join them.
- if you have a list and you want to separate all the stuff matching without deleting them, (or conversely NOT matching some pattern)
- Almost needless to mention you can use our old friend s (substitute) with the g and v.
:% g/foo/s/bar/zzz/gfor every line containing "foo" substitute all "bar" with "zzz."
- The
:addresses can also refer to marks.- Thus you can use:
:'a,'bg/foo/jto join any line containing the string foo to its subsequent line, if it lies between the lines between the 'a' and 'b' marks.
- Thus you can use:
- Another very useful vi or ex command is
:rto read in the contents of another file.- Thus: :r foo inserts the contents of the file named "foo" at the current line.
- More powerful is the
:r!command. This reads the results of a command , and insert it at the current line.
- Even more powerful are the
!(bang) and:... !(ex bang) commands.- These also execute external commands and read the results into the current text.
- However, they also filter selections of our text through the command!
- This we can sort all the lines in our file using
1G!Gsort. This is equivalent to the ex variant:1,$!sort. -
Writers often use ! with the Unix fmt or fold utilities for reformating or "word wrapping" selections of text.
- A very common macro is
{!}fmt(reformat the current paragraph).
- This we can sort all the lines in our file using
- Another useful ex command is
:so(short for:source).- This reads the contents of a file as a series of commands.
- The @ command is probably the most obscure vi command.
- @ executes the contents of a register as if it were a vi or ex command.
- Common editors can generally specify whether to use a normal search or a regular expression search.
- But the vim use a mixed search, magic (\m) mode
- For example, the
/foo(1)command, which most people use to find the stringfoo(1). - Therefore, vim stipulates that the metacharacters of regular expressions must be escaped with backslashes. As in the above example, if you really want to use regular expressions, you should write
/foo\(1\) - However, it is inconvenient to add backslashes to extremely common metacharacters like
.*.
- For example, the
- To solve this problem, vim sets the magic:
- magic (\m): all metacharacters except
* . ^ $ []need backslashing
- magic (\m): all metacharacters except
- But if you are strongly prefer normal regular expression, you can use very magic mode (\v), it is Perl-regex-compatible
- but you can NOT set it as default, it will lead to plugin's compatibility problems
- There are 2 more modes you can use
mode metacharacters need backslashing activated by comments Magic all except * . ^ $ []\mdefault modifier Very Magic N/A, Perl-regex-compatible \vNo Magic all except ^ $\MVery No Maigc all \Vnormal text search
| Capability | in Vimspeak | in Perlspeak |
|---|---|---|
| force case insensitivity | \c |
(?i) |
| force case sensitivity | \C |
(?-i) |
| backref-less grouping | \%(atom\) |
(?:atom) |
| conservative quantifiers | \{-n,m} |
*?, +?, ??, {}? |
| 0-width match | atom\@= |
(?=atom) |
| 0-width non-match | atom\@! |
(?!atom) |
| 0-width preceding match | atom\@<= |
(?<=atom) |
| 0-width preceding non-match | atom\@<! |
(?<!atom) |
| match without retry | atom\@> |
(?>atom) |
- Capture group notation is slightly different from perl, use
@instead of(? - The location of the pattern for capturing groups in vim differs from perl
- For example, to find bar immediately after foo,
- perl writes the pattern foo inside the lookaround (
?<=) brackets,(?<=foo)bar
- perl writes the pattern foo inside the lookaround (
- while vim writes the pattern before the lookaround metacharacter ,
(foo)@<=bar
- For example, to find bar immediately after foo,
- vim matches the beginning and end of words using
<,>,\bis used to match<BS>