Outils pour utilisateurs

Outils du site


linux:vim

Vim

Partage des "presse-papier" bureau / terminal / vim

  • presse-papier extérieur → vim :
    • copier : CTRL + INS
    • coller : SHITF + INS
  • presse-papier vim → extérieur :
    • copier : CTRL + [
    • coller : CTRL + ]

Commandes diverses

Help : :h
Edit file : :e [file]
Répéter la dernière commandes entrée avec : : La première fois : @: et ensuite @@

Buffers

lister les buffers ouverts : :ls
go to next buffer :bn
delete buffer : :bd

Windows

Séparer l'écran en vertical : :vsplit [fichier(optionnel)]
Changer de fenêtre de focus : CTRL + W CTRL + W ou CTRL + W arrowKeys|hjkl
Inverser les fenêtres : CTRL + W r

Vimdiff

Utiliser vimdiff entre deux fenêtres: (2 windows split) :windo diffthis

  • in destination window : diffget
  • in source window : diffput

Configuration

A la volée ou avec le fichier vimrc

A la volée, par exemple :set number! en mode commande, ou perde façon permanente, globalement avec le fichier /etc/vim/vimrc ou par utilisateur avec le fichier ~/perso.vimrc. En mode commande :set number devient set number dans le vimrc (la même commande, sans le :). Rajouter un ! à la fin bascule la commande off.

++++ Config perso /etc/vim/vimrc |

/etc/vim/vimrc
" set colorscheme
colo delek
" show line numbers
set number
" show lastline statusbar always
set laststatus=2
" Change colorscheme in case of vimdiff
if &diff
    colorscheme torte
endif
" override some of the colorscheme colors
augroup vimrc
  autocmd!
  autocmd ColorScheme * hi LineNr ctermfg=8 | hi StatusLine  ctermfg=15 ctermbg=blue cterm=NONE | hi StatusLineNC ctermfg=0 ctermbg=8 cterm=NONE
augroup END

++++

Couleurs

Apparemment, indiquer les couleurs par leur nom fonctionne mieux sur différents terminaux, avec/sans screen, etc…

RedLightRedDarkRed
GreenLightGreenDarkGreenSeaGreen
BlueLightBlueDarkBlueSlateBlue
CyanLightCyanDarkCyan
MagentaLightMagentaDarkMagenta
YellowLightYellowBrownDarkYellow
GrayLightGrayDarkGray
BlackWhite
OrangePurpleViolet

Editer des fichiers distants avec ssh

FIXME

scp

vim scp://remoteuser@server[:port]//absolute/path/to/document    # port optionnal

sshfs

sudo apt-get install sshfs

and then mount localy the remote filesystem ( issue on your local machine )

mkdir ~/remote_code
sshfs $USER@remote.example.com:/home/$USER/code ~/remote_code

Depending on what you mean when you say you do not have the rights to edit the Vim settings on the remote machine, there may be a way of using Vim on the server in the way you want anyway. If you can't change your user .vimrc (because you're logging in as a shared user, for example) but you can still create files, create it as a file called, say, Loom.vimrc and then call Vim using the -u switch:

vim -u ~/Loom.vimrc file_to_edit

You can even then use an alias: alias vim='vim -u ~/Loom.vimrc' will allow you to use Vim in the usual way, and it'll still load your custom .vimrc file. This alias won't persist after you log out, so you don't need to worry about anyone else accidentally using your customised Vim.

Ouvrir plusieurs fichiers

FIXME This page is a mess and should be rewritten.

Why not use tabs (introduced in Vim 7)? You can switch between tabs with :tabn and :tabp, With :tabe <filepath> you can add a new tab; and with a regular :q or :wq you close a tab. If you map :tabn and :tabp to your F7/F8 keys you can easily switch between files.

If there are not that many files or you don't have Vim 7 you can also split your screen in multiple files: :sp <filepath>. Then you can switch between splitscreens with Ctrl+W and then an arrow key in the direction you want to move (or instead of arrow keys, w for next and W for previous splitscreen) share|improve this answer

To save and close a tab, you can also use ZZ instead of :wq (just like would normally save and close)

I'm using the vim-gnome package in Ubuntu 10.10, and I can switch between tabs using Ctrl+PageUp and Ctrl+PageDown. I didn't have to configure anything; it was default.

Also, in edit mode gt goes to the next tab, and gT goes to the previous tab.

You can jump to any tab by using ngt, where n is the index of the tab (beginning with one). I think there's an option that displays the index of each tab near the file name, but I don't know what it is. If anyone knows, I'd love to hear it.

Note also that you can use the -p flag to open multiple files in tabs from the command line. For example, gvim -p main.pl maintenance.pl will open these two files in tabs

search?q=vim&amp;btnI=lucky

linux/vim.txt · Dernière modification: 2018/04/30 13:01 (modification externe)