2023-02-26 17:36:34 +00:00
# My personal **neovim as container** configuration
2022-10-05 19:22:26 +00:00
I made this public so I can easily clone without authentication,
but since I treat this as a personal use only stuff,
there can be some(read "a lot of") messy stuff.
2022-10-19 13:11:04 +00:00
2022-10-05 19:22:26 +00:00
Much of this might have been selectively copy pasted from plugin repos.
Those repos are obviously listed in plugin setup part.
2023-03-06 18:59:59 +00:00
**Tested only with rootless podman, docker might require additional setup,
or proper in-container user setup**
2022-10-14 07:08:35 +00:00
2023-03-06 18:59:59 +00:00
## Basic usage of this config
2022-10-14 07:08:35 +00:00
2023-02-26 17:14:08 +00:00
### Host system Setup
Installing host system stuff, currently just fonts (Fedora example):
2022-10-14 07:08:35 +00:00
```bash
2023-02-26 17:14:08 +00:00
sudo dnf install -y \
2022-11-12 11:54:14 +00:00
dejavu-fonts-all \
2023-02-26 17:14:08 +00:00
gnu-free-mono-fonts
```
2023-03-06 18:59:59 +00:00
### Image management
2023-03-11 12:30:39 +00:00
#### get latest version from ghcr
2023-03-06 18:59:59 +00:00
```bash
podman pull ghcr.io/szwendacz99/neovim:latest
```
2023-03-11 12:30:39 +00:00
#### or build
2023-02-26 17:14:08 +00:00
```bash
git clone https://github.com/Szwendacz99/nvim & & \
2023-03-11 12:30:39 +00:00
podman build -t neovim ./nvim & & \
podman tag localhost/neovim:latest localhost/neovim:$(date +"%Y-%m-%dT%H-%M")
2023-02-26 17:14:08 +00:00
```
pack to file with high compression:
```bash
2023-03-06 18:59:59 +00:00
podman save localhost/neovim:latest -o /dev/stdout | \
xz -z -T 8 -c > neovim$(date +"%Y-%m-%dT%H-%M").tar.xz
2023-02-26 17:14:08 +00:00
```
2022-10-14 07:08:35 +00:00
2023-02-26 17:14:08 +00:00
import file back to local registry:
2022-10-19 13:11:04 +00:00
2023-02-26 17:14:08 +00:00
```bash
podman load -i ./neovim.tar.xz
2022-10-14 07:08:35 +00:00
```
2023-03-06 18:59:59 +00:00
### Image usage examples
2023-02-26 17:14:08 +00:00
basic startup for editing current folder:
```bash
podman run --privileged -it --rm \
-e XDG_RUNTIME_DIR=/runtime_dir \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY \
2023-03-12 12:19:38 +00:00
-v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions \
2023-02-26 17:14:08 +00:00
--workdir /data \
2023-03-12 12:19:38 +00:00
-v "$(pwd):/data:rw" \
neovim:latest
2023-02-26 17:14:08 +00:00
```
2022-11-12 11:54:14 +00:00
2023-02-27 19:57:20 +00:00
function for opening current dir or some files/folders in temporary container:
2023-02-26 17:14:08 +00:00
```bash
function nvim() {
2023-03-12 12:19:38 +00:00
# Mount current folder OR folders/files given as parameters, then
# open neovim. Container will be removed on neovim exit.
# Mount wayland for clipboard sync.
# Also pass all parameters to neovim as its arguments.
2023-02-27 19:57:20 +00:00
for arg in "$@"; do
2023-03-12 12:19:38 +00:00
if [ -f "$arg" ] || [ -d "$arg" ] ; then
2023-07-16 12:23:44 +00:00
local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$arg:$arg:rw")
echo "Mounting $arg"
2023-02-27 19:57:20 +00:00
fi
done
if [ -z "$MOUNT_FILE" ]; then
# mount current workdir if no arguments with path
2023-02-28 20:49:14 +00:00
# mount on base_path to make sessions saving work
2023-07-16 12:23:44 +00:00
local base_path="$(pwd)"
# use list as a trick to allow paths with spaces
local MOUNT_FOLDER=(--workdir "/data$base_path" -v "$base_path:/data$base_path:rw")
2023-02-26 17:14:08 +00:00
fi
2023-03-12 12:19:38 +00:00
# make sure there is a folder for sessions on default path
2023-10-08 09:16:50 +00:00
mkdir -p ~/.local/share/nvim/sessions ~/.local/state/nvim/shada/
touch ~/.local/state/nvim/shada/main.shada
2023-02-27 19:57:20 +00:00
2023-07-16 12:23:44 +00:00
echo "Files mount options: ${MOUNT_FILE[*]}"
echo "Folder mount options: ${MOUNT_FOLDER[*]}"
2023-02-26 17:14:08 +00:00
podman run --privileged -it --rm \
-e XDG_RUNTIME_DIR=/runtime_dir \
2023-02-27 19:57:20 +00:00
-e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \
-v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \
-v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \
2023-10-08 09:16:50 +00:00
-v ~/.local/state/nvim/shada/main.shada:/root/.local/state/nvim/shada/main.shada:rw \
2023-07-16 12:23:44 +00:00
"${MOUNT_FILE[@]}" \
"${MOUNT_FOLDER[@]}" \
2023-02-26 17:14:08 +00:00
neovim:latest "$@"
}
```
2022-10-14 07:08:35 +00:00
2023-03-06 18:59:59 +00:00
If there is need to make more persistent container that will also start with
bash so you can install project dependencies and stuff,
then use function below.
2023-02-27 19:57:20 +00:00
```bash
function nvim_project() {
2023-03-12 12:19:38 +00:00
# Mount current folder to a container that will not be removed on exit.
# Requires first argument to be a name for the container so it can be
# easily reentered later.
# If you specify some paths as latter parameters, then these paths will
# be mounted instead of current folder.
# Also mounts wayland for clipboard sync.
2023-02-27 19:57:20 +00:00
if [ -z "$1" ]; then
2023-03-12 12:19:38 +00:00
echo "give project/container name as first parameter"
return 1
2023-02-27 19:57:20 +00:00
fi
2023-07-16 12:23:44 +00:00
local container_name="$1"
2023-03-12 12:19:38 +00:00
shift # skip first parameter as it can be name of a folder/file in
# current dir so it could try mounting it later
2023-02-27 19:57:20 +00:00
for arg in "$@"; do
2023-03-12 12:19:38 +00:00
if [ -f "$arg" ] || [ -d "$arg" ] ; then
2023-07-16 12:23:44 +00:00
local MOUNT_FILE=("${MOUNT_FILE[@]}" -v "$arg:$arg:rw")
echo "Mounting $arg"
2023-02-27 19:57:20 +00:00
fi
done
if [ -z "$MOUNT_FILE" ]; then
# mount current workdir if no arguments with path
2023-02-28 20:49:14 +00:00
# mount on base_path to make sessions saving work
2023-03-12 12:19:38 +00:00
local base_path
base_path="$(pwd)"
2023-07-16 12:23:44 +00:00
local MOUNT_FOLDER=(--workdir "/data$base_path" -v "$base_path:/data$base_path:rw")
2023-02-27 19:57:20 +00:00
fi
2023-03-12 12:19:38 +00:00
# make sure there is a folder for sessions on default path
2023-10-08 09:16:50 +00:00
mkdir -p ~/.local/share/nvim/sessions ~/.local/state/nvim/shada/
touch ~/.local/state/nvim/shada/main.shada
2023-02-27 19:57:20 +00:00
2023-07-16 12:23:44 +00:00
echo "Files mount options: ${MOUNT_FILE[*]}"
echo "Folder mount options: ${MOUNT_FOLDER[*]}"
2023-02-27 19:57:20 +00:00
podman run --privileged -it \
-e XDG_RUNTIME_DIR=/runtime_dir \
-e WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \
-v "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/runtime_dir/$WAYLAND_DISPLAY:rw" \
-v ~/.local/share/nvim/sessions:/root/.local/share/nvim/sessions:rw \
2023-10-08 09:16:50 +00:00
-v ~/.local/state/nvim/shada/main.shada:/root/.local/state/nvim/shada/main.shada:rw \
2023-07-16 12:23:44 +00:00
"${MOUNT_FILE[@]}" \
"${MOUNT_FOLDER[@]}" \
2023-02-27 19:57:20 +00:00
--entrypoint bash \
2023-03-12 12:19:38 +00:00
--name $container_name \
2023-02-27 19:57:20 +00:00
neovim:latest
}
```
2023-03-06 18:59:59 +00:00
This container will not be removed on exit, you can reenter later with:
2023-02-27 19:57:20 +00:00
```bash
podman start -ai {project/container name}
```
2023-08-03 14:19:54 +00:00
## Additional packages to install as needed
### Perl lang
For Perl language support run this command to install required packages for
lsp server:
```bash
dnf install -y perl-App-cpanminus;
cpanm PLS;
```
And then in neovim:
```bash
:MasonInstall perlnavigator
```
2023-12-28 18:17:49 +00:00
### Ruby
```bash
dnf install -y ruby-devel rubygems
```
```bash
:MasonInstall standardrb ruby-lsp solargraph
```
2023-03-06 18:59:59 +00:00
## Inside vim
2022-10-14 07:08:35 +00:00
2023-03-06 18:59:59 +00:00
```vim
2023-02-07 18:49:35 +00:00
# manage plugins:
:Lazy
2022-10-14 07:08:35 +00:00
```
2023-03-06 18:59:59 +00:00
There is need to make sure your system can display (almost) any unicode
character. Hacked fonts may be needed for filetype icons but there is also
need for a dedicated package with unicode fonts (like unifont-fonts.noarch)
that will have every character missing from default font used in Neovim editor.
Link to hacked fonts:
2022-10-14 07:08:35 +00:00
[https://www.nerdfonts.com/font-downloads ](https://www.nerdfonts.com/font-downloads )
2023-03-06 18:59:59 +00:00
### General info
2022-11-12 11:54:14 +00:00
2023-03-06 18:59:59 +00:00
#### Mason
2022-11-12 11:54:14 +00:00
2023-03-06 18:59:59 +00:00
Mason installs stuff in `.local/share/nvim/mason/packages` so they are
independent from system stuff, like pip installed python packages.
All that is saved in image, so that is why image is so heavy.
2022-11-12 11:54:14 +00:00
2023-03-06 18:59:59 +00:00
### Commands and keys
2022-10-14 07:08:35 +00:00
2023-03-06 18:59:59 +00:00
#### General
|keys|action|
|----|----|
|\<leader\>l|disable (search) highlighting|
#### Opened files navigation
|keys|action|
|----|----|
|\<leader\> m m| open minimap|
|\<leader\> m c | close minimap|
|\<leader\> m f | focus minimap|
|Ctrl w w| Move to next splitted frame|
|Ctrl w \<arrow\> | moving throught splitted frame|
|Ctrl w c | close split|
|Ctrl w v | split vertically|
|Ctrl w s| split horizontally|
|Ctrl w x| swap places of two splits|
|gt |next tab|
|gT| previous tab|
|:tabnew |Create new tab|
|Ctrl+g Ctrl+t |(when in file tree) open selected file in new tab|
|:bd | close buffer|
|:bnext | next buffer|
|:b3 |switch to buffer 3|
|:buffers | list buffers and their numbers |
#### File explorer
|keys|action|
|----|----|
|Ctrl+t | Toggle file explorer when not focused on it|
|f | Toggle filtering when focused on explorer|
|\<leader\> n | Move focus to explorer|
|d |Delete selected file|
|rn |Rename file|
|c |add file to clipboard|
|p | paste (file) from clipboard |
#### File searching / Telescope
|keys|action|
|----|----|
|\<leader\>ff |Find files|
|\<leader\>fg| Live grep|
|\<leader\>fb| Buffers|
|\<leader\>fh |Help tags|
2023-10-08 09:16:50 +00:00
|Ctrl+/|Show mappings for picker actions (insert mode)|
2023-03-06 18:59:59 +00:00
|Ctrl+q| Open search result list as a dedicated split (quickfix list) (will overwrite previous one created this way in current tab)|
|Ctrl+u | Scroll preview up|
|Ctrl+d | Scroll preview down|
2023-10-08 09:16:50 +00:00
|Ctrl+f|Scroll left in preview window|
|Ctrl+k|Scroll right in preview window|
2023-03-06 18:59:59 +00:00
|Ctrl+x |Open selection as a split|
|Ctrl+v | Open selection as a vsplit|
|Ctrl+t | Open selection in new tab |
2023-08-03 14:19:54 +00:00
#### Markdown Preview
Mardkown Preview plugin commands:
```bash
:MarkdownPreview*
```
2023-03-06 18:59:59 +00:00
#### Git stuff
|keys|action|
|----|----|
Ctrl+g show current code chunk changes
|\<leader\>hb | show full git blame of current line (double use to enter displayed diff)|
|\<leader\>hD |show splitted blame diff (double use to enter displayed diff)|
|\<leader\>hd| show splitted diff|
|\<leader\>hr| reset hunk|
|\<leader\>hR| reset whole buffer|
|\<leader\>td| toggle deleted |
2022-10-14 07:08:35 +00:00
2023-10-08 09:16:50 +00:00
##### Telescope git stuff
Commands: `:Telescope git_*`
Bindings:
|keys|action|
|----|----|
|< leader > gs|git_status|
|< leader > gc|git_commits|
|< leader > gb|git_branches|
2022-10-14 07:08:35 +00:00
Genreal git commands:
```bash
:Git < command >
2022-10-19 13:11:04 +00:00
#Commands with dedicated display
:Git # show nice interactive summary of whole git project state
:Git mergetool, :Git difftool # load their changesets into the quickfix list
2022-10-14 07:08:35 +00:00
:Git blame # this will nicely show \
# for every line in separate split
2022-10-19 13:11:04 +00:00
# Useful shortcuts for blame mode:
# o - jump to patch or blob in horizontal split
# A, C, D - different display (lenght) modes
# g? - other keybindings
#other examples:
2022-10-14 07:08:35 +00:00
:Git add .
2022-10-19 13:11:04 +00:00
:Git commit
2022-10-14 07:08:35 +00:00
```
Nice single file diff viewer:
```
:Gdiffsplit
```
2022-11-12 11:54:14 +00:00
GitSings provides some commands for displaying git stuff:
2022-10-14 07:08:35 +00:00
```bash
2022-11-12 11:54:14 +00:00
:Gitsigns *
2022-10-14 07:08:35 +00:00
#examples:
2022-11-12 11:54:14 +00:00
:Gitsigns toggle_word_diff
:Gitsigns toggle_linehl
:Gitsigns toggle_numhl
:Gitsigns toggle_signs
2022-10-14 07:08:35 +00:00
```
2023-03-06 18:59:59 +00:00
#### Code editing stuff
|||
|----|----|
|w|jump forward by one word|
|b|jump backward by one word|
|:%s/^original.\\\*/replacement/gc|regex replacing (c is for choice prompt, its optional)|
|Ctrl+q|Visual block select mode|
#### LSP usage
|||
|----|----|
|\<space\>q | open list with diagnostics postions|
|\<space\>e |open diagnostics floating window|
|\[d | next diagnostic|
|\] | previous diagnostic|
|\<leader\>k| open hoover box and enter it|
|\<leader\>rn |rename element (function name, etc)|
|\<leader\>f| format file|
|gd |go to definition|
|gD| go to declaration|
|\<space\>D| go to type definition|
|gi| go to implementation|
|gr| go to references|
|Ctrl+f |scroll down popup with docstring|
|Ctrl+b |scroll up popup with docstring|
|\<leader\>wa |add workspace folder|
|\<leader\>wr |remove workspace folder|
|\<leader\>wl | list workspace folders |
2023-07-18 19:41:09 +00:00
#### Lspsaga plugin
Display element (function or whatever?) hierarchy
```bash
:Lspsaga incoming_calls and :Lspsaga outgoing_calls
```
Show avaliable code actions for current line
```bash
:Lspsaga code_action
```
Element definition
```text
Invoke by running :Lspsaga peek_definition and :Lspsaga peek_type_definition. Layout is drawer and is currently the only one available. If you want to go to the definition, use :Lspsaga goto_definition and :Lspsaga goto_type_definition
```
Finder - find current element over all files
```bash
:Lspsaga finder
```
Floating terminal
```bash
:Lspsaga term_toggle
```
Show hover doc (Use `:Lspsaga hover_doc ++keep` if you want to keep the hover window.)
```bash
:Lspsaga hover_doc
```
Outline
```bash
:Lspsaga outline
```
Rename
```bash
:Lspsaga rename
```
2023-05-14 10:39:06 +00:00
#### LSP diagnostics (custom and trouble.nvim)
2023-03-06 18:59:59 +00:00
|||
|----|----|
2023-05-14 10:39:06 +00:00
|\<leader\>vt| switch display of virtual text|
2023-03-06 18:59:59 +00:00
|\<leader\>xx| Open diagnostics window|
|\<leader\>xw |workspace diagnostics|
|\<leader\>xd |document diagnostics|
|\<leader\>xl| loclist|
|\<leader\>xq |quickfix|
|gR | lsp references |
#### Sessions
To save new session on specific path, just use :SaveSession, then when opening nvim there, without arguments, the session will be restored.
#### Notifications
|||
|----|----|
|:Notifications |show recent notifications|
|:Telescope notify | show recent notifications in telescope gui|