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
Related
I'm looking for a solution to swap the Ctrl and Alt keys under FreeDOS OS. Does anybody know anything about this? Maybe there is a program similar to 'loadmap' that is used in GNU OS.
I have not tried that, but the command to use to make your own keyboard mappings file is KC and the command to load a keyboard mapping (typically called from AUTOEXEC.BAT) is KEYB.
If it is only for a limited number of shortcuts you want to modify you can also have a look at XKEYB and KEYMAN that together will allow you to make your own keyboard macros that can include the use of CTRL and ALT keys.
I have just started learning VIM using gvim. When I am in the insert mode, and after I have copied stuff ,I usually use CTRL+R + Shift * key combination to paste the stuff in. I would like to map those keys to CTRL+V .
Can you please let me know what I should be doing in my vimrc to achieve my desired goal?
I am on a Windows OS.
Thanks
The key combination
:map < c-v > P
should set the paste shortcut to Ctrl+V.
There is a tutorial for creating VIM keymaps here.
You can also try the 3rd chapter of the free book "Learn Vimscript the Hard Way". It gives a very good example of mapping "dd" to "-". I would actually visit this link first and maybe afterwards take the tutorial above.
I have 0 Experience with vim on windows. But you can try inoremap <c-v> <c-r>*
And on my linux box, the insert mode Ctrl-v is very important, it can let me input next non-digit literally. It is very handy to input special keys. So if it is same to you, consider to use other keys.
I want to use the following code to quickly go from insert mode -> command mode. The problem is it just doesnt seem to be registering my keys. I've tried with control (nothing happens) and i've also tried with command (D) and it just says spellcheck not activated.
" Quick command mode from insert
imap <C-;> <esc>:
How do i go about doing this? is there an easier vim way that I'm not aware of?
Certain Ctrl chords can't be mapped, including Ctrl-;.
This is mentioned in this FAQ, see also the Vim FAQ:
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
First make sure that the key is passed to Vim. In insert mode, press Ctrl-V
followed by the desired key. You should see the keycode corresponding to
the key. If you do see the keycode, then you can create a mapping for the
key using the following command:
:map <C-V><xxx> <your_command_to_be_mapped>
For more information, read
:help map-keys-fails
:help :map-special-keys
:help key-codes
The tip about trying to print the character using Ctrl-V is good to remember if you run into this problem with another key combo.
I tried it, however it doesn't seem to work, also as pb2q said, it just can't be mapped. But there are other ways to escape using a Ctrl key combination.
For example, you can also escape insert mode with the following key presses:
Ctrl-[
Ctrl-c
On OS X (I think Lion and above), you are able to map alt - ; using this method, alt - ; on OS X outputs ç, which you can map.
But at a MacBook, I prefer to use PCKeyboardHack to map caps lock to esc. Or at Windows, use a tool I've created myself for that or even Ctrl2Cap.
EDIT
oh sorry, I thought you wanted to switch to normal mode, that's why I talked about caps lock mappings.
I have recently switched from using MacVim to just using Vim on the command line. One feature I miss is being able to save a file with ⌘S rather than having to go back into normal mode and then :wq
I am using Vim inside iTerm2. Is there any way to get ⌘S to save a file both in insert and normal mode?
You can use iTerm2 to map Cmd-S to some other combination that the shell and Vim will recognize (e.g. Ctrl+S) , then you can simply map that command via a .vimrc file as Andrew pointed out.
In summary:
edit iTerm2 Keys with a new entry that maps Cmd-S to Ctrl+S.
Add commands for mapping Ctrl+S to vimrc file (like Andrew describes) or like this site.
Here is an even simpler way to do it: using iTerm2's "Send Text". Basically you can map Cmd-S to send a text to the current vim session :w\n.
Well, I'm not sure that command-line Vim can register the ⌘ key, and I'm not on my Mac to confirm, but you can map ⌘S in .vimrc like this.
inoremap <D-s> <ESC>:w<CR>i "insertmode
nnoremap <D-s> :w<CR> "normalmode
Again, this will only work if command-line vim can recognize the ⌘key.
It is not possible to map to ⌘ in the console version of Vim. If you want to be able to use ⌘ in a mapping you'll need to switch back to MacVim.
When I'm opening a new file in Vim and I use tab completion, it completes the whole file name instead of doing the partial match like Bash does. Is there an option to make this file name tab completion work more like Bash?
I personally use
set wildmode=longest,list,full
set wildmenu
When you type the first tab hit, it will complete as much as possible. The second tab hit will provide a list. The third and subsequent tabs will cycle through completion options so you can complete the file without further keys.
Bash-like would be just
set wildmode=longest,list
but the full is very handy.
The closest behavior to Bash's completion should be
set wildmode=longest:full,full
With a few character typed, pressing tab once will give all the matches available in wildmenu. This is different to the answer by Michael which opens a quickfix-like window beneath the command-line.
Then you can keep typing the rest of the characters or press tab again to auto-complete with first match and circle around it.
Apart from the suggested wildmode/wildmenu, Vim also offers the option to show all possible completions by using Ctrl + D. This might be helpful for some users that stumble across this question when searching for different autocompletion options in Vim like I did.
If you don't want to set the wildmenu, you can always press Ctrl + L when you want to open a file. Ctrl + L will complete the filename like Bash completion.
I'm assuming that you are using autocomplete in Vim via Ctrl + N to search through the current buffer. When you use this command, you get a list of solutions; simply repeat the command to go to the next item in the list. The same is true for all autocomplete commands. While they fill in the entire word, you can continue to move through the list until you arrive at the one you wish to use.
This may be a more useful command: Ctrl + P. The only difference is that Ctrl + P searches backwards in the buffer while Ctrl + N searches forwards... Realistically, they will both provide a list with the same elements, and they may just appear in a different order.
set wildmode=longest:full gives you a Bash-like completion with:
suggestions in a single line
Tab completing only what is certain
Right/Ctrl-n | Left/Ctrl-p to select suggestions.
From the help:
If you prefer the <Left> and <Right> keys to move the cursor instead
of selecting a different match, use this:
:cnoremap <Left> <Space><BS><Left>
:cnoremap <Right> <Space><BS><Right>
Try using :set wildmenu. Apart from that, I'm not sure what exactly you're trying.
Oh, yeah, and maybe try this link: link