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 :)?...
Related
I have reassigned ; to : in Vim. I am constantly saving my code using :w. When I am in the insert mode, after making some changes, due to my muscle memory, I type ;w to save the document, but it adds ;w text in the code. Is it possible to assign ;w in insert mode to exit and save the document. If there is a better method, please let me know.
:inoremap ;w <esc>:w<cr>i save buffer and return to insert mode
:inoremap ;w <esc>:wq<cr> save and close buffer (exit vim if buffer only one).
You can remap : and ; at the OS level, and just get used to it. I started that some months ago and the adjustment was fairly smooth. Now I love it. Not sure what OS you’re on, but I’m sure there’s a solution for any. In X, you’d use xmodmap. In my ~/.xinitrc I have (among many remappings):
# Swap ; and :
xmodmap -e "keycode 47 = colon semicolon"
Use xev to see what exactly your keycodes are.
Do any maps work from hit-enter mode? Reading :help hit-enter, it seems the only way to continue writing commands without redrawing clearing the screen, is to start a command with :.
But there we read:
-> Press ':' or any other Normal mode command character to start that command.
Why doesn't nnoremap ; : apply? (What are "other Normal mode command character[s]"?) I'd like to quickly start a new command without losing the displayed contents from the previous command. I'd also like to be able to use the leader key without losing the displayed contents.
For instance, try ;ls<Ret>, then ; or your <leader> key.
It's not that bad, I can use : after, just wondering if I could get more control in hit-enter-mode.
nnoremap gb :ls<CR>:b<Space>
Is the "canonical" way to do what you want.
I'm trying to map pressing [ctrl] + [semicolon] in insert mode to move to the end of the line and add a semicolon. It's something I find myself doing a lot after installing the surround plugin.
I tried running this command
inoremap <c-;> <esc>A;<esc>
but when I try it, it exits me out of insert mode, and goes into command mode. Trying with another modifier d yields the same result too.
Can semicolon not be mapped with a modifier?
What am I doing wrong?
I didn't read your question carefully, just saw your mapping took you out of the insert mode and the last <esc>... my fault.
You want to map ctrl+; vim cannot capture the keycode. there are some key combination cannot be mapped in vim. ; is one of them, another example like ctrl+=.
so you may want to choose another mapping.
btw, you can try in insert mode press ctrl-v then the keycombination to see if it could be used.
Depending on your terminal it is possible to set up mappings. For example if you use urxvt, in ~/.Xresources add:
URxvt.keysym.C-semicolon: \033[;
And in ~/.vimrc add:
map <Esc>[; <C-Semicolon>
map! <Esc>[; <C-Semicolon>
Then you should be able to map it like this (not tested):
inoremap <c-Semicolon> <Esc>A;<Esc>
I use this to map split window movement like this (this works for me):
noremap <C-Semicolon> <C-w>l
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 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)