linux editor

Vim

Install neovim

#this to be run at each release
snap install neovim
sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim 1
sudo update-alternatives --config

Add those into .bashrc:

export EDITOR=/usr/bin/vim
export VISUAL=/usr/bin/vim

Install plugins

curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
cat ~/.config/nvim/init.vim
set encoding=utf-8
colo murphy
set hlsearch
set nonu

call plug#begin()
Plug 'https://github.com/ryvnf/readline.vim.git'
Plug 'https://github.com/tpope/vim-surround.git'
call plug#end()

" in order to keep terminal cursor after vim quit
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
\,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
\,sm:block-blinkwait175-blinkoff150-blinkon175

Plugin install/update:

:PlugInstall
:UpdateRemotePlugins

Regexp

Gready / non Gready

In vim, .\{-} is equivalent to .*? for non gready operators:

:%s/jim.\{-}//g

Delete blank lines

:g/^$/d

No format on paste

:set paste
#Note: it breaks vim-readline

No numbering

:set nonu

Vim Surround

Add surround:

  1. Visual a word, part of text
  2. S" -> "surround"
  3. S( -> (surround)

Replace surround:

  1. On a "word" press cs"' to change to 'word'
  2. On a "word" press cs") to change to (word)

Delete surround:

  1. On a "word" press ds" to change to word

Open multiple files in tabs

vim file1.md file2.md
#then in vim this will turn buffers into tabs
:tab all
:qa # quit all

Re-use sessions

#8will save the session in a Session.vim (overrite with !)
:mksession!
#or
:mks!
#later on this will back to the state save
vim -S

Spelling

Plugins

image

lazy vim

install nerd fonts

#!/bin/bash

declare -a fonts=(
    JetBrainsMono
)

version='3.2.1'
fonts_dir="${HOME}/.fonts"

if [[ ! -d "$fonts_dir" ]]; then
    mkdir -p "$fonts_dir"
fi

for font in "${fonts[@]}"; do
    zip_file="${font}.zip"
    download_url="https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/${zip_file}"
    echo "Downloading $download_url"
    wget "$download_url"
    unzip "$zip_file" -d "$fonts_dir"
    rm "$zip_file"
done

find "$fonts_dir" -name '*Windows Compatible*' -delete

fc-cache -fv

git

In DiffView:

dp ; stage the hunk - aka do push
do ; discard the hunk - aka do optain
]c/[c ; next/previous hunk
; to save a given merged file, save the diff buffer (in the bottom)

gh code review

<space> gp ; list pull requests
:Octo review
[q ]q ; change file
<space> ca ; add comment
<space> sa ; add suggestion
:Octo review submit ; to submit the pr

terminal

<C-/> ; show/hide a terminal
<C-\><C-n> ; quit terminal mode (allow to scroll, copy/paste...)

keybindings

You can:

- get a list of all active mappings with :help maplist(),
- get details about a specific mapping with :help maparg(),
- check if a mapping exists with :help mapcheck(),
- check if a mapping to a specific command exists with :help has_mapto().

If you want a list of all normal mode commands, see :help normal-index.

"+y ; copy to os clipboard
:LspRestart ; restart code server
:map ; show all key bindings and source
<c-h> ; will show the current file in the tree
<ctrl> i ; next cursor place
<ctrl> o ; previous cursor place
<shift> h ; previous buffer
<shift> l ; next buffer
<space> / ; search within files
<space> bd ; close current buffer
<space> ca ; code actions
<space> e : show/hide left panel
<space> ff ; search files names
<space> ft ; open terminal
<space> ul ; hide numbering
<space> w (hjkl) ; navigate on panels, with multidirectional keys
<space> / ;in neotree, type  to live grep+args in current node
<space>cs ; show outlines or code functions / methods
<space>gb ; will show git blame popup
<space>qq ; quit and save session
<space>sW ; grep search current selected word
[d, [w, [e, ]d, ]w, and ]e ; go to next error/warn/diagnose
[h and ]h ;next git hunk
[t and ]t ; next todo
s ; ar startup restore session
<Space>w< ; resize
<Space>wm ; maximize
<c-t> ; trouble view
<c-q> ; revert trouble
<Space>cs ; show outlines

Tricks

Cancel search

vim.keymap.set('n', '<Esc>', function()
    vim.cmd.nohlsearch()
    vim.cmd.diffupdate()
    vim.cmd.mode()
end, { desc = 'Clear search' })

Java

:JdtWipeDataAndRestart : allows to restart the lsp; apparently needed when adding depts into gradle (not maven)

logs message

:mess
:lua Snacks.notifier.show_history()
:noice

markdown

Marks

React ?

This page was last modified: