Re-learning Vim (2)

Date: 2019/09/24 (initial publish), 2022/07/20 (last update)

Source: en/note-00007.md

Previous Post Top Next Post

TOC

This page is here as my old memo and contents are outdated. See:

Let’s review how I initialize Vim and use a few interesting packages.

Please note that I now manage package directly via the Vim 8’s native package management framework with packadd! without using so-called package managers.

Vim general settings (packages)

As of 2021-09-02, I mostly use the latest version from github for some fancy fast developing packages but also use older mature packages from Debian vim-scripts package.

Vim general settings (keyboard bindings)

Thought on configuration and keyboard bindings are:

As I read “Recommendations” again, I feel like I need to cut back on some fancy packages more. But as long as they do not slow down start up time and hidden under longer key sequences, I may keep them there. Currently, my start up time is about 70ms without airline+netrw enabled, and 300 ms with both enabled.

For now, I set them up as:

For selecting TAB opened from FZF with CTRL-T.

Most of FZF commands <leader>-commands are not used much. This is why I chose 2-chars. So I may change.

I set the font setting of GNOME terminal and GVim to Hack 14 point. Not all non-standard powerline fonts are included. So skip them in airline in override.vim. This font has easy-to-identify 0oO and 1lI fonts and some cute non-standard glyphs used for producing cute bar with airline.

Local entry point: ~/.vim/vimrc and ~/.vim/gvimrc

Let’s list highlight of configuration. Local configuration for each plugins are also included in this ~/.vim/vimrc file.

Quote and comment and line continuation in VimScript

Map <leader><leader> in NORMAL MODE and VISUAL MODE

This is to automatically select word below cursor (NORMAL, or visually highlighted word. Very useful for search and replace operation by working with ‘/’ and ‘?’ and ’n’ and ‘N’. It can also create substitute all template with <leader>r so this is more than '#' and '*'.

Map <Esc><Esc> and <Esc> to <C-\><c-n> in TERMINAL-JOB MODE

Since TERMINAL-JOB MODE feels like INSERT/REPLACE MODE, I didn’t like vim style <C-w>N nor odd neovim style <C-\><c-n> to get out. I accidentally typed <C-w> in INSERT MODE to lose data. Now I can always bang on <Esc><Esc> everywhere first if I want to move around windows.

Remapping <Esc><Esc> in addition to <Esc> avoids causing interference with the terminal escape code (ISO color etc.) and mapping/keyboard delays.

FZF.VIM issues are handled.

Map <Esc>h, <Esc>j, <Esc>k, <Esc>l

I have typed CTRL-W in INSERT and REPLACE mode ending up with breaken code. These are safer alternatives to avoid such incidences so I can bang always on <Esc>s and type these to move around screen. Even if I forget to be in NORMAL MODE, damages with these keys are minimal.

gvim font setting

Setting to ‘Hack 14’ required to use escaped space in the ~/.vim/gvimrc file.

External packages

dense-analysis/ale

This is used a lot for writing shell and python

This is a very nice syntax checker front-end.

See Development system (3) to understand how to set up backend linters. Setting these to be not-so-noisy are important part of their configuration. I also backuped them to my dotfiles: osamu-utils.

It is important to use static checker for interpreter languages since they usually don’t complain even if typo causes unused/non-assigned variables.

I use this with:

Since these can clutter screen, I am setting its display of reports to be toggles on demand.

LSP hasn’t been used.

ciaranm/securemodelines – vim-scripts

Features like “modeline” is very convenient but it may become source of security concern. This plugin disables Vim’s native capability for “modeline” but still enables very limited commands to be parsed.

Since this works even under “:set nomodeline” default start scheme, I am using this all the time.

osamuaoki/vim-spell-under

When syntax highlist and spell checker are activated together, text becomes difficult to read in some cases in terminal. This forces spell checker to use underline.

ntpeters/vim-better-whitespace

This is a new improved version of bronson/vim-trailing-whitespace . This takes care all weird UTF-8 spaces too.

My configuration marks all problematic spaces but only remove problematic dangling spaces upon explicit user request. (So the annoyance noticed by #vim Recommendations is addressed.)

nathanaelkane/vim-indent-guides

This is a plugin for visually displaying indent levels in Vim.

Unlike using vim native approach of “:set list” with “:set listchars=...” to visualize TAB and tailing spaces, vim-better-whitespace and vim-indent-guides doesn’t cause problem when selecting screen area with mouse-drags.

gnupg (vim-scripts)

This let you use gnupg.

matchit (vim internal and optional)

This let you move between matching { and } and similar pairs.

osamuaoki/vim-python-matchit

This let you move between matching if/try-block sections and for/while-block sections in python. Since for/while can have else in python, I patched upstream 0.5 to cover this case.

junegunn/fzf and junegunn/fzf.vim

I installed this to manage most of my <leader> interface commands for files, buffers, text search, … . Nice interactive window menus.

As for grepping the source, ripgrep(rg) and ugrep(ug) seems to be SMP aware and 10x faster than ag. Since rg is Git aware (.gitignore), this was my choice. I installed the Debian ripgrep package.

Since this use terminal mode, <Esc> handling needs to be adjusted to avoid crashing.

airblade/vim-gitgutter

It is installed but not activated on demand and default off.

romainl/vim-qlist

This has not been used much.

Native behavior of [I, ]I, [D, and ]D to search the keyword and the macro definition is a bit half baked. It should be much nicer if it allows to jump to pertinent positions as in the QuickFix list.

This script replaces these NORMAL MODE commands with more desirable behavior ones of the QuickFix list.

airblade/vim-gitgutter

This is not used much.

Checks diff from the repository contents asynchronously without blocking editor response and mark changed lines.

The display of git status is toggled on demand.

jceb/vim-orgmode

This has not been used. (Interesting) (commented out now)

vim-airline/vim-airline and vim-airline/vim-airline-themes

I understand this is only visual sugar candy and not much functionality improvement as Gurus told me. My startup time is 150ms with this and 80 ms without.

But it was irresistible … Sigh … Forgive me for my weakness. I try to use this with minimal complications, though.

Other similar packages such as rbong/vim-crystalline and itchyny/lightline.vim require you to write custom script from scratch and if such scripts are added, their claimed advantages may not be true any more. On the other side, the popular vim-airline seems to have addressed all the interference issues already and works as out-of-box as long as the latest version is obtained from github. (Well.. sort of. I had to adjust local font glyph availability issues.)

If I need really light statusline, I use bare static status line string defined in ~/.vim/vimrc). If vim-airline is active, this setting is overridden.

netrw, winmanager, bufexplorer

I was wondering ~/.vim/.netrwhist file. I realize this is related to netrw which is the native Vim filer in vim package. Not bad.

`vim-scripts has other 2 packages. These are kind of old and not-too-flashy but give me good UX for file and buffer uses on vim.

Filers provided by FZF.VIM is cute but I should learn this one too.

Previous Post Top Next Post