Mastodon hachyterm.io

I use Vim again as my main editor, and I go the minimal route.

Why?

Minimal Vim is a portable skill. Vim is everywhere, on every machine. It works all the time.

Vim has its own language and combined with the Unix philosophy, it is quite powerful.

For text editing, I can do a lot of things with Vim’s built-in tools.

The Config

So, let’s see my current config:

" https://github.com/romainl/idiomatic-vimrc#suggested-minimal-settings-for-programming

"==============================================================================
" Filetypes & syntax
"==============================================================================

" Enabling filetype support provides filetype-specific indenting,
" syntax highlighting, omni-completion and other useful settings.
if has('autocmd')
  filetype plugin indent on
endif
if has('syntax') && !exists('g:syntax_on')
  syntax enable
endif

" `matchit.vim` is built-in so let's enable it!
" Hit `%` on `if` to jump to `else`.
runtime macros/matchit.vim

"==============================================================================
" Files & backups
"==============================================================================

set regexpengine=0                " Set automatic regex expression engine
set nobackup                      " Don't create backup files.
set nowritebackup                 " Don't create backup before writing.
set noautowrite                   " Don't auto save.
set noswapfile                    " Don't create swap files.

"==============================================================================
" Editor behavior
"==============================================================================

set updatetime=300                " Faster completion.
set timeoutlen=500                " Key timeout duration.
set ttimeoutlen=0                 " Key code timeout.

set noerrorbells                  " No error bells.
set noautochdir                   " Don't auto change directory.
set selection=exclusive           " Selection behavior.
set mouse=a                       " Enable mouse support.
set clipboard+=unnamedplus        " Use system clipboard.
set cursorline                    " Display cursorline.
set autoread                      " Read file automatically when changed outside of vim.
set autoindent                    " Minimal automatic indenting for any filetype.
set backspace=indent,eol,start    " Proper backspace behavior.
set hidden                        " Possibility to have more than one unsaved buffers.

"==============================================================================
" Searching & completion
"==============================================================================

set path+=**                      " Include subdirectories in search.

set ignorecase                    " Case insensitive search.
set smartcase                     " Case sensitive if uppercase in search.
set nohlsearch                    " Don't highlight search results.
set incsearch                     " Show matches as you type.

set ruler                         " Show line number at the bottom-right of the screen.
set wildmenu                      " Command-line completion: <Tab> to move, <CR> to validate.
set completeopt=menuone,popup,noselect,noinsert " Insert-mode completion: popup menu.

"==============================================================================
" Display
"==============================================================================

set number                        " Show absolute line numbers.
set signcolumn=yes                " Keep the gutter width stable.

set termguicolors
colorscheme=alabaster

"==============================================================================
" Folding
"==============================================================================

set foldmethod=indent
set shiftwidth=2                  " Indent folds are computed from this.
set foldlevel=99                  " Open all folds at startup.
nnoremap <Leader>z za

"==============================================================================
" Mappings
"==============================================================================

" Leader
let mapleader=" "
nnoremap <space> <nop>
let maplocalleader=","
nnoremap , <nop>

" list buffers, then navigate
nnoremap <leader><space> :ls<cr>:b<space>

" Tag jumping
" - Use <Leader>] or ^] to jump to tag under cursor
" - Use g^] for ambiguous tags
" - Use ^t to jump back up the tag stack
nnoremap <Leader>] <C-]>

" undotree ships no keybinding of its own - its <Plug>Undotree* maps only exist
" while the panel is open. Using <Leader>U leaves the 'u' letter free: unimpaired
" already reserves it as the cursorcolumn toggle (<Plug>(unimpaired-toggle)u).
nnoremap <Leader>U :UndotreeToggle<CR>

"==============================================================================
" Smart path (fd, respects .gitignore)
" https://teukka.tech/posts/vimtip-path/
"==============================================================================

function! s:SetSmartPath()
  if executable('fd')
    let l:dirs = systemlist('fd . --type d')
    if v:shell_error == 0 && !empty(l:dirs)
      let &path = '.' . ',' . join(l:dirs, ',')
    endif
  endif
endfunction

augroup SmartPath
  autocmd!
  autocmd VimEnter * call s:SetSmartPath()
augroup END

"==============================================================================
" Hyphen keyword scoping
"==============================================================================

" '-' belongs inside identifiers (snake_case, kebab-case) in some filetypes,
" but globally it also swallows '-', so that `d-`, `f-` and friends become
" word motions in every other language. Scope it instead.
let s:hyphen_filetypes = [
      \ 'css', 'html', 'javascript', 'typescript', 'typescriptreact',
      \ 'json', 'yaml', 'ruby', 'python', 'sh', 'lua', 'markdown',
      \ 'scss', 'less',
      \ ]

function! s:SetHyphenKeyword() abort
  setlocal iskeyword&
  if index(s:hyphen_filetypes, &filetype) >= 0
    setlocal iskeyword+=-
  endif
endfunction

augroup HyphenKeyword
  autocmd!
  autocmd FileType * call s:SetHyphenKeyword()
augroup END

"==============================================================================
" Window layout
"==============================================================================

augroup WindowLayout
  autocmd!
  autocmd VimResized * wincmd =
augroup END

"==============================================================================
" netrw
"==============================================================================

let g:netrw_banner=0               " disable annoying banner
let g:netrw_browse_split=4         " open in prior window
let g:netrw_altv=1                 " open splits to the right
let g:netrw_liststyle=3            " tree view
let g:netrw_keepdir=1              " keep current directory unchanged while browsing
let g:netrw_localcopydircmd='cp -r' " recursive copy
packadd! netrw
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'

"==============================================================================
" Persistent undo
"==============================================================================

if has("persistent_undo")
  let target_path = expand('~/.undodir')

  " create the directory and any parent directories if the location is missing.
  if !isdirectory(target_path)
    call mkdir(target_path, "p", 0700)
  endif

  let &undodir=target_path
  set undofile
endif

"==============================================================================
" grep: ripgrep
"==============================================================================

if executable('rg')
  set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case
  set grepformat=%f:%l:%c:%m
endif

There are a few convenient settings I like or “stole” from romainl’s idiomatic vimrc.

I also have a few plugins like tpope’s vim-fugitive and vim-surround, but nothing too fancy.

No LSP?!

LSP setup has always been a bit finicky and needed a lot of configuration work.
I am trying to get by without LSP.

Is that really minimal?

I use some plugins and my .vimrc has a few options that are not strictly necessary.

For me, it is minimal. A few years ago I had several files with tons of keybindings, lots of plugins (ALE, fuzzy finding, LSP, etc.).

My current setup is more “vanilla” than before. It’s still close to the default experience, so that I don’t schlepp around so many customization that a session on a remote server throws me off.