Vim Tips Wiki
(I think it's a bad idea)
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
{{TipProposed
  +
|id=0
  +
|previous=0
  +
|next=0
  +
|created=May 3, 2012
  +
|complexity=basic
  +
|author=Baliganikhil
  +
|version=7.0
  +
|subpage=/201205
  +
|category1=
  +
|category2=
  +
}}
 
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.
 
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 keys==
+
==Mapping short-cut keys==
 
Open the ~/.vimrc file if it exists, if not, create a new file. Paste the following remapping code into it.
 
Open the ~/.vimrc file if it exists, if not, create a new file. Paste the following remapping code into it.
 
<pre>
 
<pre>
 
 
set smartindent
 
set smartindent
 
set tabstop=4
 
set tabstop=4
Line 11: Line 22:
   
 
set mouse=a
 
set mouse=a
se nu
+
set nu
   
 
:map <C-a> GVgg
 
:map <C-a> GVgg
Line 59: Line 70:
 
Shift + ( --> Select text between parentheses
 
Shift + ( --> Select text between parentheses
 
</pre>
 
</pre>
 
==References==
 
   
 
==Comments==
 
==Comments==
Line 68: Line 77:
 
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.
 
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.
   
  +
<pre>
 
Ctrl + a --> Increment number
 
Ctrl + a --> Increment number
 
Ctrl + n --> ''this one is OK, a synonym for the j command''
 
Ctrl + n --> ''this one is OK, a synonym for the j command''
Line 89: Line 99:
 
Shift + [ --> [ starts many movement commands, Shift+[ gives you a {.
 
Shift + [ --> [ starts many movement commands, Shift+[ gives you a {.
 
Shift + ( --> ( jumps between sentences, but ( is already shifted, how do you even type this?
 
Shift + ( --> ( jumps between sentences, but ( is already shifted, how do you even type this?
  +
</pre>
  +
 
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. <small>--Preceding [[Vim Tips Wiki:Quick reference|unsigned]] comment added by [[User:Fritzophrenic|Fritzophrenic]] 20:54, May 3, 2012</small>
  +
: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. <small>--Preceding [[Vim Tips Wiki:Quick reference|unsigned]] comment added by [[User:Baliganikhil|Baliganikhil]] 08:46, May 4, 2012</small>
  +
::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 [[VimTip356|356 Quick yank and paste]] one day). However, mapping Ctrl-C to <code>y</code> 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 <code>y</code> and <code>p</code>. Also, it is never a good idea to map a key that is easy to press for <code>:q!</code> because sooner or later the key will be pressed accidentally and a lot of work will be lost. [[User:JohnBeckett|JohnBeckett]] 10:38, May 4, 2012 (UTC)
  +
  +
----
  +
I think that the above reply paired with the original tip is very useful. For example, I never use tags (maybe that's my fault?) but I find it very convenient to have a hotkey for opening a new tab, and vim doesn't provide this. I can rest assured that, at least for the time being, I haven't lost any functionality that I might care about, and now I've learned some new commands about tagging that might help me in the future.
   
  +
This is a nice summary of what "normal hotkeys" do in vim. Very convenient as a reference.
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.
 
[[Category:shortcuts]]
 
[[Category:Map]]
 

Revision as of 01:59, 20 April 2014

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
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 keys

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
set 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

Comments

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)

I think that the above reply paired with the original tip is very useful. For example, I never use tags (maybe that's my fault?) but I find it very convenient to have a hotkey for opening a new tab, and vim doesn't provide this. I can rest assured that, at least for the time being, I haven't lost any functionality that I might care about, and now I've learned some new commands about tagging that might help me in the future.

This is a nice summary of what "normal hotkeys" do in vim. Very convenient as a reference.