Vim's completion behaviour in insert mode

现象 在使用Vim的补全的时候,可能从其他IDE/编辑器过来的同学可能会对Vim在弹出补全菜单后,Tab和Enter的行为感到不理解,例如经常会直接插进一个制表符或者换行回车,这其实是Vim自己在插入模式下补全功能的特殊设计,至于为什么这么设计,那就得问开发者了:) 原因 以下摘自Vim的帮助文档 :help popupmenu-completion,简单来说就是Vim的插入模式处于补全状态时,其实有3个状态,不同状态下Enter的功能表现是不一样的,而Tab在Vim补全的上下文和Space几乎是一样的,就是插入对应的空格/制表符 There are three states: A complete match has been inserted, e.g., after using CTRL-N or CTRL-P. A cursor key has been used to select another match. The match was not inserted then, only the entry in the popup menu is highlighted. Only part of a match has been inserted and characters were typed or the backspace key was used. The list of matches was then adjusted for what is in front of the cursor. In all three states these can be used: CTRL-Y Yes: Accept the currently selected match and stop completion. CTRL-E End completion, go back to what was there before selecting a match (what was typed or longest common string). Select a match several entries back, but don’t insert it. Select a match several entries further, but don’t insert it. Select the previous match, as if CTRL-P was used, but don’t insert it. Select the next match, as if CTRL-N was used, but don’t insert it. or Stop completion without changing the match and insert the typed character. ...

February 1, 2023 · 2 min · ChaosNyaruko

Rob Pike's 5 Rules of Programming

Rob Pike’s 5 Rules of Programming Rule 1. You can’t tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don’t try to second guess and put in a speed hack until you’ve proven that’s where the bottleneck is. Rule 2. Measure. Don’t tune for speed until you’ve measured, and even then don’t unless one part of the code overwhelms the rest. Rule 3. Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don’t get fancy. (Even if n does get big, use Rule 2 first.) Rule 4. Fancy algorithms are buggier than simple ones, and they’re much harder to implement. Use simple algorithms as well as simple data structures. Rule 5. Data dominates. If you’ve chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming. Pike’s rules 1 and 2 restate Tony Hoare’s famous maxim “Premature optimization is the root of all evil.” Ken Thompson rephrased Pike’s rules 3 and 4 as “When in doubt, use brute force.”. Rules 3 and 4 are instances of the design philosophy KISS. Rule 5 was previously stated by Fred Brooks in The Mythical Man-Month. Rule 5 is often shortened to “write stupid code that uses smart objects”.

January 20, 2023 · 2 min · ChaosNyaruko

今天摸鱼水段子时,在/r/ProgrammerHumor/上发现一个有意思的现象 熟悉Python的同学可能都踩过坑,但我确实是第一次知道这个现象,于是我在本地试了一下,发现确实如此,于是我求助于谷歌,并最终在Python的官方文档里找到了解释 Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input. For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). Any integer value is valid for ndigits (positive, zero, or negative). The return value is an integer if ndigits is omitted or None. Otherwise, the return value has the same type as number. ...

January 3, 2023 · 1 min · ChaosNyaruko

Get Server A basic VPS is enough for personal usage. Nginx Setup apt install nginx main directories and files: /etc/nginx/sites-available /etc/nginx/sites-enabled(typically symbolic links for “available”) /etc/nginx/nginx.conf /var/log/nginx/access.log /var/log/nginx/error.log Get HTTPS Cert Support Using HTTPS should be modern and more secure. https://snapcraft.io/docs/installing-snap-on-debian https://certbot.eff.org/instructions?ws=nginx&os=debianbuster We use certbot to get https support for your website, and renew automatically. Debian10/11 operation example: apt install snapd snap install core snap install hello-world snap refresh core snap install --classic certbot ln -s /snap/bin/certbot /usr/bin/certbot certbot --nginx / certbot certonly --nginx certbot renew --dry-run The job should be in: ...

December 16, 2022 · 1 min · ChaosNyaruko

Don't use Vim

The ORIGINAL post Don’t use Vim Don’t do the crime, if you can’t do the time. – Anthony Vincenzo “Tony” Baretta Vim is an amazing text editor. I love it. Really, I wouldn’t organize a Vim advent calendar if I didn’t. But, as amazing as it is, Vim is not for everyone. It can’t solve all your problems, or be a TUI version of your favorite IDE, or make you a better programmer, or land you that dream job in the Bay Area. But Vim can help you be more mindful, focused, and efficient, as long as you approach it with the right mindset. ...

August 29, 2022 · 10 min · Me