Compare commits

..

2 Commits

Author SHA1 Message Date
Fabio Scotto di Santolo
f62a535335 Fix Vim FZF shortcuts 2026-07-22 20:35:23 +02:00
Fabio Scotto di Santolo
9ce213a620 Add fzf functions to Vim 2026-07-22 15:14:12 +02:00
7 changed files with 308 additions and 1 deletions

View File

@@ -33,6 +33,18 @@ common_packages:
- zip
- zoxide
vim_plugins_enabled: true
vim_plugin_distro_packages:
- fzf
- vim-fugitive
vim_plugin_source_plugins:
- name: fzf
repo: https://github.com/junegunn/fzf.git
version: v0.72.0
- name: fzf.vim
repo: https://github.com/junegunn/fzf.vim.git
version: 34a564c81f36047f50e593c1656f4580ff75ccca
common_dotfiles:
- name: .bashrc
src: .bashrc

View File

@@ -5,6 +5,19 @@ platform_package_manager: pkg
platform_service_manager: rc
ansible_python_interpreter: /usr/local/bin/python3
vim_plugin_distro_packages:
- fzf
vim_plugin_source_plugins:
- name: fzf
repo: https://github.com/junegunn/fzf.git
version: v0.72.0
- name: fzf.vim
repo: https://github.com/junegunn/fzf.vim.git
version: 34a564c81f36047f50e593c1656f4580ff75ccca
- name: vim-fugitive
repo: https://github.com/tpope/vim-fugitive.git
version: 3b753cf8c6a4dcde6edee8827d464ba9b8c4a6f0
effective_user_group: "{{ user_group }}"
effective_user_home: "/home/{{ effective_username }}"
user_home: "/home/{{ username }}"

View File

@@ -3,3 +3,16 @@ platform_profile: void
platform_family: void
platform_package_manager: xbps
platform_service_manager: runit
vim_plugin_distro_packages:
- fzf
vim_plugin_source_plugins:
- name: fzf
repo: https://github.com/junegunn/fzf.git
version: v0.72.0
- name: fzf.vim
repo: https://github.com/junegunn/fzf.vim.git
version: 34a564c81f36047f50e593c1656f4580ff75ccca
- name: vim-fugitive
repo: https://github.com/tpope/vim-fugitive.git
version: 3b753cf8c6a4dcde6edee8827d464ba9b8c4a6f0

View File

@@ -7,6 +7,7 @@ effective_user_group: "{{ server_user_group }}"
effective_user_home: "{{ server_user_home }}"
server_container_stack_dir: /opt/docker/server
ai_agents_enabled: false
vim_plugins_enabled: false
profile_packages:
- avahi-daemon

View File

@@ -50,6 +50,53 @@
loop_control:
label: "{{ item.dest }}"
- name: Install distro packages for Vim plugins
tags: [packages, vim, fzf]
ansible.builtin.package:
name: "{{ vim_plugin_distro_packages | default([]) }}"
state: present
when:
- vim_plugins_enabled | default(false)
- (vim_plugin_distro_packages | default([])) | length > 0
- name: Ensure git package is installed for source Vim plugins
tags: [packages, vim, fzf]
ansible.builtin.package:
name: git
state: present
when:
- vim_plugins_enabled | default(false)
- (vim_plugin_source_plugins | default([])) | length > 0
- name: Ensure Vim plugin pack directory exists
tags: [dotfiles, dotfiles:common, vim, fzf]
ansible.builtin.file:
path: "{{ effective_user_home }}/.vim/pack/plugins/opt"
state: directory
owner: "{{ effective_username }}"
group: "{{ effective_user_group }}"
mode: "0755"
when:
- vim_plugins_enabled | default(false)
- (vim_plugin_source_plugins | default([])) | length > 0
- name: Install source Vim plugins
tags: [dotfiles, dotfiles:common, vim, fzf]
ansible.builtin.git:
repo: "{{ item.repo }}"
dest: "{{ effective_user_home }}/.vim/pack/plugins/opt/{{ item.name }}"
version: "{{ item.version }}"
update: false
become_user: "{{ effective_username }}"
environment:
HOME: "{{ effective_user_home }}"
loop: "{{ vim_plugin_source_plugins | default([]) }}"
loop_control:
label: "{{ item.name }}"
when:
- vim_plugins_enabled | default(false)
- (vim_plugin_source_plugins | default([])) | length > 0
- name: Ensure AI config directories exist
tags: [dotfiles, dotfiles:common]
ansible.builtin.file:

View File

@@ -89,7 +89,7 @@ nnoremap <silent> <leader>h :set hlsearch!<CR>
" ----------------------------------------------------------
set updatetime=250
set timeoutlen=400
set timeoutlen=800
set ttimeoutlen=10
set shortmess+=c
@@ -149,6 +149,125 @@ endif
nnoremap <silent> <leader>g :silent grep! <C-R><C-W> .<CR>:copen<CR>
nnoremap <leader>/ :silent grep!<Space>
" ----------------------------------------------------------
" Optional plugins
" ----------------------------------------------------------
" Plugins are installed out-of-band by Ansible when available. Keep this
" vimrc usable as a standalone onefile: load optional packages only when they
" exist and keep builtin fallbacks for the mappings below.
let s:fzf_min_version = [0, 54, 0]
function! s:PackAdd(package) abort
silent! execute "packadd " . a:package
endfunction
function! s:PackAddForCommand(package, command) abort
if exists(":" . a:command) == 2
return 1
endif
call s:PackAdd(a:package)
return exists(":" . a:command) == 2
endfunction
function! s:PackAddByRuntimeFile(runtime_file, command) abort
if exists(":" . a:command) == 2
return 1
endif
" Distro packages and source installs do not always use the same Vim package
" directory name. Look for a package containing the expected runtime file and
" load it by its actual directory name.
for l:packpath in split(&packpath, ",")
let l:packages = glob(l:packpath . "/pack/*/opt/*", 0, 1)
\ + glob(l:packpath . "/pack/*/start/*", 0, 1)
for l:package_dir in l:packages
if filereadable(l:package_dir . "/" . a:runtime_file)
call s:PackAdd(fnamemodify(l:package_dir, ":t"))
if exists(":" . a:command) == 2
return 1
endif
endif
endfor
endfor
return 0
endfunction
let s:has_fzf = s:PackAddForCommand("fzf", "FZF")
\ || s:PackAddByRuntimeFile("plugin/fzf.vim", "FZF")
let s:has_fzf_vim = s:has_fzf
\ && (s:PackAddForCommand("fzf.vim", "Files")
\ || s:PackAddByRuntimeFile("autoload/fzf/vim.vim", "Files"))
let s:has_vim_fugitive = s:PackAddForCommand("vim-fugitive", "Git")
\ || s:PackAddByRuntimeFile("autoload/fugitive.vim", "Git")
function! s:FzfExecutable() abort
if executable("fzf")
return "fzf"
endif
return ""
endfunction
function! s:FzfVersionOk() abort
let l:fzf = s:FzfExecutable()
if empty(l:fzf)
return 0
endif
let l:version = matchstr(get(systemlist(l:fzf . " --version"), 0, ""), '^\d\+\.\d\+\.\d\+')
if empty(l:version)
return 0
endif
let l:parts = map(split(l:version, '\.'), 'str2nr(v:val)')
return l:parts[0] > s:fzf_min_version[0]
\ || (l:parts[0] == s:fzf_min_version[0] && l:parts[1] > s:fzf_min_version[1])
\ || (l:parts[0] == s:fzf_min_version[0] && l:parts[1] == s:fzf_min_version[1]
\ && l:parts[2] >= s:fzf_min_version[2])
endfunction
if s:has_fzf_vim && s:FzfVersionOk()
let g:fzf_layout = {"down": "40%"}
let g:fzf_vim = get(g:, "fzf_vim", {})
let g:fzf_vim.preview_window = ["right,50%", "ctrl-/"]
endif
function! s:FzfCommand(command) abort
if s:has_fzf_vim && s:FzfVersionOk() && exists(":" . a:command) == 2
execute a:command
elseif a:command ==# "Files" || a:command ==# "GFiles" || a:command ==# "GitFiles"
edit .
elseif a:command ==# "Buffers"
ls
elseif a:command ==# "Rg"
silent grep! <cword> .
copen
endif
endfunction
function! s:GitStatus() abort
if s:has_vim_fugitive && exists(":Git") == 2
Git
elseif executable("git")
botright new
setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted
silent read !git status --short --branch
1delete _
file git-status
else
echohl WarningMsg | echom "git executable not found" | echohl None
endif
endfunction
nnoremap <silent> <leader>ff :call <SID>FzfCommand("Files")<CR>
nnoremap <silent> <leader>fg :call <SID>FzfCommand("GFiles")<CR>
nnoremap <silent> <leader>fb :call <SID>FzfCommand("Buffers")<CR>
nnoremap <silent> <leader>fr :call <SID>FzfCommand("Rg")<CR>
nnoremap <silent> <leader>gs :call <SID>GitStatus()<CR>
" ----------------------------------------------------------
" Quickfix / location list
" ----------------------------------------------------------

View File

@@ -0,0 +1,102 @@
# Vim shortcuts
Configurazione sorgente: `.vimrc`.
- Leader: `Space`
- Local leader: `\\`
- Le shortcut sotto sono pensate per normal mode, salvo dove indicato.
- `timeoutlen` è impostato a `800 ms`: premi le sequenze con leader senza aspettare troppo.
## Base
| Shortcut | Azione |
|---|---|
| `Space l` | Toggle caratteri invisibili / whitespace |
| `Space h` | Toggle evidenziazione ricerca |
| `Space w` | Salva file corrente |
| `Space q` | Chiudi finestra corrente |
| `Space x` | Salva e chiudi |
| `Space z` | Toggle fold sotto il cursore |
## Ricerca
| Shortcut | Azione |
|---|---|
| `Space g` | Cerca la parola sotto il cursore nel progetto e apre quickfix |
| `Space /` | Avvia `:grep!` manuale |
## FZF / file / Git
Queste shortcut usano `fzf.vim` quando disponibile; altrimenti cadono su fallback portabili.
| Shortcut | Azione |
|---|---|
| `Space ff` | `:Files`, fallback `:edit .` |
| `Space fg` | `:GFiles`, fallback `:edit .` |
| `Space fb` | `:Buffers`, fallback `:ls` |
| `Space fr` | `:Rg`, fallback `:grep! <cword> .` + quickfix |
| `Space gs` | `:Git` con vim-fugitive, fallback buffer con `git status` |
## Quickfix e location list
| Shortcut | Azione |
|---|---|
| `]q` | Prossimo elemento quickfix |
| `[q` | Precedente elemento quickfix |
| `Space qo` | Apri quickfix |
| `Space qc` | Chiudi quickfix |
| `]l` | Prossimo elemento location list |
| `[l` | Precedente elemento location list |
| `Space lo` | Apri location list |
| `Space lc` | Chiudi location list |
## Finestre
| Shortcut | Azione |
|---|---|
| `Ctrl h` | Vai alla finestra a sinistra |
| `Ctrl j` | Vai alla finestra sotto |
| `Ctrl k` | Vai alla finestra sopra |
| `Ctrl l` | Vai alla finestra a destra |
## Diff
| Shortcut | Azione |
|---|---|
| `Space df` | Attiva diff su tutte le finestre |
| `Space do` | Disattiva diff su tutte le finestre |
## Tags e preview
| Shortcut | Azione |
|---|---|
| `Space t` | Vai al tag della parola sotto il cursore |
| `Space pt` | Apri il tag in preview window |
| `Space po` | Apri preview window |
| `Space pc` | Chiudi preview window |
| `K` | Apri la man page della parola sotto il cursore |
## Cscope
Disponibili solo se Vim ha supporto `cscope`.
| Shortcut | Azione |
|---|---|
| `Space cs` | Cerca simbolo |
| `Space cg` | Cerca definizione |
| `Space cd` | Cerca funzioni chiamate dal simbolo |
| `Space cc` | Cerca chiamanti |
| `Space ct` | Cerca testo |
| `Space ce` | Cerca egrep |
| `Space ci` | Cerca include |
Nota: `Space cf` è riservato a ClangFormat, quindi non usarlo per cscope file search.
## Format, build e run
| Shortcut | Modo | Azione |
|---|---|---|
| `Space cf` | normal | Esegue `clang-format` sul file |
| `Space cf` | visual | Esegue `clang-format` sulla selezione |
| `Space m` | normal | Build smart: `ninja`, `cmake --build build`, `make -C <root>` o `make` |
| `Space r` | normal | Salva ed esegue il file corrente; supporta C, Python e shell |