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-sensible – basics
- matchit – provided by vim
-
securemodelines – vim-scripts
-
winmanager – vim-scripts
-
bufexplorer – vim-scripts
-
gnupg – vim-scripts
- vim-spell-under – osamu: syntax highlight to work with spell checker
- vim-python-matchit – osamu: patched 0.5 to jump to “else”, too for “for” and “while”
- vim-better-whitespace – github
- vim-indent-guides – github
- ale – github: linter interface configured to be on-demand display
- gitgutter – github: git interface configured to be on-demand display
- fzf and fzf.vim with rg – github: menu based selection interface
- access extra functionalities with
<leader>
-sequences.
- access extra functionalities with
- vim-airline and vim-airline-themes – github: nerdy look
Please note actual basic configuration settings are in
~/.vim/vimrc
. This file includes the Vim 8 native package management. The whole~/.vim/
contents are at dot-vim.I use linters with very quiet configuration defined in my dotfiles. The backup copies of these dotfiles are at osamu-utils. No sensitive info’s are in these. That’s backed up locally.
I now set up those IDE-like fancy heavy features (ale, gitgutter, fzf) as on-demand display modification and low profile from user’s view. (We can further disable packages by comment out corresponding
packadd!
line with leading"
.)Also, cursor remembers its position.
Vim general settings (keyboard bindings)
Thought on configuration and keyboard bindings are:
- Use external packages as little exposure as possible.
- Use CapsLock for Esc via GNOME Tweak setting.
- Less key binding customization is better.
- Never change data modifying functionality
- Adding limited shell-like control key bindings to undefined in INSERT and COMMAND modes.
- Provide alternative safer access to some keys (CTRL-W: this deletes a word in INSERT)
- Avoid redefining keys with similar improved variants
- If functionalities are needed, instead, define new ones to unused keys such
as
<leader>
-combinations (usually with 1 or 2 keys. I think that 2 keys are good compromise for not so used functions. - Give access to FZF.VIM provided functions with
<leader>
+2 chars.
- If functionalities are needed, instead, define new ones to unused keys such
as
- Don’t try to do things with Vim when other tools do them better.
gitk
for Git history and diffmc
for interactive file explorer.
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:
Q
: Paste MACRO (routine for keyboard MACRO just withq
-key. NORMAL MODE:qq
+ … +<Esc>
+q
+Q
…) by defining unused ‘Q’ as ‘@q’<C-F>
as<Right>
,<C-B>
as<Left>
,<C-D>
as<Del>
for INSERT and REPLACE and COMMAND.- Use
<C-O>
as ‘cedit’ for COMMAND MODE to open editable command history. (No more surprise) <leader><leader>
: Highlight search word under the cursor in NORMAL, or exact selected word in VISUAL to “-register<C-L>
to clear highlight (Redefinition but harmless modification to its presentation details)<leader>r
to create replace-all template
<leader><CR>
: TERMINAL-JOB start<Esc><Esc>
or<Esc>
: get out to TERMINAL-NORMALi
: get back to TERMINAL-JOB
<leader>e
: Strip whitespaces at EOL (vim-better-whitespace)<leader>p
: Toggle Pase/NoPaste (No more )<leader>w
: Toggle WinManager<leader>b
: Toggle BufferExplorer<leader>ss
: Rotate SPELL and SYNTAX mode – default<leader>aa
: Toggle ALE (ALE)- Set up linters as osamu-utils
<leader>gg
: Toggle GitGutter (GitGutter)<leader>hp
: hunk preview (GitGutter) – default<leader>hs
: hunk stage (GitGutter) – default<leader>hu
: hunk undo (GitGutter) – default
- FZF commands (down-selection tool)
<leader>fb
: Buffers selection (FZF.VIM)<leader>fc
: Color selection (FZF.VIM)<leader>ff
: Files selection (FZF.VIM)<leader>gl
: GFiles selection (FZF.VIM) –git ls-files
<leader>gs
: GFiles? selection (FZF.VIM) –git status
<leader>fm
: Maps listing with selection (FZF.VIM)<leader>fr
: Rg search selection (FZF.VIM)<leader>??
: many others (FZF.VIM)
For selecting TAB opened from FZF with CTRL-T.
<leader>1
: Tab 1<leader>2
: Tab 2- …
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
- Quoted string in VimScript is single quote.
- Comment lines start with double quote
- Line continuation is reverse slash prepended to the following line. It seems leading blank characters are allowed.
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:
- shell:
shellcheck
- python3:
pylint
andflake8
(These needs to be set to be quiet to avoid excessive noise.) See https://github.com/osamuaoki/osamu-utils/tree/main/dot/.config for backed up settings.
Since these can clutter screen, I am setting its display of reports to be toggles on demand.
LSP hasn’t been used.
- https://github.com/dense-analysis/ale (FAQ)
- https://www.vimfromscratch.com/articles/vim-and-language-server-protocol/
- https://github.com/rhysd/vim-lsp-ale
- https://github.com/prabirshrestha/vim-lsp
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.
- Mark all types of spaces in wrong position on display.
- Strip spaces at EOL upon hitting “
<SPACE>e
” only.
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 |