-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim.txt
264 lines (219 loc) · 14.2 KB
/
vim.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
[[{vim]]
# Vim Cheat Sheet
vim History: <https://begriffs.com/posts/2019-07-19-history-use-vim.html>
- Core Author: Bram Moolenaar ([email protected])
## CONCEPTS:
===========
vim buffer: in-memory buffer of file on disk.
vim window: graphical viewport on a buffer.
buffer N <--> M window (viewport)
vim tab: collection of windows.
:edit $file (:e ) open file in current window
:split $file (:sp) open file in a new horizontal split
(:vsplit for new vertical split)
EXIT VIM:
:w <- (w)rite to current file. (dump current memory buffer to file on disk)
:w <new_file> <- to <new_file>
:wa <- write all buffers
:q <- quit (! to force, loosing non writen modifications in buffer)
gf : edit file under your cursor in current window. (<c-O> to move to previous buffer)
<c-w>g: edit file under your cursor in new tab.
<c-w>f: edit file under your cursor in new vert. split.
<c-^>/<c-6>/<c-O>: navigate to previous buffer/scroll-line in current window
:h CTRL-^ and :h alternate-file for more info.
TIP: Learn to use :b and :sb to switch buffers instead of cycling! (See :h :b)
# BASICS: │ *VISUAL("EASY") MODE*: │
───────────────────────────────────────────────┼─────────────────────────────────────┤
[Esc] key ← exit edit/visual/... mode │ v: start V. (mark) mode │
:help "keyword" ← open help for keyword │ (then apply command on it) │
:ls ← list open buffers │Ctrl: Enter Visual Block Mode. Very │
:b 3 ← edit buffer 3 │ + v powerful to draw ASII diagrams,│
u | Ctrl + r ← Undo | Redo │ edit tabbed data, repetitive │
. ← repeat last command │ "switch-case like" code,... │
...! ← '!' forces cmd ... │ > ← shift text right │
execution │ < ← shift text left │
:!sh ← pass visual-block/range as STDIN to
sh/python/... and replace block/range
with STDOUT from sh/python/... execution
☞ Any action(insert/delete/...) prefixed with number "N" is repeated "N" times☜
INSERT/EDIT: *(BOOK)MARKING* ☞FAST MOVE☜ among code
(i)nsert before cursor │ (r)eplace single character │ ma ← set local ( line) (m)ark
(I)nsert start of line │ (J)oin line below with space │ mA ← set global (file,line)book(m)ark
(a)ppend after cursor │ (gJ) " " witouth "" │ 'a ← go to 'a' (file+line)
(A)ppend at end-of-line │ (cc)hange/replace entire line │ :marks ← list "book"marks
(o)pen(add) new line below │ (C)hange/ " to end-of-line
(O)pen(add) new line above │ (ciw)hange/replace word │ *MACROS*
(ea) append at end-of-word │ (cw)hange/replace to end-of-word │ qa ← start recording macro 'a'
(q)uit|close current pane │ gwip - reflow paragraph │ q ← stop recording
(buffer still in memory)│ │ @a ← run macro 'a'
(d)elete marked text │ │ @@ - rerun last macro
(R)eplace (vs insert) │ │ TIP: macros are really powerful, they
│ │ can be used even as a basic data
│ │ processing engine.
● MOVE RELATIVE TO:
▶ cursor ▶ word ▶ screen
│ ↑k │ w: forward to w.start │ H: S. top
└ ←h ↓j →l │ b: backward to w.start │ M: S. middle
─ └ e: forward to w. end │ L: S. low
▶ window: <c-w>+... │ Ctrl+b: back full
│ ↑k ▶ Scroll: │ Ctrl+u: back half
│ ←h ↓j →l │ Ctrl + e : down 1 line │ Ctrl+f: for. full
│ <c-w>_: "maximize" win └ Ctrl + y : up 1 line └ Ctrl+d: for. half
│ <c-w>=: make all win.
│ same size
│ :h CTRL-W : Help
└
▶ code-block: ▶ line:
│ %: jump to "peer" │ 0: start-of-l.
│ block-delimiter │ $: end-of-l.
│ ({[←...→)}] │ 9g: line 9
│ {: prev. paragraph │ gg: first line of d.
│ or block. │ G: last line of d.
│ }: next paragraph └ 4G: 4th line of d.
└ or block
*SEARCH*(regex) *REPLACE* (re gex) *YANK("COPY") AND PASTE* *REGISTERS* (C&P for the pros)
/... ← forward search │:%s/XX/YY/... ← (s)ubstitute XX→YY │ yy ← yank line │ :reg ← show registers content
?... ← backward " │ ^ ^ ┌ i == ignore case │ yw ← yank to next work │ "xy ← yank into register x
(n)ext: repeat search │ │ flags├ g == ** * │ y$ ← yank to end-of-line │ (persist @ ~/.viminfo)
(N) backward │ │ └*c == confirm* │ (p)aste after cursor │ "xp ← paste "x"─reg.
│ │ ┌ % : All file │ (P)aste before cursor │ (y)ank("copy") marked text
│ └ range├ 3,$: line 3 to end │ dd ← cut line
│ └ ... │ dw ← cut to next word
│ ** *: all matches in line │ (D)elete to end-of-line
│ vs just first │ x ← cut char. on cursor
*MULTIFILE EDIT* *TABS* *SPELL CHECK (7.0+)*
:e file_name (current pane, new buffer) │ :tabn ... open (new/existing)file │ :set spell spelllang=en_us
:bn (b)uffer (n)ext in current pane │ in new tab │ :setlocal spell spelllang=en_us
:bp (b)uffer (n)ext in current pane │ Ctrl+wT: move current window to new tab │ (^ prefer on mixed prose/code)
:bd (b)uffer (d)elete │ gt: (g)o next (t)ab (gT for prev) │ :set nospell ← turn-off
:ls*list buffers │ #gt (g)o to tab # │ - Color code:
:sp file_or_buffer hori.(s)plit→edit │ :tabm # (m)ove tab to #th pos. │ · Red : misspelled words
:vsp file_or_buffer vert.(s)plit→edit │ │ · Orange: rare words
Ctrl+ws: split window horizontally │ │ · Blue : words NOT capitalized
Ctrl+wv: split window vertically │ │]s [s ← Move to next/prev.error
Ctrl+w←: move to (←↑→↓) window │ │ z= : Show alternatives
│ zg : add to dict.
│ zw : remove from dict
# Package Manager (vim 8.0+/Neovim):
- Package manager: Replaces ad-hoc plugin managers before 8.0
(bundler, vim-plug,... *not needed anymore*)
│Package│ 1 ←···→ 1+ │plugin│ 1 ←····→ 1+ │vimscript│
- Use like:
$*$ mkdir -p ~/.vim/pack/$name/start* ← $name : arbitrary name, ussually local or plugin
~/.local/share/nvim/site/pack/$name/start for neovim
$*$ cd ~/.vim/pack/$name/start*
$*$ git clone $url_git_repo * ← use $*$ git pull ...* to update/swith package version
# ALE: (A)synchronous (L)int (E)ngine -> """lint while you type""".
- Vim Script Plugin (vs CoC NodeJS)
- Install:
$ mkdir -p ~/.vim/pack/git-plugins/start
$ git clone --depth 1 \
https://github.com/dense-analysis/ale.git \
~/.vim/pack/git-plugins/start/ale
- :help ale-options <·· help on global options
- :help ale-integration-options <·· help on options for particular linters.
- :help ale-fix <·· help on how to fix files with ALE.
Ctrl+k: ale_previous_wrap (nmap <silent> <C-k> <Plug>)
Ctrl+j: ale_next_wrap (nmap <silent> <C-j> <Plug>)
- :ALEFix "Fixing"
- :ALEFixSuggest ··> suggest some supported tools for fixing code.
- :ALEGoToDefinition (with LSP enabled)
- :ALEFindReferences (with LSP enabled)
- :ALEHover (with LSP enabled, show "brief info about symbol 'down' the cursor)
- : ALESymbolSearch (with LSP enabled)
- :ALERename (LSP? refactor)
- :ALEFileRename (LSP? rename file + fix import paths : tsserver only).
- : ALECodeAction (execute actions on cursor or visual range like automatically fixing errors).
- :ALEInfo Show linters configured for current file
- ALE makes use of job control functions and timers (NeoVim 0.2 and Vim 8+)
to run linters in the contents of text-buffers (in memory "real-time"
buffers vs saved-to-disk).
# CoC Plugin: Visual Code Intellisense support: [[{]]
<https://github.com/neoclide/coc.nvim>
- popular Vim plugin written in TypeScript.
WARN: dependent on the npm ecosystem for providing full IDE features to Vim.
- Both ALE and coc.nvim implement Language Server Protocol (LSP) clients for
upporting diagnostics (linting with a live server),
- easiest way to using 'ALE' and coc.nvim together:
REF: <https://github.com/dense-analysis/ale#faq-coc-nvim>
1) :CocConfig <··· Will open 'coc.nvim' config file
+ "diagnostic.displayByAle": true <··· add this line to inform coc.nvim to send diagnostics to ALE
so ALE controls how all problems are presented to you.
You can further configure how problems appear
by using all of the settings mentioned in ALE's
help file, including how often diagnostics are
requested. See :help ale-lint.
2) Edit ~/.vimrc and add:
+ let g:ale_disable_lsp = 1 <··· Disable LSP features in ALE (let coc.nvim in charge of it)
^^^^^^^^^^^^^^^^^^^^^^^^^
WARN: before plugins are loaded!!!
Optional:
'b:ale_disable_lsp' can also be set/unset in 'ftplugin' files to en/dis-able LSP features in ALE for different filetypes.
- add support for Language Server Protocol (LSP) allowing to reuse "Visual Studio Plugins"
*CoC Tunning* *CoC Troubleshooting*
─ Open definition/references/... in new tab: │- Try ':CocOpenLog' to find anything there that
→ :CocConfig │ might indicate the issue.
→ Fix entry: Ex: │- Ex: Fix CoC JAVA:
"coc.preferences.jumpCommand": "tab drop"│ → :CocConfig → Fix entry:
│ "java.home": "/usr/lib/jvm/java-14-openjdk"
│ → :CocCommand java.clean.workspace
│ → restart coc
│- :CocDisable
[[}]]
# Vim 9.0 (2022-06) [[{01_PM.NEW]]
- many small additions.
- Vim9 script.
- Much better performance by compiling commands (up to x10/x100)
- closer to common languages like JS/TypeScript/Java.
- Splitting up large script is much simpler with 'import/export' support
- WARN: No 100% backwards compatible by legacy scripts support
still working. (no plans to drop it)
- # vs " for comments.
- dictionary not available as function arg.
- error control.
- def vs function!
- argument+return types must be specified.
- Code coverage dramatically increased.
- Vim 8.2 (2019-12)
Vim is Charityware. You can use and copy it as much as you like, but
you are encouraged to make a donation for needy children in Uganda.
Please visit the ICCF web site for more information:
https://iccf-holland.org
[[01_PM.NEW}]]
## vim tips [[{01_PM.TODO]]
http://rayninfo.co.uk/vimtips.html
[[qa.UX]]
## YouCompleteMe
* <https://github.com/ycm-core/YouCompleteMe>
- an identifier-based engine that works with every programming language,
- a powerful clangd-based engine that provides native semantic code
completion for C/C++/Objective-C/Objective-C++/CUDA (from now on
referred to as "the C-family languages"),
- a Jedi-based completion engine for Python 2 and 3,
- an OmniSharp-Roslyn-based completion engine for C#,
- a Gopls-based completion engine for Go,
- a TSServer-based completion engine for JavaScript and TypeScript,
- a rls-based completion engine for Rust,
- a jdt.ls-based completion engine for Java.
- a generic Language Server Protocol implementation for any language
YCM also provides semantic IDE-like features in a number of languages, including:
- displaying signature help (argument hints) when entering the
arguments to a function call (Vim only)
- finding declarations, definitions, usages, etc. of identifiers,
- displaying type information for classes, variables, functions etc.,
- displaying documentation for methods, members, etc. in the preview
window, or in a popup next to the cursor (Vim only)
- fixing common coding errors, like missing semi-colons, typos, etc.,
- semantic renaming of variables across files,
- formatting code,
- removing unused imports, sorting imports, etc.
See Autocomplet vs CoC comparative video:
https://www.youtube.com/watch?v=ICU9OEsNiRA
## Clean vim registers effectively
https://stackoverflow.com/questions/19430200/how-to-clear-vim-registers-effectively
## Regex in vim
https://stackoverflow.com/questions/17731244/how-to-regex-in-vim
## vim bookmarks
* <https://github.com/MattesGroeger/vim-bookmarks>
[[01_PM.TODO}]]
[[vim}]]