Neovim

about | blog | config | notes | github

neovim_logo.png

Neovim is a fork of vim that aims to modernize vim. This config below is primarily targeted at Neovim, but with a few minor modifications (if any, I recalling getting the same config to work at some point), it can work with the vim.

1. Tips and Tricks

I'll add useful help messages here at some point…

2. Trivia

  • According to [BROKEN LINK: hillelwayne.com/post/always-more-history/], vi uses hjkl as the arrow bindings not but its own design. But because the software was developed on the ADM-3A. This keyboard didn't have dedicated arrow keys, but made use of control characters (the first 32 characters of the 1967 ASCII Table). As a result, ctrl-{h,j,k,l} became the designated keys for moving the cursor around. When Bill Joy developed vi, he used hjkl for the arrow keys as it was only naturally having used the ADM-32.

3. Configuration

3.1. Load Vim Plugins (VimPlug)

call plug#begin('~/.vim/plugged')

" vim-airline:
" Lean & mean status/tabline for vim thats light as air
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'morhetz/gruvbox'

Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'

Plug 'jamessan/vim-gnupg'
Plug 'chrisbra/csv.vim'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
Plug 'mattn/calendar-vim'

" Plug 'valloric/youcompleteme'
Plug 'yggdroot/indentline'
Plug 'mbbill/undotree'

" Language Based Plugins
Plug 'JuliaEditorSupport/julia-vim'
Plug 'ledger/vim-ledger'
Plug 'nathangrigg/vim-beancount'
Plug 'vim-scripts/gnuplot.vim'

call plug#end()

3.2. Configure loaded plugins

3.2.1. Vim Airline

" vim-airline
let laststatus = 2
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1

" vim-airline-themes
" let g:airline_theme = 'base16_gruvbox_dark_hard'

3.2.2. Git Gutter

" git-gutter
nmap <C-M-j> <Plug>GitGutterNextHunk
nmap <C-M-k> <Plug>GitGutterPrevHunk
let g:gitgutter_set_sign_backgrounds = 1

3.2.3. Indent Lines

" Indent Lines
"let g:indentLine_char = '.'
let g:indentLine_char_list = ['|', '¦', '┆', '┊']
let g:indentLine_setColors = 1
"let g:indentLine_bgcolor_term = 0
let g:indentLine_color_term = 8
let g:indentLine_conceallevel = 2
let g:indentLine_concealcursor = "n"

3.2.4. Vim Ledger

" Configure vim ledger
let g:ledger_maxwidth = 80
let g:ledger_bin = 'ledger'
let g:ledger_extra_options = '--pedantic --explicit'
let g:ledger_align_at = 77
let g:ledger_date_format = '%Y-%m-%d'

3.2.5. Markdown

" Markdown conceal
let g:vim_markdown_conceal = 0
let g:vim_markdown_conceal_code_blocks = 0

3.2.6. Vim Wiki

" Vim Wiki
let personal_wiki = {}
let personal_wiki.name = 'Tabula Rasa'
let personal_wiki.path = '~/usr/wiki/src'
let personal_wiki.path_html = '~/usr/wiki/.html'
let personal_wiki.syntax = 'markdown'
let personal_wiki.ext = '.md'
let personal_wiki.maxhi = 1
let personal_wiki.diary_rel_path = "journal/"
let personal_wiki.diary_index = "toc"
let personal_wiki.diary_header = "Personal Journal"
let personal_wiki.diary_caption_level = 0
let personal_wiki.auto_diary_index = 1

let g:vimwiki_list = [personal_wiki]
let g:vimwiki_global_ext = 1
let g:vimwiki_listsyms = ' ○◐●✓' " '✗○◐●✓'
let g:vimwiki_folding = 'expr'
let g:vimwiki_hl_cb_checked = 2

3.3. Setup Sane Vim Defaults

set nocompatible
set number          " Show Line numbers
set ruler           " Show line and column number of the cursor
set cursorline      " highlight current line
set cursorcolumn    " Create a column for where the cursor is
set colorcolumn=80  " Create a column to show where 80 chars are
set modeline        " Allow source files to configure vim as well
set nowrap

" TAB = 4 SPACES
set tabstop=4           " number of visual spaces per TAB
set softtabstop=4   " number of space in TAB while editing
set expandtab           " TABs are now SPACEs
set shiftwidth=4    " Allows helps to make it 4 spaces in neovim

filetype plugin on
filetype indent on  " Load filetype-specific indent files
syntax on

set wildmenu        " visual autocomplete for command menu
set lazyredraw      " redraw only when we need to

set showmatch       " highlight matching brackets [{()}]
set incsearch       " search as characters are entered
set hlsearch        " highlight matches

set noshowmode      " Stop showing the default mode

set mouse=a         " Set mouse wheel to scroll

" Code concealing
set conceallevel=2
set concealcursor-=n

" Enable Code Folding
set foldenable
set foldlevelstart=10
set foldnestmax=10
set foldmethod=indent    " fold based on ident level

" Custom file search
set path+=**

3.4. Vim Colorschemes

" Use peachpuff built-in colorscheme as the base
colorscheme peachpuff

" Color of the Columns
highlight ColorColumn ctermbg=black
highlight CursorColumn ctermbg=black
highlight VertSplit ctermfg=black

" Change the default coloring of line numbers
highlight LineNr ctermfg=black

" Change colorscheme of Pmenus
highlight Pmenu ctermfg=darkgrey ctermbg=black

" Set background color of folded blocks
highlight Folded ctermbg=black

" Some syntax highlighting changes (maybe move this to its own file)
highlight Function ctermfg=darkblue
highlight String ctermfg=darkgreen
highlight Comment ctermfg=darkgrey
highlight Exception ctermfg=darkred

" Fix colors on gitgutter after colorscheme has been set
highlight SignColumn ctermbg=None
highlight GitGutterAdd ctermbg=None ctermfg=green
highlight GitGutterChange ctermbg=None ctermfg=yellow
highlight GitGutterDelete ctermbg=None ctermfg=red

" Change colors to be more intuitive for vimwiki
highlight VimwikiHeader1 ctermbg=None ctermfg=darkred
highlight VimwikiHeader2 ctermbg=None ctermfg=darkblue
highlight VimwikiHeader3 ctermbg=None ctermfg=darkgreen
highlight VimwikiHeader4 ctermbg=None ctermfg=yellow
highlight VimwikiHeader5 ctermbg=None ctermfg=cyan
highlight VimwikiHeader6 ctermbg=None ctermfg=magenta

highlight Conceal ctermbg=None ctermfg=darkblue

3.5. Custom Keybindings

" Sets a keybind to turn off highlighted searches
nnoremap <leader><space> :nohlsearch<CR>

" Keybinds to quickly switch buffers
noremap <S-j> :bn<CR>
noremap <S-k> :bp<CR>

" Custom git mappings (is fugitive or gitgutter better to use instead?)
noremap <F2> :Git <CR>
noremap <F3> :Git diff<CR>
noremap <F4> :Gclog<CR>

" Key binds to toggle the Undo Tree
noremap <F5> :UndotreeToggle<CR>

noremap <F6> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") .
    \ '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
    \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" .
    \ " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#")<CR>

" Ledger remap tab completion
au FileType ledger inoremap <silent> <Tab>
            \ <C-r>=ledger#autocomplete_and_align()<CR>
au FileType ledger vnoremap <silent> <Tab>
            \ :LedgerAlign<CR>
au FileType ledger nnoremap <silent> <C-m>
            \ :silent<space>make<bar>redraw!<bar>cwindow<CR>
au FileType ledger nnoremap <silent> <C-s>
            \ :call ledger#transaction_state_toggle(line('.'), ' !*?')<CR>

" Vimwiki doc pubs open
autocmd FileType vimwiki nnoremap <Leader>p :silent !pubs doc open %:r<CR>

3.6. Custom Vim Functions

3.6.1. Trim Whitespace

" Trim the whitespace present in a file
fun! TrimWhitespace()
    let l:save = winsaveview()
    keeppatterns %s/\s\+$//e
    call winrestview(l:save)
endfun
command! TrimWhitespace call TrimWhitespace()

3.6.2. Toggle Calendar

" Toggle calendar view within view if in vim wiki
function! ToggleCalendar()
    execute ":Calendar"
    if exists("g:calendar_open")
        if g:calendar_open == 1
            execute "q"
            unlet g:calendar_open
        else
            g:calendar_open = 1
        end
    else
        let g:calendar_open = 1
    end
endfunction
:autocmd FileType vimwiki map <leader>c :call ToggleCalendar()<CR>

3.6.3. Workspace Management

function! WinMove(key)
    let t:curwin = winnr()
    exec "wincmd ".a:key
    if (t:curwin == winnr())
        if (match(a:key,'[jk]'))
            wincmd v
        else
            wincmd s
        endif
        exec "wincmd ".a:key
    endif
endfunction

nnoremap <silent> <C-h> :call WinMove('h')<CR>
nnoremap <silent> <C-j> :call WinMove('j')<CR>
nnoremap <silent> <C-k> :call WinMove('k')<CR>
nnoremap <silent> <C-l> :call WinMove('l')<CR>

3.7. Vim mode line

" vim:ft=vim

Created: 2021-11-13

Emacs 26.1 (Org mode 9.5)