Change command line mode key ":" - vim

I'd like to change the way to enter command line mode. In particular, I want to change the : key to ;, since : is just Shift + ; for me. I've tried, so far,
nnoremap ":" ";"
nnoremap "<S-;>" ";"
nnoremap : ;
but they've not worked.

Mappings are thoroughly documented under :help mapping, and introduced in the gentlest way possible in chapter 5 of the user manual: :help 05.4, the reading of which is pretty much mandatory if you ever hope to use Vim efficiently.
Case in point…
The left-hand side of a mapping is what you want to press and the right-hand side is what you want to happen instead, so all your attempts are in the wrong order.
Both sides of a mapping are the exact key you would press so ";" in a mapping is not ;, it is ", then ;, then ". If you wanted ;, you should have used ;. Besides, you are very unlikely to find even one resource on the web suggesting that notation.
You won't extract any value from Vim by trying random things and turning to the internet for help when you are lost. Vim must be learned to be used and there is no way around that.
See :help user-manual.

Looks like you got : and ; the wrong way around. nnoremap ; : does the trick for me.

Related

Remapping ; and : in Vim breaks it

I've just discovered that some people tend to remap their : to ; in Vim (since ; is only used for search, and : is used all the time, not having to press Shift all the time is great).
EDIT (forgot to show what I did):
nnoremap ; :
nnoremap : ;
I tried it, and I love it. However, it does come with a price. It kind of breaks my configs, eg:
map <leader>G mG:Git!
Commands like the one seen above no longer work.
So my question is, to those who remap their semicolons, what is the remedy for this? Should I just remap : and ; on system level via xmodmap instead?
Decision:
Ultimately, I've decided to remap colon and semicolon at system level, for consistency purposes.
nnoremap <leader>G mG:Git!
allows you to use : in its original meaning.
(edit) Obligatory reference in LVHW.

How do I map <q-1> to close file opened in vim?

I'm working with a particularly stubborn keyboard where the SHIFT key simply doesn't seem to stay down when I need it to, especially when I'm typing stuff that includes keys that are further towards the top of the keyboard. Typing '~' somehow almost always types '`', and typing special characters almost always leads to the corresponding numbers being typed eg. when I try to type '#' I get '2','4' for '$' and so on
I primarily use vim these days, and was wondering is it's possible to map to so that when I want to close a file without writing, I can do it without having to worry about whether I have typed '1' or '!'
Help much appreciated
If you are able to enter colon easily then you can add cnoremap q1 q! to your .vimrc so it wouldn't matter if you entered ! or 1 at the end of a command. If colon is also a difficult to enter character then you can create mapping in the normal mode by adding noremap q1 :q!<CR>. Obviously you can create both mappings.
However i'd think of a new keyboard (:

vim keymap with ":" key

How to change functionality of : key to / or comma
What is name of this functional key?
When i press <S-:> I would like to use this:
nmap <S-:> >>
I'm absolutely at a loss on what you are trying to achieve here, but you could just
:nnoremap , :
:nnoremap : ,
I included the reverse mapping, because, you know, : to start command-mode is kind of important to have working in vim.
Just in case you get stuck, ZZ is usually another way to close a window in vim (if the buffer is unmodified, usually)

VIM: Mappable (unused) shortcut letters?

I'm trying to create two mappings which are efficient for myself:
map X ddp
Which I'd use to delete and paste in one go.
map X "_dw
Which would delete a word without yanking into a register.
However I don't want to break any existing, useful shortcuts so I'm wondering what keys I could use - any suggestions? Am I being too uptidy?
vim help has a section :he map-which-keys
1.7 WHAT KEYS TO MAP *map-which-keys*
If you are going to map something, you will need to choose which key(s) to use
for the {lhs}. You will have to avoid keys that are used for Vim commands,
otherwise you would not be able to use those commands anymore. Here are a few
suggestions:
- Function keys <F2>, <F3>, etc.. Also the shifted function keys <S-F1>,
<S-F2>, etc. Note that <F1> is already used for the help command.
- Meta-keys (with the ALT key pressed). |:map-alt-keys|
- Use the '_' or ',' character and then any other character. The "_" and ","
commands do exist in Vim (see |_| and |,|), but you probably never use them.
- Use a key that is a synonym for another command. For example: CTRL-P and
CTRL-N. Use an extra character to allow more mappings.
See the file "index" for keys that are not used and thus can be mapped without
losing any builtin function. You can also use ":help {key}^D" to find out if
a key is used for some command. ({key} is the specific key you want to find
out about, ^D is CTRL-D).
Many Vim plugins use an initial <Leader> to start their key sequences; this is an (otherwise normally) unused key that is configurable by the user.
*<Leader>* *mapleader*
To define a mapping which uses the "mapleader" variable, the special string
"<Leader>" can be used. It is replaced with the string value of "mapleader".
If "mapleader" is not set or empty, a backslash is used instead. Example:
:map <Leader>A oanother line<Esc>
Works like:
:map \A oanother line<Esc>
But after:
:let mapleader = ","
It works like:
:map ,A oanother line<Esc>
Note that the value of "mapleader" is used at the moment the mapping is
defined. Changing "mapleader" after that has no effect for already defined
mappings.
Every single ASCII character, upper and lower case, is used for something in Vim. So you're going to wind up overwriting something--just pick something that you don't use. It may help to use a common idiom for your own extensions. I use a leading comma, for example:
map ,w :w!<CR>
map ,e :e #<CR>
imap ,, <ESC>
(The last is particularly useful for me, since I pretty much never need to write two consecutive commas in insert mode, and it's nice not to have to go all the way to the Esc key.)
Typically I use control + [letter] or alt + [letter] for most mappings and it's safe, but watch out for 'w' since that's needed for window commands. You might also be interested in arpeggio.vim which lets you create mappings to simultaneously pressed groups of keys - it will massively expand the possibilities for your mappings with no danger of over-mapping something. For example, you could map "dp" (pressed simultaneously) to execute "ddp" to delete and paste in one command.
Uhmm, no, don't. When creating your mappings try not to overwrite anything ... not so much because you don't use the command you're overmapping, but because some plugin which you have/or will have maybe using it.
And then you overmap it, and then you have to worry.
Personally, for commands such as you gave as an example, I like Ctrl+some key combinations. There are a lot of free ones in vim, and the letters on the left side near Ctrl make a nice pair then.
Btw, what are you trying to do with those mappings ... I understand the second one (delete word by word), but the first doesn't make sense to me. What is it supposed to do ? Transpose lines ?

How to jump to the next tag in vim help file

I want to learn the vim documentation given in the standard help file. But I am stuck on a navigating issue - I just cannot go to the next tag without having to position the cursor manually. I think you would agree that it is more productive to:
go to the next tag with some
keystroke
press Ctrl-] to read corresponding
topic
press Ctrl-o to return
continue reading initial text
PS. while I was writing this question, I tried some ideas on how to resolve this. I found that searching pipe character with /| is pretty close to what I want. But the tag is surrounded with two pipe '|' characters, so it's still not really optimized to use.
Use the :tn and :tp sequences to navigate between tags.
If you want to look for the next tag on the same help page, try this search:
/|.\{-}|
This means to search for:
The character |
Any characters up to the next |, matching as few as possible (that's what \{-} does).
Another character |
This identifies the tags in the VIM help file.
If you want to browse tags occasionally only, without mapping the search string to keyboard,
/|.*|
also does the trick, which is slightly easier to type in than the suggested
/|.\{-}|
For the case, that the "|" signs for the links in the help file are not visible, you can enable them with
:set conceallevel=0
To establish this setting permanently, please refer to Defining the settings for the vim help file
Well, I don't really see the point. When I want to read everything, I simply use <pagedown> (or <c-f> with some terminals)
" .vim/ftplugin/help/navigate.vim
nnoremap <buffer> <tab> /\*\S\+\*/<cr>zt
?
Or do you mean:
nnoremap <buffer> <tab> /\|\zs\S\{-}\|/<cr><c-]>
?
You could simply remap something like:
nmap ^\ /<Bar><Bslash>zs<Bslash>k<Bslash>+<Bar><CR>
where ^\ is entered as (on my keyboard) Ctrl-V Ctrl-#: choose whatever shortcut you want.
This does a single key search for a | followed by one or more keyword characters and then a |. It puts the cursor on the first keyword character. The and bits are there due to the way map works, see
:help :map-special-chars
As an aside, I imagine that ctrl-t would make more sense than ctrl-o as it's a more direct opposite of ctrl-], but it's up to you. Having said that, ctrl-o will allow you to go back to before the search as well.

Resources