Wikia

Vim Tips Wiki

Using standard editor shortcuts in Vim

Talk0
1,599pages on
this wiki
Revision as of 08:22, July 14, 2012 by JohnBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Recently created tip

We have not yet decided whether to keep this tip as its own page or merge it somewhere else. If you have a suggestion on the tip content, please edit this page or add your comments below (do not use the discussion page).

Please discuss whether to keep this as a new tip, or whether to merge it into an existing tip, on the new tips discussion page.
created May 3, 2012 · complexity basic · author Baliganikhil · version 7.0

Many first time users find it very hard to use Vim. Especially those who come from X-Windows based editors (GUI Editors). This is a small tip to map standard shortcuts which we find in most editors with shortcuts in Vim.

Mapping short-cut keysEdit

Open the ~/.vimrc file if it exists, if not, create a new file. Paste the following remapping code into it.

set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

set mouse=a
se nu

:map <C-a> GVgg
:map <C-n> :enew
:map <C-o> :e . <Enter>
:map <C-s> :w <Enter>
:map <C-c> y
:map <C-v> p
:map <C-x> d
:map <C-z> u
:map <C-t> :tabnew <Enter>
:map <C-i> >>
:map <C-w> :close <Enter>
:map <C-W> :q! <Enter>
:map <C-f> /
:map <F3> n
:map <C-h> :%s/
:map <S-t> vat
:map <S-T> vit
:map <S-{> vi{
:map <S-(> vi(
:map <S-[> vi[

Once you are done, restart Vim. Now the following should work.

Ctrl + a --> Select All
Ctrl + n --> New File (Also See Ctrl + t)
Ctrl + o --> Open File (Opens current folder to browse)
Ctrl + s --> Save File
Ctrl + c --> Copy
Ctrl + v --> Paste
Ctrl + x --> Cut
Ctrl + z --> Undo
Ctrl + r --> Redo
Ctrl + t --> Open new tab
Tab --> Indent
Ctrl + w --> Close (tab)
Ctrl + W --> Force close (Quit)
Ctrl + f --> Find
F3 --> Find Next
Ctrl + h --> Replace All
Shift + t --> Select (HTML, XML etc.) tag (inclusive)
Shift + T --> Select (HTML, XML etc.) tag (exclusive)
Shift + { --> Select text between flower brackets
Shift + [ --> Select text between square brackets
Shift + ( --> Select text between parentheses

CommentsEdit

This is my first tip - If there are some mistakes or improvements that can be made, please do let me know


I don't think I'd ever recommend anything like this, without offering replacements for the lost functionality. Almost everything you use here overrides a very useful built-in command.

Ctrl + a --> Increment number
Ctrl + n --> ''this one is OK, a synonym for the j command''
Ctrl + o --> Navigate backward in jump list
Ctrl + s --> ''this one is OK, it doesn't do anything on its own''
Ctrl + c --> Interrupt action that is taking too long
Ctrl + v --> Start "visual block" mode
Ctrl + x --> Decrement number
Ctrl + z --> Send Vim to background ''admittedly, probably OK for GUI vim''
Ctrl + r --> No need for a mapping, this is already a redo action
Ctrl + t --> Go back in tag list
Ctrl + i/Tab --> Navigate forward in jump list
Ctrl + w --> prefix for ALL the window switching commands
Ctrl + W --> Indistinguishable from the above
Ctrl + f --> ''probably OK, there are synonyms and this is probably infrequently used''
F3 --> ''This is OK, Vim doesn't use any F{num} keys by default''
Ctrl + h --> ''this is OK, synonym for the h command''
Shift + t --> Jump to previous specified letter
Shift + T --> indistinguishable from above (think about it, how do you type 'T' compared to 't'?)
Shift + { --> { is "jump to previous paragraph", very useful...I'm not sure how you'd even type Shift+{, it's already a shifted key.
Shift + [ --> [ starts many movement commands, Shift+[ gives you a {.
Shift + ( --> ( jumps between sentences, but ( is already shifted, how do you even type this?

If you want a point-and-click editor, you might try the Cream distribution of Vim. But in general, intentionally crippling Vim's powerful interface is a bad idea. --Preceding unsigned comment added by Fritzophrenic 20:54, May 3, 2012

You are right in that some features get overwritten. This tip is not for advanced users - it is for beginners who find it very hard to remember commands but are used to these in other editors. --Preceding unsigned comment added by Baliganikhil 08:46, May 4, 2012
Thanks to Baliganikhil for the new tip, but Fritzophrenic is correct: Vim users should work how to use Vim (Tutorial is the start of an attempt to provide guidance), so these mappings are more of a current individual preference than general advice. Perhaps this should be moved to a user page?
I do agree about Ctrl-A/C/V/X: when I used Konversation for the first time (the IRC client with KDE on Linux) I wondered how to copy some of the messages, and sure enough Ctrl-C worked. About that time I decided that Vim old timers had lost the battle over those keys, and I worked out how to properly map them (I intend fixing 356 Quick yank and paste one day). However, mapping Ctrl-C to y is not helpful. I only use Ctrl-C/V for copy/paste with other applications: within Vim, it is essential to learn the basics like y and p. Also, it is never a good idea to map a key that is easy to press for :q! because sooner or later the key will be pressed accidentally and a lot of work will be lost. JohnBeckett 10:38, May 4, 2012 (UTC)
Advertisement | Your ad here

Photos

Add a Photo
103photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki