Vim (Italiano)

From ArchWiki
Revision as of 08:46, 18 October 2011 by Maveloth (Talk | contribs) (Undo and Redo: translate)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Vim (Italiano)#)
Attenzione: Questo articolo è in fase di traduzione. Seguite per ora le istruzioni della versione inglese.

Template:Article summary start Template:Article summary text Template:Article summary end

"Vim is an advanced text editor that seeks to provide the power of the de-facto UNIX editor ‘vi’, with a more complete feature set." Vim is not a simple text editor like nano or pico. It does require some time to learn, and a great amount of time to master.

Vim is designed to make your fingers work as little as possible, and you should never have to use the mouse. This may seem odd, but once you master vim, you’ll begin to understand the reasoning.

Feature

  • Vim è molto potente per effettuare editing avanzati
  • Espandibile, grazie alle opzioni di configurazione
  • Semplici e robuste scorciatoie da tastiera
  • Evidenziazione della sintassi

Installazione

  • Per installare vim per la linea di comando
pacman -S vim
  • Per installare la versione con la GUI (fornisce vim):
pacman -S gvim
Nota: Vim non è più compilato con l'opzione X server. Per molti utenti, significa che la normale funzione di copia e incolla dagli appunti di un ambiente grafico non funzionerà. Se questa è una operazione fondamentale, considerare l'installazione di Template:Package Official che include una versione di Vim con questo supporto. (Attribution)

Usage

This is a basic overview on how to use vim. Alternately, you could use Template:Codeline to further familiarize yourself. Vim has four different modes:

  • Command mode: keystrokes are interpreted as commands.
  • Insert mode: keystrokes are entered into the file.
  • Visual mode: keystrokes select, cut, or copy text
  • Ex mode: input mode for additional commands (e.g. saving a file, replacing text...)

Basic Editing

If you start vim with:

$ vim somefile.txt

you will see a blank document (providing that somefile.txt does not exist. If it does, you will see what is in there). You will not be able to edit right away – you are in Command Mode. In this mode you are able to issue commands to vim with the keyboard.

Note: Vim is an example of classic Unix-style ware. This means that it is not flashy, and it will not hold your hand. It does not come with built-in paperclips and games. It will allow you to get the job done however, and quickly too. Also, all commands are case sensitive. Sometimes the uppercase versions are “blunter” versions (s will replace a character, S will replace a line), other times they are completely different commands (j will move down, J will join two lines).

You insert text (stick it before the cursor) with the i command. I (uppercase i) inserts text at the beginning of the line. You append text (place text after the cursor, what most people expect) with a. Typing A will place the cursor at the end of the line.

Return to command mode at any time by pressing Template:Keypress.

Moving Around

In vim, you can move the cursor with the arrow keys, but this isn't the vim way. You’d have to move your right hand all the way from the standard typing position all the way to the arrow keys, and then back. Not fun.

In vim you can move down by pressing j. You can remember this because the “j” hangs down. You move the cursor back up by pressing k. Left is h (it's left of the “j”), and right is l (lowercase L).

^ will put the cursor at the beginning of the line, and $ will place it at the end.

Note: ^ and $ are commonly used in regular expressions to match the beginning and ending of the line. Regular expressions are very powerful and are commonly used in *nix environment, so maybe it is a little bit tricky now, but later you will notice “the idea” behind the use of most of these key mappings.

To advance a word, press the w key. W will include more characters in what it thinks is a word (e.g. underscores and dashes as a part of a word). To go back a word, b is used. Once again, B will include more characters in what vim considers a word. To advance to the end of a word, use e, E includes more characters.

To advance to the beginning of a sentence, ( will get the job done. ) will do the opposite, moving to the end of a sentence. For an even bigger jump, { will move the the beginning a whole paragraph. } will advance to the end of a whole paragraph.

To advance to the header (top) of the screen, H will get the job done. M will advance to the middle of the screen, and L will advance to the last (bottom). gg will go to the beginning of the file, G will go to the end of the file. <ctrl>D will let you scroll page by page.

Repeating commands

If a command is prefixed by a number, then that command will be executed that number of times over (there are exceptions, but they still make sense, like the s command). For example, pressing 3i then “Help! ” then Esc will print “Help! Help! Help!“. Pressing 2} will advance you two paragraphs. This comes in handy with the next few commands…

Deleting

The x command will delete the character under the cursor. X will delete the character before the cursor. This is where those number functions get fun. 6x will delete 6 characters. Pressing . (dot) will repeat the previous command. So, lets say you have the word "foobar" in a few places, but after thinking about it, you’d like to see just “foo”. Move the cursor under the "b", hit 3x, move to the next "foobar" and hit . (dot).

The d will tell vim that you want to delete something. After pressing d, you need to tell vim what to delete. Here you can use the movement commands. dW will delete up to the next word. d^ will delete up unto the beginning of the line. Prefacing the delete command with a number works well too: 3dW will delete the next three words. D (uppercase) is a shortcut to delete until the end of the line (basically d$). Pressing dd will delete the whole line.

To delete then replace the current word, place the cursor on the word and execute the command cw. This will delete the word and change to insert mode. To replace only a single letter use r.

Annulla e ripeti

Vim ha una funzione appunti integrata (anche nota come buffer). Le azioni possono essere annullate con il tasto Template:Keypress e ripetute con la combinazione Template:Keypress+Template:Keypress.

Visual Mode

Pressing v will put you in visual mode . Here you can move around to select text, when you’re done, you press y to yank the text into the buffer (copy), or you may use c to cut. p pastes after the cursor, P pastes before. V, Visual Line mode, is the same for entire lines. Ctrl-v is for blocks of text.

Note: Whenever you delete something, that something is placed inside a buffer and is available for pasting.

Search and Replace

To search for a word or character in the file, simply use / and then the characters your are searching for and press enter. To view the next match in the search press n.

To search and replace use the substitute :s/ command. The syntax is: Template:Codeline. For example:

Command        Outcome
:s/xxx/yyy/    Replace xxx with yyy at the first occurence
:s/xxx/yyy/g   Replace xxx with yyy first occurrence, global (whole sentence)
:s/xxx/yyy/gc  Replace xxx with yyy global with confirm
:%s/xxx/yyy/g  Replace xxx with yyy global in the whole file

You can use the global :g/ command to search for patterns and then execute a command for each match. The syntax is: Template:Codeline.

Command  Outcome
:g/^#/d  Delete all lines that begins with #
:g/^$/d  Delete all lines that are empty

Saving and Quitting

To save and/or quit, you will need to use Ex mode. Ex mode commands are preceded by a :. To write a file use :w or if the file doesn’t have a name :w filename. Quitting is done with :q. If you choose not to save your changes, use :q!. To save and quit :x. There is also another shortcut for saving and then quitting which is the combination of <shift>zz

Additional Commands

  1. Pressing s will erase the current letter under the cursor, and place you in insert mode. S will erase the whole line, and place you in insert mode.
  2. o will create a newline below the line and put you insert mode, O will create a newline above the line and put you in insert mode.
  3. yy will yank an entire line
  4. cc will delete the current line and place you in insert mode.
  5. * will highlight the current word and n will search it

Configuration

Vim's personal configuration file is located in the home directory: Template:Filename. Advanced users tend to keep a well-tailored Template:Filename. The global configuration file is located at Template:Filename. The fall-back Template:Codeline variable is defined as Template:Filename. For example, to create a global colorscheme the Template:Filename colorscheme file should be stored in Template:Filename.

Currently, the vim global configuration in Arch Linux is very basic and differs from many other distributions' default vim configuration file. To get some commonly expected behaviors (like syntax highlighting, return to the line of the last edit...), consider using vim's example configuration file:

cp /etc/vimrc /etc/vimrc.bak
cp /usr/share/vim/vim73/vimrc_example.vim /etc/vimrc

Backup Files

Vim by default creates a backup of an edited file in the same directory as the file called Template:Filename. To prevent clutter, many users tell vim to use a backup directory:

set backupdir=~/.vim/backup,/tmp

Or, it's possible to even disable this behavior:

set nobackup
set nowritebackup
set noswapfile    ! (additionally disable swap files)

Wrap Searches

set wrapscan

Check Spelling

set spell

Vim will now highlight incorrectly spelled words. With the cursor on a misspelled word, use z= to view suggested corrections.

Only English language dictionaries are installed by default, more can be found at the vim ftp archive. After downloading the spl files for the given language (e.g. hu.cp1250.spl, hu.iso-8859-2.spl and/or hu.utf-8.spl for Hungarian) into Template:Filename, run:

:setlocal spell spelllang=LL

To activate spell checking for the selected language (i.e. Template:Codeline for the above mentioned example).

Syntax Highlighting

To enable syntax highlighting (vim supports a huge list of programming languages):

filetype plugin on
syntax on

Example Template:Filename

An example Template:Filename covering common options.

Template:File

Some more examples can be found in #Resources.

Merging Files (Vimdiff)

Vim includes a diff editor (a program that can merge differences between two files). Begin with Template:Codeline; to use:

]c :        - next difference
[c :        - previous difference
Ctrl+w +w   - switch windows
do          - diff obtain
dp          - diff put
zo          - open folded text
zc          - close folded text
:diffupdate - re-scan the files for differences

Vim Tips

Specific user tricks to accomplish tasks.

Line Numbers

  1. Show line numbers by Template:Codeline.
  2. Jump to line number Template:Codeline.

Substitute on Lines

To only substitute between certain lines:

:n,ns/one/two/g

For example, to replace instances of 'one' with 'two' between lines 3&4, one would execute:

:3,4s/one/two/g

Make Vim restore cursor position in files

If you want the cursor to appear in its previous position after you open a file, add the following to your Template:Filename:

if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
endif

See also this tip in Vim Wiki.

Empty space at the bottom of gvim windows

When using a window manager configured to ignore window size hints, gvim will fill the non-functional area with the GTK theme background color.

A solution is to make a more pleasing background color: just put the following lines in Template:Filename:

style "vimfix" {
  bg[NORMAL] = "#242424" # this matches my gvim theme 'Normal' bg color.
}
widget "vim-main-window.*GtkForm" style "vimfix"

Resources

Official

Tutorials

Example configurations

Other

  • HOWTO Vim -- Gentoo wiki article which this article was based on (author unknown).