Remapping ; and : in Vim breaks it - vim

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.

Related

Change command line mode key ":"

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.

Activate command line mode with custom key

I wonder if it is possible to change the colon key to activate the command line mode? I don't know if this will be useful or not but I think it is worth trying. Because typing colon key in my keyboard requires the movement of two little fingers in both hands.
You can indeed.
I have this in my .vimrc; it swaps : with ;, which means that I can activate command line mode with a single keystroke:
nnoremap ; :
nnoremap : ;
You could of course substitute any key you like (and that you don’t mind remapping — if it’s already assigned to a command, ideally it’s not to a command that you use very often) for ;.

Advanced Usage of Ranges with Vim Keymappings

I have a mapping in my vimrc that downwardly comments out regions of c code:
nmap comc :normal! I//<ESC>
Since the 'normal' ex command implicitly converts input such as "Ncomc" to ".,.+N-1 comc", I can range comments downwardly without many keystrokes and without leaving normal mode. This is, however, a very limited subset of what vim ranges can do. If I'm willing to be verbose, I can achieve upward ranging comments like so:
.,.-5 normal comc
While editing text, I would much prefer to type something like "-6comc" or make a mapping of "Comc" that uses upward ranges. I'm haven't been able to do so successfully.
Similarly, range operations support commenting until a search pattern is reached, e.g :
.,/int main/ comc
I would, however, like to do so without all that typing.
The behavior you requested is normally done with :h map-operator mapping. With this commenting 3 lines down will turn into comc2j though, but 3 lines up is now just as easy: comc2k.
You can also use visual mode without changing your mapping at all: V2kcomc. You will have to add xnoremap with the identical lhs and rhs because nnoremap works only for normal mode. (And do not use nmap.)
Third option is mapping - to something that moves {count} lines up and puts count back:
nnoremap <expr> - (v:count ? ":\<C-u>\n" . (v:count-1) . 'k' . v:count : '')
. This assumes you are writing 6-comc, not -6comc.
// By the way, I would suggest The NERD Commenter if it comes to the plugin.
While it's commendable to go as far as possible without any plugins, sometimes they're just the best option. What will you do when you start working in a language that has comments with # or (*...*)? Add new mappings for these comment characters?
I recommend commentary.vim which does filetype-aware commenting.
The default commenting operator in commentary.vim is gc. You can combine it with motions, and use it in Visual mode too.
Your use cases:
Comment downwards N lines (say, 3): :.,.+3normal gcc, or gc3j or 4gcc.
Comment upwards 5 lines: :.,.-5normal gcc, or simply gc5k.
Comment until int main: :.,/int main/-1normal gcc, or simply gc/int main followed by Enter.

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)

Disable the ':' character in Vim

In my ~/.vimrc I have mapped ; to : so I don't have to press shift every time I want to enter a command and so I avoid typos like :W. I have mapped it using nnoremap ; :. My muscle memory is so strong however, is that I find myself frequently pressing : when I dont need to and I still get typos like :W.
How can I disable the : character completely and just use ; in normal mode?
nnoremap ; :
nnoremap : <nop>
would be considered fairly harmless.
I don't need to point out that using this kind of setup will drive anyone trying to use your box nuts, and will render yourself crippled when at a random other UNIX console :)?...

Resources