Vim's "hit-enter" mode. Using ; of `:map ; :` without clearing displayed contents. - vim

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.

Related

Vim exit Insert mode with some key press

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.

Error in my Vim mapping

I would like to map Control + F3 with map <c-f3> :w <CR> :make <CR><CR><CR>. When I leave out the Control this works fine. With control from normal command mode insert mode is entered and 1;5R is inserted into the buffer.
When I use a simpler command e.g. map <c-f3> dd this works as expected.
With Shift instead of control I get a similar behavior (1;2R inserted into buffer). What can I do get my mapping right?
Edit: I want the command to be executed from normal command mode. However, vim enters insert mode, which is not desired.
The combination of function keys and modifiers is problematic in terminal Vim; whether this works depends on the terminal.
Check your $TERM value; a wrong one can cause these problems. Also, your termcap database must be correct and complete.
Try out another terminal (gnome-terminal vs. konsole vs. xterm); it may work there.
Alternatively, use GVIM; it doesn't have these problems (but still can't map some other combinations).
If you use varying terminals, it's best to avoid these key combinations, and just use plain <F1..12>, and <Leader>... for the rest.
map defines keystrokes for normal, visual and operation modes. For insert mode you should use imap.
Something like this I believe: imap <c-f3> <esc>:w :make <cr><cr><cr>. <ESC> puts the Vim to normal mode.
:he :key-mapping for explaining.

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 ;.

Vim "show my last command" command?

Is there a command which shows what was the last command in normal mode?
Suppose I accidently hit random key and got some unexpected result.
Sure I can undo it, but could I reveal what key was pressed and how it was interpreted?
Hit the colon (:) and then use the up arrow to start going back through previous commands. You can use the up/down arrows too to move around the list.
q: will show you command history in Vim.
q/ will show you history of searches.
And must importantly, :q will quit the mode.
The text from the last command is stored in the . register. You can see all registers by :display. Unfortunately it doesn't say what the started the normal command.
To see commands from : (command mode) you can use :hist or q: which is limited to the last 20 (by default).
Another ability is to save the undo buffer :wundo undo.bin -- but the undo buffer is binary.
But none of these actually answer your question. I'm curious if it can be done.
Entering colon : then ctrl+p shows your previous command, i.e., moving backward through your vim command history. ctrl+n moves forward.
This is very convenient if you're used to using the command line and prefer not to change your keyboard hand positioning to use arrow keys.
It is difficult to know it. You can play with the variables:
v:operator
v:count (and v:prevcount)
v:register
But you cannot fully get the last normal mode command issued.
However if you want to systematically record everything you type while in Vim, you can launch vim -W ~/.vim-last-scriptout (a Windows version: vim -W "%HOMEPATH%\Vim\.last-scriptout) You can alias it in your shell on a UNIX machine. Every single key, or control-key, will be recorded into that file. Note that if you happen to use gvim or vim -g (the GUI) you might encounter this bug.
If you want to replay this file you can use :source! (with the exclamation mark) or the -s option from the command line.
On Windows I have set gvimportable.exe -W gvim_directory\last_scriptout as my default editor in my Commander program (FreeCommander). This way I can always remember what I have typed to do something and repeat a sequence of commands on another file. Of course I have another shortcut for opening Vim and playing the scriptout.
Note that the file might be written only when Vim exits, so you have to lose your session to know what you've done.

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