Vim

Neovim

Install latest version from: https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.deb

Install AstroVim: https://github.com/AstroNvim/AstroNvim

Nerd Fonts

DWL:

wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.3.3/3270.zip

mkdir ~/.local/share/fonts
unzip 3270.zip -d  ~/.local/share/fonts
fc-cache -f -v

Install:

mv ~/.config/nvim ~/.config/nvim.bak
mv ~/.local/share/nvim ~/.local/share/nvim.bak
git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim

Config:

Install LSP

  Enter :LspInstall followed by the name of the server you want to install
  Example: :LspInstall pyright
Install language parser

Enter :TSInstall followed by the name of the language you want to install
  Example: :TSInstall python

Update AstroNvim
  Run :AstroUpdate to get the latest updates from the repository

Paste X -> Vim

Set in ~/.vimrc:

set mouse=v
or
set mouse=""

Indent

in order to auto indent a section (a selection of rows for example) we can use:

>

Indent more

<

Indent less

=

Autoindent

:set sw=2

Change indent to 2 spaces

Re-indent a whole file

ggG=

Wich means: go to the top, select to the end of file, auto indent.

vimrc

.vimrc:

syntax enable
filetype plugin indent on
set background=dark
set ofu=syntaxcomplete#Complete

autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS

augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 80 characters.
  autocmd FileType text setlocal textwidth=80

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

augroup END

" Set paste macro
map <F2>        :set paste! <CR>:set paste?<CR>
imap <F2> <C-O> :set paste<CR>
map <F3>        :set number! <CR>:set number?<CR>
imap <F3> <C-O> <CR> <C-O>:set number?<CR>


' Save macro
map <Esc><Esc> :update<CR>

" Ruby
autocmd FileType ruby setlocal shiftwidth=2 tabstop=2

" Arduino
autocmd! BufNewFile,BufRead *.ino setlocal ft=arduino

" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]

" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview

Auto indent

In order to set C-style auto indenting with a 4 spaces TABs:

" Smartindent with 4 spaces
set cindent
set tabstop=4
set shiftwidth=4
set expandtab

To turn all tabs in spaces: :%retab

Fast set-up: set expandtab ts=4 sw=4 ai

In previous .vimrc there was filetype plugin indent on wich defins indent as well on a file type basis (but no TAB width).

Movements

H   move to top of screen
M   move to middle of screen
L   move to bottom of screen

Scroll page

SHIFT g

jumps to end of file.

gg

jumps to the beginning of file.

``

jumps to previous location

Page movements

CTR d

Scrolls down half page of text

CTR b

Scrolls up an entire page

CTR e

Scrolls down a single line

CTR y

Scrolls up a single line

In page movements

z ENTER

Actual line goes on top

  1. or zz

    Actual line goes to middle of the screen

z-

Actual line to bottom of the screen

Marks

  • ma set mark a at current cursor location

  • ‘a jump to line of mark a (first non-blank character in line)

  • `a jump to position (line and column) of mark a

  • d’a delete from current line to line of mark a

  • d`a delete from current cursor position to position of mark a

  • c’a change text from current line to line of mark a

  • y`a yank text to unnamed buffer from cursor to position of mark a

  • :marks list all the current marks

  • :marks aB list marks a, B

Registers

Previous yanked / deleted buffers are available with : :registers . This can be re-used with es:

"2p

Paste not last (1) but previous buffer.

It is possible to create custom bufferrs: after making a selection: "ayy copies the content of a line and assign it to the buffere "a .

Comments

For fast one / multiple line comment use: http://www.vim.org/scripts/script.php?script_id=1528

[CTR] + c

Comment one or mole lines (visual)

[CTR] + x

Un-Comment one or mole lines (visual)

HTML closing tags

When typing an html document, you can automatically close html tags using omni completion. For example, you may type <li>example</ then press Ctrl-x Ctrl-o to automatically finish typing the tag so the text reads <li>example</li>.

With the following abbreviation in your vimrc, you can simplify this process:

:iabbrev </ </<C-X><C-O>

With this abbreviation, you can simply type </ then press Space to automatically complete the tag.

C++ formatting

apt-get install astyle
:%!astyle   (inside vim)

in .vimrc:
map <F4>    :%!astyle<CR>

Ctags

  • ctags -R .

  • Jumping to a tag: You can position the cursor over a tag name and then press Ctrl-]

  • Returning after a tag jump: You can press Ctrl-t.

  • Ctrl+W Ctrl+] - Open the definition in a horizontal split

gd

gd trova la prima occorrenza di una parola su cui e’ il cursore, in genere la definizione della funzione.

Inside / around

ci”

si posiziona dentro un double quotes

ca”

cambia attorno ai double quotes

Funziona con w , tags t , braces {, brackets [, …

Increment

[CTR]a

su un numero

Macro

qa

registra una macro in a

@a

riesegue quella macro

Spell Check

Commands:

]s   [s     move
z=          suggest
zg          add

Powerline

Debian way

installare:

apt-get install vim-nox powerline python3-powerline fonts-powerline

.tmux.conf

source "/usr/share/powerline/bindings/tmux/powerline.conf"

.bashrc

# powerline
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/share/powerline/bindings/bash/powerline.sh

.vimrc:

Per Vim non ci sono le estensioni!
Bisogna installare tutto manualmente :(

~/.ipython/profile_default/ipython_config.py

c = get_config()
c.InteractiveShellApp.extensions = [
    'powerline.bindings.ipython.post_0_11'
]

Manual install

Install python mode:

git clone --depth 1 https://github.com/klen/python-mode.git
cp -R python-mode/* ~/.vim

    Then rebuild helptags in vim:

:helptags ~/.vim/doc/

Installare powerline per pip3 / python 3 e controllare il path:

apt-get install python3-pip
pip3 install powerline-status

In .vimrc:

" powerline
set rtp+=/usr/local/lib/python3.5/dist-packages/powerline/bindings/vim/
set laststatus=2
set t_Co=256
let g:Powerline_symbols = 'fancy'

" flake skip errors reports
let g:pymode_lint_ignore="E221,E251"

Fonts per powerline, l’install fa fatto per ogni utente:

git clone --depth 1 https://github.com/powerline/fonts
fonts/install.sh

oppure:

apt-get install fonts-powerline

Serve vim con il supporto di python3, tipicamente vim-nox:

apt-get install vim-nox
vim --version | grep +python

.vimrc

"ctags
set tags=tags;
map <M-Right> <C-]>
map <M-Left> <C-T>
set mouse ="a"
syntax enable
filetype plugin on
set nocp
set ignorecase
set smartcase
set background=dark
set ofu=syntaxcomplete#Complete

autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS

filetype plugin indent on
"" Smartindent with 4 spaces
set cindent
set tabstop=4
set shiftwidth=4
set expandtab

augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 80 characters.
  autocmd FileType text setlocal textwidth=80

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

augroup END

let mapleader = "\\"
" Set paste macro
map <F2>    :set paste! <CR>:set paste?<CR>
imap <F2> <C-O> :set paste<CR>
map <F3>    :set number! <CR>:set number?<CR>
imap <F3> <C-O> <CR> <C-O>:set number?<CR>
map <F4>    :%!astyle<CR>

"Save macro
map <F5> :update <CR>
map <F6> :update <CR>
map <Leader>' :update <CR>

" Ruby
autocmd FileType ruby setlocal shiftwidth=2 tabstop=2

" Arduino
autocmd! BufNewFile,BufRead *.ino setlocal ft=arduino
" C Stuff
" prérequis tags

" configure tags - add additional tags here or comment out not-used ones
"set tags+=~/.vim/tags/stl

" build tags of your own project with CTRL+F12
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
noremap <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>
inoremap <F12> <Esc>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>

" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]

" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview

" powerline
set rtp+=/usr/local/lib/python3.5/dist-packages/powerline/bindings/vim/
set laststatus=2
set t_Co=256
let g:Powerline_symbols = 'fancy'

" pymode
let g:pymode_options = 1
let g:pymode_run = 1
let g:pymode_run_bind = '<leader>r'

.tmux.conf

source "/usr/local/lib/python3.5/dist-packages/powerline/bindings/tmux/powerline.conf"

.bashrc

# powerline
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/local/lib/python3.5/dist-packages/powerline/bindings/bash/powerline.sh

Note

In genere bisogna far ripartire il server grafico.

Windows

ctrl-w up arrow

move cursor up a window

ctrl-w ctrl-w

switch between windows

ctrl-w ctrl _

Maximize current window

:split filename

split window and load another file vsplit for vertical

[CTRL]w[SHIFT]s

split orizzontal current buffer

:only

keep only this window open

CTRL-w CTRL-o

select actual window and close others

<C-w>n - :new horizontal split (editing a new empty buffer)
<C-w>s - :split window horizontally (editing current buffer)
<C-w>v - :vsplit window vertically (editing current buffer)
<C-w>c - :close window
<C-w>o - close all windows, leaving :only the current window open
<C-w>w - go to next window
<C-w>p - go to previous window
<C-w><Up> - go to window above
<C-w><Down> - go to window below
<C-w><Left> - go to window on left
<C-w><Right> - go to window on right

Tabs

:tabnew

new tab

:tabedit

new tab wih a file

Navigating between tabs can be done with the mouse, or with commands

:tabn - next tab
:tabp - previous tab
:tabc - close current tab
:tabo - close all other tabs leaving ONLY the current tab open

You can also navigate to next/previous tabs using the <C-PageDown> and <C-PageUp> keys.

Folding

z-M

close all

z-R

open all

za

Toggle

zo

Open

zc

Close

zj zk

move to next prev

Setup folding: :set foldmethod=syntax

Autopep

F8

Autopep, syntax for python

Ctags

ctags -R *

Gereare i tags

Ctrl-]

Jump to the tag underneath the cursor

Ctrl-t

Jump back up in the tag stack

Neovim

Disable mouse for paste:

init.lua

    vim.opt.mouse = ""