I have the following filter command:
vnoremap <silent> <leader>C :w! !pbcopy<CR><CR>
Yet, when I run it, there is a short 'hiccup', as shown in the video here: https://gyazo.com/ca78c5adfcf4b3b7a6a9f885acb5c8bc. Why does this occur? It seems to be inputing the command 'invisibly' or something (such as the extra command line that often occurs after an input command or echom).
if you run the command "by hand" you'll see that after the first <CR> (when you press enter the first time, when the command gets executed) vim enlarges the status bar displaying the output of the command and a message that says:
Press ENTER or type command to continue
then you press enter again (the second <CR> in the remap) and the status bar shrinks again. I think the "hiccup" is due to this status bar fast "enlarge and shrink" which causes a screen redraw and is also the reason why you need a double <CR> in the remap.
Related
I've been a vim user for a while now and I know how to move around the files, but is there anyway to do so on the editor command line itself (is there a name for that?).
e.g. I typed :vimgerp /sometext/ files/*.js and I realized I spelled :vimgrep incorrectly and I want to just jump to the beginning of that line and fix it. Any other sort of small tips here (jump between words -- neither w,e nor alt+left/right seem to work) also appreciated.
http://vimdoc.sourceforge.net/htmldoc/usr_20.html
<Left> one character left
<Right> one character right
<S-Left> or <C-Left> one word left
<S-Right> or <C-Right> one word right
CTRL-B or <Home> to begin of command line
CTRL-E or <End> to end of command line
The easiest method would be to use CTRL-F. This opens your command in the command-line window where you can edit your misspelled command like any other plain text.
from vimhelp
OPEN c_CTRL-F q: q/ q?
There are two ways to open the command-line window:
From Command-line mode, use the key specified with the 'cedit' option. The default is CTRL-F when 'compatible' is not set.
From Normal mode, use the "q:", "q/" or "q?" command. This starts editing an Ex command-line ("q:") or search string ("q/" or
"q?"). Note that this is not possible while recording is in progress
(the "q" stops recording then).
It's not the fastest and therefore probably only worth it for long commands, but you could just hit enter on the incorrect command as is, undo any incorrect changes if necessary, then open up your command history with q:, where you can edit it as you like. Enter then runs the command if you have your cursor over it in the command history buffer.
Also, shift+arrow left/right jumps between words in command mode, and you can use home/end to go to the beginning and end.
is there a way to clear highlighted text after running a substitute command in vim? For example, when I run:
:'<,'>s/<\([^>].*\)>/<!--\1-->/
to comment out the current line in an html file, after the command runs all of the text in the doc is highlighted and I have to hit the spacebar to clear the selection.
Is there anything I can add immediately after or as part of the substitute command so any selection is cleared automatically after the command runs so I don't have to hit the spacebar to clear it?
Well, <Space> doesn't clear anything by default so you have it must have it mapped to something like :nohl<CR>. Therefore, you need to execute the command that you mapped to <Space> after your substitution.
This is done by "chaining" Ex commands with |:
:'<,'>s/<\([^>].*\)>/<!--\1-->/|nohl
The way I've been kicking out to the terminal (to see the output of some command, etc) is to run :!<CR>, however it always prints out Press ENTER or type command to continue and bumps the output up one line, eventually causing some things to scroll off the screen.
Is there a better way of showing the terminal from vim? Or is there a way to make it so :!<CR> does not print that text message?
Use :susp or <C-z>. fg in shell to restore vim.
Normally scrollback is available through <C-PageUp> though thus avoiding one line scroll at all costs is not necessary.
If you want to see the results of one command with arguments (e.g. tail, ls, locate, etc), you can also use:
command! -nargs=* -complete=shellcmd ShellRead new | setlocal buftype=nofile bufhidden=hide noswapfile | read !<args>
cabbrev Sh ShellRead
This shows results of a shell cmd into a 'scratch' window in the session.
Makes it easier for yanking/saving/using if needed. There is no extra prompting to press Enter.
e.g. :ShellRead locate blast
will show the results in a new split window, if it is successful, else it shows error message
Of course it is an interactive shell process you want, then this won't work. ;)
I'm developing a Vim plugin That needs to run a shell command(targeted for running compilers and build systems) and capture it's output. I also want to display the command's stdout and stderr as it runs, so I'm using Ruby for running the command(though I'm still displaying with Vim's :echo command, so I can set the highlight for stderr)
Anyways, I want to allow the user to cancel the command in the middle. Canceling a program is traditionally done with Ctrl+C, and Vim's allows the user to use Ctrl+C to cancel the current running vimscript by throwing Vim:Interrupt. I want to use Vim's :sleep command to allow the user to press Ctrl+C if they want to cancel the command they are running, catch Vim:Interrupt, and proceed accordingly.
My problem is that pressing Ctrl+C in Vim while not in insert mode causes Vim to display Type :quit<Enter> to exit Vim - and to erase whatever messages were echoed before. This is a problem for me, because I want to keep whatever output the command put in stdout and stderr before the user canceled it displayed(and maybe add a message that the command was canceled).
Is there any way to temporarily disable this message and keep whatever was echoed before the user pressed Ctrl+C?
You can prepend the left hand side of your mappings with <silent> to hide what they would normally output on the command line.
In this case, the following mapping should work (it seems to, here):
nnoremap <C-c> <silent> <C-c>
Say, I just ran this command in Vim:
:nmap <CR> <C-]>
And now I want to copy this line and put it into my .vimrc.
How can I select and copy the whole line in command-line mode?
The fastest way is to run the command, switch to the destination
buffer (with .vimrc loaded, in this case) and paste the whole
command from the : register by typing
":p
in Normal mode.
If the command is further back in time, one can first recall it from
history (e.g., by typing the first few letters and pressing the up
arrow key ↑), rerun it, and then use the above method.
When these shortcuts are unhandy, one can resort to the general
approach of using the command-line window (see :help cmdwin).
To open it, either type q: in Normal mode, or press the key
combination set by the cedit option (Ctrl+F,
by default) in Command-line mode.
You can type Ctrl-F while in command mode to open up a special window with all previous commands. Then you can scroll to the desired line, hit yy to copy that line, then press Ctrl-C to return to command mode, and then ESC to return to normal mode. From there you can paste.
See :help cmdwin for more information on the command window.