Hits : 5011

Vim – a very simple tutorial


Contents

  • Commands
  • multiple files
  • Folds
  • μη-ορατοί χαρακτήρες
  • Νέα καρτέλα
  • tabs
  • macros
  • file explorer
  • file explorer

  • vim : Vi Improved


    http://www.vim.org

    top


    Το Vim είναι o δημοφιλέστερος κειμενογράφος που υπάρχει.
    Έαν από τα χαρακτηριστικά του είναι ότι υποστηρίζει καταστάσεις (modes).
    Οι κυριότερες καταστάσεις είναι τρεις (3):


    Για να μεταβούμε στην Edit Mode πατάμε το πλήκτρο Insert.
    Για να μεταβούμε από την Edit Mode στην Command Mode πατάμε το πλήκτρο esc.
    Για να μεταβούμε από την Command Mode στην Execute Mode πληκτρολογούμε την άνω & κάτω τελεία (:).

    top

    Commands


    ZZ Αποθήκευση & Τερματισμος
    :q Τερματισμός Vim 
    :qa Τερματισμός Vim χωρίς καμία αποθήκευση
    :q! Τερματισμος Vim και αγνόησε αλλαγές
    :i Εισαγωγή στην κατάσταση κειμενογράφου
    :e file_name Άνοιγμα Αρχείου
    :edit file_name Άνοιγμα Αρχείου
    :d Delete lines
    :m Move lines

    top

    More Commands


    :set nu  Εμφάνιση Γραμμών
    :set nonu Μη εμφάνιση γραμμών
    :noh No highlight
    :syntax on  Εμφάνιση σύνταξης κώδικα
    :! cmd  Εκτέλεση εντολής cmd 
    :r! cmd  Eκτέλεση εντολής cmd και insert το output στο κείμενο
    :%s :%s/ to_string_pou_theloume_na_allaksoume / to_string_pou_theloume_na_valoume /
    :sp filename Άνοιγμα αρχείου διαιρώντας το παράθυρο
    Insert next letter
    shift+i Insert previous letter
    Insert on below line
    shift +o Insert on above line
    dd  Delete line
    yy  Copy line
    Paste
    Undo
    replace character
    replace characters
    Μαρκάρισμα γραμμής
    'x Μετάβαση στην μαρκαρισμένη γραμμή
    ''ayy Copy test to buffer a [a-z]
    ''ap Paste a text buffer
    dw  delete word
    d$ delete from here to the end of the line

    top

    Vim Options


    Άνοιγμα δύο (2) ή περισσοτέρων αρχείων σε οριζόντια διαχώριση:

    Formatter "highlight/html" not found
    top

    Άνοιγμα δύο (2) ή περισσότερων αρχείων σε κάθετη διαχώριση:

    Formatter "highlight/html" not found

    Άνοιγμα και τοποθέτηση του κέρσορα στο τέλος ενός αρχείου:

    Formatter "highlight/html" not found

    Άνοιγμα και τοποθέτηση του κέρσορα σε συγκεκριμένη γραμμή ενός αρχείου:

    Formatter "highlight/html" not found

    Άνοιγμα και τοποθέτηση του κέρσορα στο αλφαρηθμητικό αναζήτησης ενός αρχείου:

    Formatter "highlight/html" not found

    Άνοιγμα αρχείου με κωδικό:
    vim -x test
    Enter encryption key: ****
    Enter same key again: ****


    Και οτιδήποτε γράφουμε γίνεται encrypted.
    > cat test
    VimCrypt ~01!��


    top

    vim usefull


    Θέλουμε να τροποποιήσουμε ένα αλφαριθμητικό με ένα άλλο από την γραμμή m έως την γραμμή n:

    Formatter "highlight/html" not found

    Θέλουμε να προσθέσουμε ένα σχόλιο στην αρχή σε όλες τις γραμμές:

    Formatter "highlight/html" not found

    Θέλουμε να διαγράψουμε όλες τις κενές γραμμές από ένα αρχείο:

    Formatter "highlight/html" not found

    Θέλουμε να μεταφέρουμε 5 γραμμές στην αρχή :

    Formatter "highlight/html" not found

    Θέλουμε να διαγράψουμε όλες τις γραμμές από το σημείο που είμαστε μέχρι το τέλος του αρχείου:

    Formatter "highlight/html" not found

    Θέλουμε να ταξινομήσουμε ένα συγκεκριμένο αριθμό γραμμών :

    Μεταβαίνουμε στην γραμμή και γράφουμε
    :.,+162 sort


    top

    vim tabs


    Στην έκδοση 7 του vim, υπάρχει η δυνατότητα του tab.

    Formatter "highlight/html" not found

    Όταν θέλω να τρέξω μία εντολή σε όλα τα tabs γράφω:

    Formatter "highlight/html" not found

    εναλλακτικά:

    vim testfile1
    :tabe testfile2

    [ctrl] + w (twice)

    για να αλλάξω καρτέλα

    Vim Map Commands


    Disable the F1 (help) in vim:

    :nmap <F1> <nop>


    Add a custom command to key shortcut:

    :map <f1> :r! export -p LC_ALL=C; echo "\# ebal, `date`"<return>

    Vim Cheat Sheet


    file:vimcheatsheet.gif

    top

    My vimrc


    " ebal, Mon Feb 14 08:37:12 EET 2011
    syntax on
    set nu
    set hlsearch
    
    :map <f1> :r! echo "\# ebal, `date -R`"<return>
    
    :setlocal spell spelllang=en_us


    top

    multiple files


    eg. vim file1 file2

    go to the next file :

    :bn

    list opened files:

    :ls

    split them into horizontal split

    :split file2

    split them into vertical

    :vs file2

    move from one split to another

    [ctrl] + w + right arrow
    [ctrl] + w + left arrow

    or

    [ctrl] + w (twice)


    top

    Folds


    :set foldmethod=expr
    :set foldexpr=getline(v:lnum)=~\"\\#\"
    
    :set foldmethod=expr
    :set foldexpr=getline(v:lnum)=~\"\\#\"&&getline(v:lnum)=~'\\S'?'<1':1
    
    zf --> manual fold
    
    zi
    zR
    
    zo : fold open
    zc:  fold close


    top

    μη-ορατοί χαρακτήρες


    Δείξε τους μη-ορατούς χαρακτήρες:

    :set list



    Κρύψε τους μη-ορατούς χαρακτήρες:

    :set list!


    top

    Νέα καρτέλα


    eg.

    vim -p src/*.ml


    open a new tab

    :tabe[dit] newfile


    Μετακίνηση μεταξύ των tabs: gt ή gT
    Μετακίνηση ενός tab στο τέλος :tabmove

    Αναζήτηση σε όλα τα tabs

    :vimgrep pacman **


    top


    tabs


    tabstop

    :set tabstop


    επιστρέφει τον αριθμό χαρακτήρων του tab

    :set tabstop 16


    θέτει τον αριθμό χαρακτήρων του tab

    expandtab

    εάν ενεργοποιηθεί, προσθέτει spaces στο πλήθος ενός tab

    indentation mode:

    >
    <


    shiftwidth

    μπορείς να αλλάξεις το shiftwidth σε κάτι διαφορετικό από το tabstop

    Προσθήκη tab χαρακτήρων σε γραμμές:

    visual mode (select lines) & >
    για προσθήκη tab χαρακτήρων

    < για μείωση tab χαρακτήρων

    softtabstop

    δεν κατάλαβα τι είναι :(

    top



    macros


    recordings of your typings to save you time and be awesome

    eg. You want to remove any comments from your source code

    :%s/^#/d

    first you need to choose a macro name: c
    c for comments

    (escape mode)

    type: q 
    and after that: c
    type your code:

    :%s/^#/d

    and after that type: q

    You can see your macros with: reg
    (registers)

    :help reg

    for more info

    To run your macro: @c

    and see the magic

    top



    file explorer


    :Explore ~


    opens a new tab to your home dir for choosing a new file to edit.
    x over an dir and the default file manager will popup up


    top

    file explorer


    vim abbreviations

    :h abbreviations
    
    :iab teh the
    :iabclear
    
    :iabbrev teh the
    :iab


    top