I want to create keybindings like with the keys: shift, ctrl, alt, cmd, but don't know what how to insert them in the configuration file:
like I know that Ctrl is represented as C, I could write: ctrl+p as <C-p>, but how would you write:
alt+p ?
shift+p ?
cmd+p ?
Check the help file for :h shift. Basically it will lead to:
<S-...> shift-key shift <S-
<C-...> control-key control ctrl <C-
<M-...> alt-key or meta-key meta alt <M-
<A-...> same as <M-...> <A-
<D-...> command-key (Macintosh only) <D-
Inside Vim, run: :help key-notations
This will give you a list of all the abbreviations (symbols) of different keys that you will use when mapping.
For instance, after running the above command you will find that alt is notated as: <M-...> so for alt+p you would use: <M-p>
Related
It would be nice if I could press Ctrl + S to save a Vim file like in Windows, rather than :wq. Is it possible to create shortcut keys in Vim?
Yes, it's absolutely possible. You just need to use
<C-yourKey> for map ctrl+yourKey key according to documentation vimdoc.sourceforge.net/htmldoc/intro.html#control
map <Alt>q <Esc>la
This line in my vimrc seems not working after the Esc key. It do exits the insert mode but doesn't enter insert mode again. I also tried
inoremap <Alt>q <Esc>la
map <Alt>q <Esc><Ctrl-A>
map <Alt>q <Esc><Ctrl>A
Basically I want to have something within the normal typing position to have the same effect as key. Say
(i>5[cursor])
->
(i>5)[cursor]
Solution:
I figured out the problem. Its cuz my terminal doesn't properly recognize alt as the alt, instead as a system level alt somehow. see
Alt key shortcuts not working on gnome terminal with Vim
As far as I can see there are two problems:
<Alt> isn't a thing. If you want to map Alt+q, that's <M-q>.
:map doesn't apply to insert mode.
You haven't explained what you're trying to do, so I can't tell you what to do instead.
Now, my config is: http://vim.wikia.com/wiki/Example_vimrc
with additional two lines in it:
source $VIMRUNTIME/mswin.vim
behave mswin
my sample text is:
foo.bar
how can i select foo, then .bar using Ctrl+Shift+Right
and bar, then foo. using Ctrl+Shift+Left ?
Ctrl+Lelf and Ctrl+Right stop on dot char, like traditional editor, but when i use Ctrl+Shift+Arrows - it stops only on whitespaces.
vim version: 7.4
os: ubuntu 14.04
The Select-mode (which will be enabled by :behave mswin) only "simulates" some behaviors of MS-Windows like editors. Just these movements cursor keys, <End>, <Home>, <PageUp> and <PageDown> with the shift key are expanding/collapsing current selection.
From :help Select-mode:
Commands in Select mode:
- Printable characters, <NL> and <CR> cause the selection to be deleted, and
Vim enters Insert mode. The typed character is inserted.
- Non-printable movement commands, with the Shift key pressed, extend the
selection. 'keymodel' must include "startsel".
- Non-printable movement commands, with the Shift key NOT pressed, stop Select
mode. 'keymodel' must include "stopsel".
- ESC stops Select mode.
- CTRL-O switches to Visual mode for the duration of one command. *v_CTRL-O*
- CTRL-G switches to Visual mode.
From :help keymodel:
... Using a shifted special key starts selection ...
... Special keys in this context are the cursor keys, <End>, <Home>,
<PageUp> and <PageDown>. ...
Try to read about it: :help behave, :help Select-mode and :help keymodel.
But, I strongly recommend you to learn about the "real" vim movements and commands and disable :behave mswin. It is actually way more powerful.
In your case you could simply press veE to select first foo then foo.bar. Or if your intention is to select the whole foo.bar at once even simpler, press vW.
I'm trying to create a keyboard shortcut to save my file in vim, so I would like to map control alt S to ESC, :, w, ENTER, a. Is there any easy way to do that?
Look at this :
http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files
Or this:
In vim how to map "save" to ctrl-s
Or this:
http://sigttou.com/vim-ctrl-s
I am going through this document and this is what I gathered.
<Esc> Escape key
<C-G> CTRL-G
<Up> cursor up key
<C-LeftMouse> Control- left mouse click
<S-F11> Shifted function key 11
<M-a> Meta- a ('a' with bit 8 set)
<M-A> Meta- A ('A' with bit 8 set)
<t_kd> "kd" termcap entry (cursor down key)
However I don't see how I can map Command/Apple key here. I am using plugin mentioned here. It works great. I open a tab and then I hit Command-R and I get the list of files. I could not find where the mapping is done between Command-R and the function. I am using vim settings as mentioned here
the modifier "D" stands for the "Command" key
Or T- in gvim, but it doesn't work with all keys, e. g. not with letters. T-CR, T-F5 or T-DELETE are OK though. Availability could be checked with ^K or ^V