dotfiles/nvim/.config/nvim/keys/maps.vim
Marty Oehme 7bdf9ff8d2
nvim: Switch from vimL to lua setup
Switched to a lua setup. Moved from `init.vim` to `init.lua`. Moved to a
lua-based plugin manager (packer.nvim). Moved some plugins to neovim
(i.e. lua) versions instead of vimL (notably fzf and indentLine).
Enabled lsp, treesitter and similar plugins by default.
Modularized plugins a little by invoking them in separate files.

This should provide a base to build on, and allow me to more fully
integrate lua into my workflow.
More detailed changes follow:

nvim: Replace completion-nvim with nvim-compe

Replaced completion-nvim since compe comes with more things working out
of the box (especially buffer completion and treesitter save me two
plugin installations), and seems to be overall a bit better supported.

It's fast, it works well, and I can add custom completion sources so
that should be good enough for me.

Changed around a couple of other things for lsp settings and treesitter,
and moved the files around a bit.

This is somewhat in preparation for a move to a lua-based configuration,
since I have long wanted to make the switch.

nvim: Add treesitter-enabled rainbow brackets

Added rainbow brackets to the editor, using the treesitter AST
detection. I am not sure yet if I will keep them, or if they confuse me
more than they help by coloring *everything* *everywhere* and being a
bit too much for my tired eyes.

nvim: Add vim-terminator to enable repl style dev

Added vim-terminator and included some basic keybindings. The plugin
allows sending code over to a terminal window, or repl for those
languages where it's enabled (python, R, bash somewhat).

The basic workflow for me right now is: From e.g. a python file
1. Open a repl with <leader>rr
2. Send over code with
    2a. <leader>rt sending (selected part or whole of) file over
    2b. <leader>rd sending (selected part or whole of) delimited area
        over

A delimited area in option 2b looks for certain patterns and sends
everything up-to the next instance of that pattern.
Currently, the enabled patterns are `In[n]:` with n being a number,
emulating the way jupyter blocks are coded; and `^```` (three
back-ticks at the beginning of a line), to enable sending code fences
from (R)markdown files.

Since it uses the filetype to determine which repl/interpreter to send
code to, it is still a little unwieldy in markdown files (which in this
editor get handled as `pandoc` filetype.)

FIXME: There are two options going forward, either finding a way to
correctly identify the interpreter without filetype (should be done in
vim-terminator and seems inelegant) or correctly setting the filetype
for code fences in (R)Markdown *only* (seems more feasible and may
already be enabled in RMarkdown plugins for vim).

nvim: Fix simultaneous opening alacritty and nvim

When opening both (e.g. `alacritty -e nvim file`), neovim would open
with the wrong size (usually way smaller than the resulting terminal
size) and stay that way until you resized the terminal window.

This simply sends a 'resize' kill command to vim whenever the user
enters it to circumvent the bug until it's fixed.

nvim: Simplify lua plugin setup, Add indentLine

Added indent line plugin to show where and how indentations occur using
neovims virtual text. Can be toggled with `:IndentBlanklineToggle`.

Simplified lua setup a little by naming settings after intent instead of
per plugin -- everything lsp-y now resides in `lsp.lua`, everything
treesitter in `treesitter.lua`, everything indentation in its respective
file. Should, as long as plugins don't get too many, be perhaps a little
simpler to reason about.

nvim: Switch to packer as plugin manager

Switched to packer -- the plugins move to lua and so will I. Packer
seems basically like `vim-plug` in a dress (which is awesome, since
vim-plug is also awesome!) and it is extremely fast.
So, no real complaints but still a little switch to get that little bit
further away from vimscript.

nvim: Add telescope plugin and configuration

Added telescope as fzf replacement. Fzf served me well, but the
configuration is somewhat difficult (not least owing to the fact it's
written in vimscript), and telescope has a burgeoning ecosystem growing
around it.

I could basically drop-in replace all of my mappings and then some.
Refined some options and changed some defaults and I am fairly happy for
now.

nvim: Switch to zettelkasten plugin over wiki.vim
2021-05-24 18:01:54 +02:00

258 lines
8.7 KiB
VimL

" The general ideas behind these mappings:
"
" * Leader prefix is the generally preferred way to map new things, however
" only for those that affect all of vim
"
" * Localleader prefix is used for mappings which only affect single buffers,
" in other words mostly filetype specific mappings
"
" many of these mapping ideas come from Tom Ryder who has them nicely
" documented
" backspace to switch to alternate (last) buffer
" this may have to be adjusted / removed to let wiki.vim use BS for navigation
nnoremap <BS> <C-^>
" since u undoes, would it not make sense that U redoes?
nnoremap U <C-r>
" d-motion puts the last 'deleted' thing into the default register to paste;
" use D-motion to truly delete something into nothingness and keep whatever
" you want in your register, ready to paste
nnoremap D "_d
" I don't particularly need ex mode (at least, yet) but faster macro access
" is nice
nnoremap Q @
" stronger versions of left,right - move all the way to beginning/end of line
nnoremap H ^
nnoremap L $
" when in softwrapped files, allow moving through the visible lines with j/k
" but when prepending a number jump *exactly* as many lines, wrapped or not
" This makes relative linenumbers much more useful in prose docs since they
" are always exactly correct
nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
" move around between matching brackets with tab
nnoremap <tab> %
nnoremap <tab> %
" when in insertion mode, C-u uppercases the current word, C-l lowercases it,
inoremap <C-U> <esc>gUiw`]a
inoremap <C-u> <esc>guiw`]a
" let me save stuff as sudo when I forget to call vim with it
cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
" yank filename to f buffer
nnoremap yf :let @f = expand("%")<cr>
" repeat the last substitute command with all its flags preserved
noremap &
\ :&&<CR>
ounmap &
sunmap &
" bracket pairings to go to the next/previous of:
" (works with count prefixes)
"
" Argument list
nnoremap [a
\ :previous<CR>
nnoremap ]a
\ :next<CR>
" Buffers
nnoremap [b
\ :bprevious<CR>
nnoremap ]b
\ :bnext<CR>
" Quickfix list
nnoremap [c
\ :cprevious<CR>
nnoremap ]c
\ :cnext<CR>
" Location list
nnoremap [l
\ :lprevious<CR>
nnoremap ]l
\ :lnext<CR>
" set our leader key to space since with hjkl, space is largely useless
let mapleader = "\<Space>"
" maps the leader for buffer local mappings
" since we are (atm) using sneak to go fwd/bwd in fFtT searches, comma does
" not do too many useful things and can be taken up as localleader
let maplocalleader = ","
" If we mapped localleader to comma, we can still get to its original function
" by douple-tapping it.
if maplocalleader ==# ','
noremap ,, ,
sunmap ,,
endif
" remove search highlights by pressing space+/ - the key for searching the
" first place
nnoremap <leader>/ :noh<cr>
" split buffers vertically/horizontally with the leader \ or - (mirrors my
" tmux setup)
nnoremap <leader>- :sp<cr>
nnoremap <leader>\ :vsp<cr>
" 'open new buffer' with leader-t (opens new buffer containing current dir and switches to it)
nnoremap <leader>t :vsp .<cr>
" open actual new tab with leader-T
nnoremap <leader>T :tabedit .<cr>
" select the whole buffer with <leader>-a
nnoremap <leader>a ggVG
" CONFIG EDITING
" quickly edit vimrc with leader+V
nnoremap <leader>V :vsp $MYVIMRC<cr>
" automatically source the vimrc file whenever it is saved (causes slowdown
" when done in MANY successions)
" au BufWritePost init.vim so ~/.config/nvim/init.vim
" source vimrc with keystroke combination
nnoremap <leader>VV :source $MYVIMRC<cr>
" PLUGIN: vim-sneak
map f <Plug>Sneak_f
map F <Plug>Sneak_F
map t <Plug>Sneak_t
map T <Plug>Sneak_T
" PLUGIN: Vifm.vim
" open/close file tree with leader-e
nnoremap <leader>e :Vifm getcwd()<CR>
" open current file tree with current file directory
nnoremap <leader>E :Vifm<CR>
" PLUGIN: Telescope GLOBAL FUZZY FINDING
" buffers and files in current workdir
noremap <leader>s :lua require 'telescope.builtin'.buffers(require 'telescope.themes'.get_ivy())<cr>
" most recently used / MRU, bound to S since it is essentially a larger
" go-back intention than just buffers
noremap <leader>S :lua require 'telescope.builtin'.oldfiles(require 'telescope.themes'.get_ivy())<cr>
" fuzzy find files in cwd
noremap <leader>f :lua require 'telescope.builtin'.find_files({follow=true, hidden=true})<cr>
" general full-text search in cwd with rg
noremap <leader>F :lua require 'telescope.builtin'.live_grep()<cr>
" git status
noremap <leader>gs :lua require 'telescope.builtin'.git_status()<cr>
" git buffercommits
noremap <leader>gb :lua require 'telescope.builtin'.git_bcommits()<cr>
" git commitlog
noremap <leader>gl :lua require 'telescope.builtin'.git_commits()<cr>
" helptags
noremap <leader><F1> :lua require 'telescope.builtin'.help_tags()<cr>
" manpages
noremap <leader><F2> :lua require 'telescope.builtin'.man_pages()<cr>
" colorschemes
nnoremap <leader><F8> :lua require 'telescope.builtin'.colorscheme(require 'telescope.themes'.get_ivy())<cr>
" spell suggestions
nnoremap z= :lua require 'telescope.builtin'.spell_suggest(require 'telescope.themes'.get_ivy())<cr>
" Note Searching
" PLUGIN: Notational-FZF
" set notational-fzf-vim keys for the NV window itself
let g:nv_fzf_binds = [
\ 'alt-a:select-all',
\ 'alt-q:deselect-all',
\ 'alt-p:toggle-preview',
\ 'alt-u:page-up',
\ 'alt-d:page-down',
\ 'ctrl-w:backward-kill-word',
\ ]
" FZF note full-text search with notational-velocity like functions (in wiki
" directory)
noremap <leader>n :NV<cr>
noremap <leader>N :NV!<cr>
" PLUGIN: CtrlSF
" (non-fuzzy) search in wiki with ctrlsf, in fullscreen window
nnoremap <leader>wF :execute(":call SearchNotes()")<cr>
" PLUGIN: wiki.vim
" use wiki.vim to look through document outlines in fzf (only for note
" directory atm)
" leader is used when it is callable from anywhere
" localleader is used when it is specific to the local file
nnoremap <leader>wf :WikiFzfPages<cr>
nnoremap <leader>wt :WikiFzfTags<cr>
" use default TOC shortcut for viewing wikitoc if in correct filetype
augroup wikitoc
autocmd!
autocmd Filetype markdown,pandoc nnoremap <buffer> gO :WikiFzfToc<cr>
augroup END
" overwrites some default mappings I don't use, or that interfere with my own
" mappings TODO: currently this just assigns bogus shortcuts, since the plugin grumbles
" when setting to an empty string
let g:wiki_mappings_local = {
\ '<plug>(wiki-link-next)' : '<tab>',
\ '<plug>(wiki-link-prev)' : '<s-tab>',
\ '<plug>(wiki-link-return)' : '<bs>',
\ 'v_<plug>(wiki-link-toggle-visual)' : '<cr>',
\ '<plug>(wiki-graph-find-backlinks)' : '<leader>wb',
\ '<plug>(wiki-graph-in)' : '<leader>wg',
\ '<plug>(wiki-graph-out)' : '<leader>wG',
\}
" additional zettelkasten mapping
augroup zettelkasten
autocmd!
autocmd Filetype markdown,pandoc nnoremap <cr> :lua require 'zettelkasten'.open_or_make_link()<cr>
autocmd Filetype markdown,pandoc vnoremap <cr> :lua require 'zettelkasten'.open_or_make_link(true)<cr>
augroup END
" Mostly dealing with Prose writing from here on out
" Format current Paragraph (esp useful in prose writing)
nnoremap <silent> <localleader>q gqap
xnoremap <silent> <localleader>q gq
nnoremap <silent> <localleader>Q vapJgqap
" PLUGIN: GOYO
" Enter distraction free prose mode with F11
noremap <F11> :Goyo<CR>
" PLUGIN: fzf-bibtex
" map @@ to automatically insert citation reference at cursor
inoremap <silent> @@ <c-g>u<c-o>:CiteRef<CR>
" map <leader>cc to insert a complete citation at cursor
nnoremap <silent> <localleader>cc :CiteRef<cr>
" map <leader>cm to insert markdown prettified citation
nnoremap <silent> <localleader>cm :CiteMarkdown<cr>
" SPELL CHECKING
" Spell check set to <leader>O, 'o' for 'orthography':
" Move to the prev/next spelling error with [S ]S
" Move to the prev/next spelling error or suggestion with [s ]s
noremap <leader>Z :setlocal spell! spelllang=en_us<CR>
noremap <leader>ZE :setlocal spell! spelllang=en_us<CR>
noremap <leader>ZG :setlocal spell! spelllang=de_de<CR>
noremap <leader>zz 1z=
" PLUGIN: tq thesaurus_query.vim
nnoremap <leader>zt :ThesaurusQueryReplaceCurrentWord<cr>
vnoremap <leader>zt "ky:ThesaurusQueryReplace <cr>k<cr>
" pp to comPile a document (or file, works for some languages like go/python/c)
" o to open the resulting document (mostly for pdfs)
" po to comPile *and* open a doc
" and all the same in uppercase for verbose output
nnoremap <localleader>dp :DocCompile<cr>
nnoremap <localleader>dP :DocCompile!<cr>
nnoremap <localleader>do :DocOpen<cr>
nnoremap <localleader>dO :DocOpen!<cr>
" PLUGIN: easy-align
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)