mywiki/vim.md

9.4 KiB

Vim

Vim è un editor di testo molto potente, che può essere ampliato ulteriormente tramite plugin vari.

Prima, però, ecco una configurazione base che aggiunge varie funzionalità:

" IMPOSTAZIONI ----------------------------------------------------------- {{{

colorscheme catppuccin_mocha
set spell spelllang=it,en
syntax on 			  			      " Enable type file detection. Vim will be able to try to detect the type of file in use.
filetype off 						  " Enable plugins and load plugin for the detected file type.
set nocompatible              		  " be iMproved, required
filetype plugin indent on   		  " required
set omnifunc=syntaxcomplete           " Enable Omnicomplete features
filetype plugin on 				      " Load an indent file for the detected file type.
filetype indent on
set foldenable
set autoindent                        " Automatically guesses the indentation given the previous one
set hlsearch                          " Automatically highlights search results, to hide them run :noh
set incsearch                         " Searches incrementally as you type.
set ruler                             " Shows the rulers
set showcmd                           " Shows current cursor info
set ignorecase                        " Ignores cases when searching
set noswapfile                        " Disables swap files
set undofile                          " Enable keeping history across sessions, don't forget to mkdir
set undodir=~/.vim/undo/
set nofixeol                          " Do not insert a new line at the end of the file automatically
set backspace=indent,eol,start        " Enable backspace key to delete stuffs properly
set termguicolors
set number						      " Add numbers to each line on the left-hand side.
set relativenumber
set clipboard=unnamedplus
set cursorline						  " Highlight cursor line underneath the cursor horizontally.
set nobackup    					  " Do not save backup files.
set nowrap						      " Do not wrap lines. Allow long lines to extend as far as the line goes.
set incsearch					      " While searching though a file incrementally highlight matching characters as you type.
set ignorecase						  " Ignore capital letters during search.
set smartcase						  " This will allow you to search specifically for capital letters.
set showmode						  " Show the mode you are on the last line.
set showmatch						  " Show matching words during a search.
set hlsearch						  " Use highlighting when doing a search.
set wildmenu						  " Enable auto completion menu after pressing TAB.
set wildmode=list:longest			  " Make wildmenu behave like similar to Bash completion.
set foldenable
set foldmethod=indent
set ttyfast						      " Speed up scrolling in Vim
set encoding=UTF-8
set nobackup                          " Neoclide
set nowritebackup
set updatetime=300
set signcolumn=yes
" }}}

Plugin Manager

Per poter installare dei plugin è necessario installare prima un plugin-manager.

Vundle

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Dopo aver clonato Vundle sulla propria macchina, inserire le seguenti righe di testo nel file .vimrc

" PLUGINS ---------------------------------------------------------------- {{{

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
"
" All of your Plugins must be added before the following line
" 

call vundle#end()            " required

" }}}

Installazione plugin

Installare un plugin è molto semplice, basta aggiungerlo nel file .vimrc, come da codice sottostante:

" PLUGINS ---------------------------------------------------------------- {{{

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
"
" All of your Plugins must be added before the following line
" 
Plugin 'neoclide/coc.nvim', {'branch': 'release'}
Plugin 'itchyny/vim-cursorword'
Plugin 'preservim/nerdtree'
Plugin 'iamcco/markdown-preview.nvim'
Plugin 'alvan/vim-closetag'
Plugin 'mattn/emmet-vim'
Plugin 'jiangmiao/auto-pairs'
Plugin 'ryanoasis/vim-devicons'
Plugin 'frazrepo/vim-rainbow'
Plugin 'mg979/vim-visual-multi', {'branch': 'master'}
Plugin 'itchyny/lightline.vim'
Plugin 'voldikss/vim-floaterm'
Bundle 'https://github.com/prashanthellina/follow-markdown-links'
Plugin 'mracos/mermaid.vim'
Plugin 'mzlogin/vim-markdown-toc'
Plugin 'bbrtj/vim-vorg-md'
Plugin 'sheerun/vim-polyglot'

call vundle#end()            " required

Una volta salvato il file, digitare :PluginInstall.

Quando l'installazione è completata, è buona norma cancellare la cache del buffer digitando il comando :bdelete.

È possibile ricercare plugin nel Web oppure tramite il comando :PluginSearch. Per aggiornare l'elenco locale dei plugin dal sito vimscripts digitare: :PluginSearch!

Alcuni plugin utili

Nel caso di neoclide, un plugin che abilita l'autocompletamento, da installare i seguenti moduli:

CocInstall coc-cmake coc-css coc-cssmodules coc-docker coc-emmet coc-flutter coc-highlight coc-html coc-htmlhint coc-html-css-support coc-json coc-ltex coc-markdown-preview-enhanced coc-markdownlint coc-omnisharp coc-prettier coc-pytho
n coc-sh coc-sql coc-vimlsp coc-xml coc-yaml coc-markdown-preview-enhanced coc-webview

Quindi eseguire:

cd ~/.vim/bundle/coc.nvim && git checkout release && yarn install && yarn build

vim

Comandi utili

Comando Funzione
gx Apre il link sotto al cursore nel browser
:m +/-n Sposta la riga sopra o sotto di n posizioni
"+y In Visual Mode, copia il testo selezionato nella clipboard del SO
vimv Da terminale, permette di rinominare cartelle e file coi comandi di Vim (https://github.com/thameera/vimv)
:args Seleziona dei file come argomenti. È possibile utilizzare i caratteri jolly
:argdo Permette di eseguire un comando su n files

Ad esempio:

:argdo %s/stringToBeReplaced/replacementString/g | update

update serve per salvare le modifiche automaticamente.

Collegamenti