דילוג לתוכן

מצב VI

הקדמה

הלוגו של Vim

Kate's VI mode is a project to bring Vim-like, modal editing to the Kate text editor and by extension to other KDE programs who share the same editor component. The project started as a Google Summer of Code project in 2008 – where all the basic functionality was written. I have continued to maintain and further develop this code and the number of missing features from Vim are slowly decreasing. Most Vim users will already be productive in Kate's VI mode. A list of what's missing is found at the bottom of the page.

This page is meant to be an updated overview of this work.

To enable the VI input mode, go to
Settings → Configure Kate… → Editing → VI Input Mode.
It can also be toggled with the "VI Input Mode" setting in the "Edit" menu. (The default shortcut key is Meta+Ctrl+V – where Meta usually is the Windows key).

יעדים

The goal of the VI mode is not to be a complete replacement for Vim and support all Vim's features. Its aim is to make the "Vim way" of text editing – and the Vim habits learned – available for programs using the Kate text editor as their internal editor. These programs include

  1. עורך הטקסט Kate
  2. KWrite – עורך הטקסט הפשוט של KDE
  3. KDevelop – סביבת פיתוח משולבת מתקדמת למגוון רחב של שפות תכנות
  4. Kile – עורך לאטך/LaTeX

The VI mode aims integrate nicely with the programs and deviate from Vim's behaviour where it makes sense. For example, :w will open a save dialogue in Kate's VI mode.

לקויות תאימות מול Vim

There are only a few features of Kate's VI mode which are incompatible with Vim (not counting things missing). They are listed below together with the respective reasons.

  1. Kate: U and Ctrl+r is redo
    Vim: Ctrl+r is normal redo, U is used to undo all latest changes on one line
    The reason for having U act as redo in Kate's VI mode is that the shortcut ctrl+r by default is taken by Kate's replace function (search and replace). By default, the VI mode won't override Kate's shortcuts (this can be configured in Settings → Configure Kate… → Editing → Vi Input Mode), therefore a redo-action needs to be available as a “regular” key press, too. Besides, the behaviour of the U command in Vim doesn't map well to Kate's internal undo system, so it would be non-trivial to support anyway.
  2. Kate: :print shows the "print" dialogue
    Vim: :print prints the lines of the given range like its grandfather ed Commands like :print are available not only in the VI mode but for users using “regular” Kate, too – I have therefore chosen to let the :print command open the print dialogue – following the principle of least surprise instead of mimicking Vim's behaviour.
  3. Kate: Y yanks to end of line.
    Vim: Y yanks whole line, just like yy. VI's behaviour for the Y command is in practice a bug; For both change and delete commands, cc/dd will do its action on the current line and C/D will work from the cursor column to the end of the line. However, both yy and Y yanks the current line.In Kate's VI Mode Y will yank to the end of the line. This is described as "more logical" in the Vim documentation.
  4. Kate: :map alters the selected lines of the document using the provided JavaScript expression.
    Vim: :map adds the provided mapping to Normal and Visual modes. The "map" command was already reserved by Kate; in 4.12+, you can use a combination of :nmap and :vmap to replace it.

פקודות נתמכות

Supported normal/visual mode commands

מקשתיאור
aכניסה למצב כתיבה והוספה לסוף
Aכניסה למצב כתיבה והוספה לסוף השורה
iכניסה למצב כתיבה
Iכתיבה לפני התו הראשון שאינו ריק בשורה
vכניסה למצב חזותי
Vכניסה למצב שורות חזותי
<c-v>כניסה למצב מקטעים חזותי
gvבחירה חזותית מחדש
oפתיחת שורה חדשה מתחת
Oפתיחת שורה חדשה מעל
Jצירוף שורות
cשינוי
Cשינוי לסוף השורה
ccשינוי שורה
sהחלפת תו
Sהחלפת שורה
ddמחיקת שורה
dמחיקה
Dמחיקה עד סוף השורה
xמחיקת תו
Xמחיקת תו אחורה
guהמרה לאותיות קטנות
guuהמרת השורה לאותיות קטנות
gUהמרה לאותיות גדולות
gUUהמרת השורה לאותיות גדולות
yשליפה
yyשליפת שורה
Yשליפה לסוף השורה
pהדבקה
Pהדבקה לפני
r.החלפת תו
Rכניסה למצב החלפה
:מעבר לשורת פקודות
/חיפוש
uהסגה
<c-r>ביצוע מחדש
Uביצוע מחדש
m.הגדרת סמן
>>הגדלת הזחת שורה
<<הקטנת הזחת שורה
>הגדלת הזחת שורות
<הקטנת הזחת שורות
<c-f>גלילת עמוד אחד למטה
<pagedown>גלילת עמוד אחד למטה
<c-b>גלילת עמוד אחד למעלה
<pageup>גלילת עמוד אחד למעלה
<c-u>גלילת חצי עמוד למעלה
<c-d>גלילת חצי עמוד למטה
zzמרכוז התצוגה סביב הסמן
gaהדפסת קוד תו
.חזרה על השינוי האחרון
==יישור שורה
=יישור שורות
~החלפת מצב רישיות (גדולות/קטנות)
<c-a>הוספה למספר
<c-x>חיסור מהמספר
<c-o>מעבר לקפיצה הקודמת
<c-i>מעבר לקפיצה הבאה
<c-w>hמעבר לתצוגה השמאלית
<c-w><c-h>מעבר לתצוגה השמאלית
<c-w><שמאלה>מעבר לתצוגה השמאלית
<c-w>jמעבר לתצוגה התחתונה
<c-w><c-j>מעבר לתצוגה התחתונה
<c-w><למטה>מעבר לתצוגה התחתונה
<c-w>kמעבר לתצוגה העליונה
<c-w><c-k>מעבר לתצוגה העליונה
<c-w><למעלה>מעבר לתצוגה העליונה
<c-w>lמעבר לתצוגה הימנית
<c-w><c-l>מעבר לתצוגה הימנית
<c-w><ימינה>מעבר לתצוגה הימנית
<c-w>wמעבר לתצוגה הבאה
<c-w><c-w>מעבר לתצוגה הבאה
<c-w>sפיצול אופקי
<c-w>Sפיצול אופקי
<c-w><c-s>פיצול אופקי
<c-w>vפיצול אנכי
<c-w><c-v>פיצול אנכי
gtמעבר ללשונית הבאה
gTמעבר ללשונית הקודמת
gqqעיצוב שורה
gqעיצוב שורות
q. / qהתחלת / סיום הקלטת מאקרו עם רשומת המאקרו השמית.

תנועות נתמכות

מקשתיאור
hשמאלה
<שמאלה>שמאלה
<backspace>שמאלה
jלמטה
<למטה>למטה
<enter>ירידה למה שלא ריק
kלמעלה
<למעלה>למעלה
עלייה למה שלא ריק
lימינה
<ימינה>ימינה
<רווח>ימינה
$לסוף השורה
<end>לסוף השורה
לעמודה 0
<home>לעמודה 0
^לתו הראשון בשורה
f.איתור תו
F.איתור תו אחורה
t.לתו
T.לתו אחורה
;חזרה על פעולת ה־t.‎ או ה־f.‎ האחרונה
,חזרה על פעולת ה־t.‎ או ה־f.‎ האחרונה
nאיתור הבא
Nאיתור הקודם
ggלשורה הראשונה
Gלשורה האחרונה
wמילה קדימה
Wמילה (באותיות גדולות) קדימה
bמילה אחורה
Bמילה (באותיות גדולות) אחורה
eלסוף מילה
Eלסוף מילה (באותיות גדולות)
geלסוף המילה הקודמת
gEלסוף המילה (באותיות גדולות) הקודמת
%לפריט התואם
`[a-zA-Z><]לסימן
'[a-zA-Z><]לסימון שורה
[[להתחלת המקטע הקודם שבסוגריים
]]להתחלת המקטע הבא בסוגריים
[]לסוף המקטע הקודם שבסוגריים
][לסוף המקטע הבא בסוגריים
*למופע הבא של המילה שתחת הסמן
#למופע הקודם של המילה שתחת הסמן
Hלשורה הראשונה בחלון
Mלשורה האמצעית בחלון
Lלשורה האחרונה בחלון
gjלשורה החזותית הבאה
gkלשורה החזותית הקודמת

עצמי הטקסט הנתמכים

מקשתיאור
iwמילה פנימית
awמילה
iWמילה (באותיות גדולות) פנימית
aWמילה (באותיות גדולות)
i"מירכאות כפולות פנימיות
a"מירכאות כפולות
i’מירכה פנימית בודדת
a’מירכה בודדת
i`גרש הפוך פנימי
a`גרש הפוך
ibסוגריים פנימיים
i)סוגריים פנימיים
i(סוגריים פנימיים
abסוגריים
a)סוגריים
a(סוגריים
iBסוגריים מסולסלים פנימיים
o}סוגריים מסולסלים פנימיים
i{סוגריים מסולסלים פנימיים
aBסוגריים מסולסלים
a}סוגריים מסולסלים
a{סוגריים מסולסלים
i<סימן אי שוויון פנימי
i>סימן אי שוויון פנימי
a<סימן אי שוויון
a>סימן אי שוויון
i[סוגר מרובע פנימי
I]סוגר מרובע פנימי
a[סוגר מרובע
a]סוגר מרובע
i,פסיק פנימי
a,פסיק

פקודות מצב כתיבה נתמכות

מקשתיאור
<c-d>הקטנת הזחת שורה
<c-t>הגדלת הזחה
<c-e>הוספה מלמטה
<c-y>הוספה מלמעלה
<c-w>מחיקת מילה
<c-r>.הוספת תוכן רשומה
<c-o>מעבר למצב רגיל לפקודה אחת
<c-a>הגדלת המספר שתחת הסמן
<c-x>הקטנת המספר שתחת הסמן

עצם טקסט שתחום בפסיק

This is something that I have been missing in Vim. The comma text object makes it easy to modify parameter lists in C-like languages and other comma separated lists. It is basically the area between two commas or between a comma and a bracket. In the line shown in the illustration to the right, the three ranges this text object can span are highlighted in red.

comma to

Comma text object ranges. If the cursor is over, say, “arg2”, pressing c i , (“change inner comma”) would delete “double arg2” and place the cursor between the two commas in insert mode. A very convenient way to change a function's parameters.

סרגל פקודות Vim מדומה

Kate 4.11 introduced a hidden config option that make /, ? and : bring up a new search/ command in place of the usual Kate Find / Replace / Command-line bar. The bar is intended to replicate many of the features of Vim's command bar, and also to fix many of the issues with Kate Vim mode's interaction with Kate's Find/Replace bar (interactive replace not working; incremental search not positioning the cursor correctly; not usable in mappings/macros; etc).

The following shortcuts are provided by the emulated command bar; as with Vim, these can be remapped with cmap, cnoremap, etc:

מקשתיאור
<c-r>.הוספת תוכן רשומה.
<c-r><c-w>הוספת מילה תחת סמן (המסמך).
<c-p>Invoke context-specific completion (see below)
move back/ up in the completion list.
<c-p>Move forward/ down in the completion list.
<c-רווח>Kate Vim Extension.
Auto-complete word from document.
<c-d>Kate Vim Extension.
In a sed-replace expression (i.e. s/find/replace/[g][c][i]),
clear the "find" term and place the cursor there.
<c-f>Kate Vim Extension.
In a sed-replace expression (i.e. s/find/replace/[g][c][i]),
clear the “replace” term and place the cursor there.
<c-g>.הרחבות Vim ל־Kate.
כמו עם ., להוסיף את תוכן הרשומה בעלת השם,
אבל למלט (escape) אותה בדרך שכשמשתמשים בה בחיפוש,
אנו מחפשים את התוכן של הרשומה בפועל,
לא את התוכן של הרשומה בפענוח לביטויים רגולריים.

ה„השלמה לפי הקשר” נקבעת לפי התנאים הבאים:

  • בסרגל חיפוש (/ או ?), השלמה אוטומטית מהיסטוריית החיפוש (שכוללת חיפושים שהופעלו דרך * ו־#, חיפושים שבוצעו בביטויי החלפה של sed וכו׳.)
  • In an empty command bar (:), auto-complete from command history (NB: auto-completion of command names is invoked automatically when you begin typing).
  • In a command-bar containing a sed-replace expression (e.g. :s/find/replace/gc), if the cursor is positioned over "find", auto-complete from the "search" history; if over the "replace", auto-complete from the history of "replace" terms.

When executing a sed-replace expression in the command bar with the "c" flag (e.g. s/find/replace/gc), a Vim-style interactive search/replace expression will be initiated.

Some example usages of the emulated command bar, with GIF animations, are given in this blog. In 4.11, the emulated command bar can be enabled by setting the hidden config option "Vi Input Mode Emulate Command Bar" to true in your katerc/kwriterc/kdeveloprc.

Missing Features

As stated earlier, the goal of Kate's VI Mode is not to support 100% of Vim's features, however, there are some features which are sorely missed

  • Visual block mode – especially the ability to prepend/append text to the visual block selection.
  • Having ex commands available in other programs than the Kate application.
  • The search code needs improvement and the * and # commands should just be regular searches.

If you miss other features or want to help on the ones mentioned above, feel free to contact me or send patches! :-)

יומן שינויים

  • 2010-05-16:
    Initial version. Collected the information from blog entries and README files to make a single source of current information.
  • 2010-05-17:
    Ctrl+A and Ctrl+X added (increment/decrement number under cursor).
  • 2010-08-30:
    Moved page to kate-editor.org.
  • 2010-09-10:
    Fixed the text on the comma text object and made some formatting fixes
  • 2021-02-03:
    Converted key-binding tables to markdown for hugo.