3

I have following instruction in my .vimrc:

map t :!../tt <C-R><C-W> <CR><CR>

It works quite fine: vim gets word from file and runs ../t word. But one annoying thing is when the command is run vim returns to shell for a while and then return to file. I don't need to see command output so is it possible to get around this annoying flash?

2
  • What does $ ../t word do? What's the output? Do you want to put it in the buffer? Commented Feb 20, 2012 at 16:14
  • 5
    Why do you remap t? This is a useful movement command ... Commented Feb 20, 2012 at 16:14

2 Answers 2

2

You can try either

nnoremap <silent> t :<C-u>silent !../tt <C-r>=shellescape(expand('<cword>'), 1)<CR><CR><C-l>

or

nnoremap <silent> t :<C-u>call system('../tt '.shellescape(expand('<cword>')))<CR>

or even

nnoremap <expr> <silent> t system('../tt '.shellescape(expand('<cword>')))[-1]

. Note some things:

  1. Don’t use map (without n and nore) unless you have a specific reason. I believe you don’t need this mapping for visual and operator-pending modes (leading n restricts mapping to normal mode only) and you also should not want this mapping to be remappable.
  2. Use <C-u> to discard count you can occasionally type unless you do know you need it (third version uses two hacks that turn mapping to no-op with a side-effect and does not need <C-u>).
  3. Never forget to escape shell arguments.
  4. Version with silent ! (do not forget space after silent, this is why @David Pope’s answer does not work) has <C-l> at the end. This is because using ! will always provide access to your terminal and thus redraw is needed after command has run.
  5. Versions with system() won’t work if you add an argument containing newline, it is a documented bug. If you don’t want to do so (expand('<cword>') won’t ever add newline) it is absolutely safe.
  6. t is a very useful motion. It is better to learn to use it then remap it to something. I suggest ,t as a lhs.
Sign up to request clarification or add additional context in comments.

Comments

0

I believe this should work.

map <silent> t :silent!../tt <C-R><C-W> <CR><CR>

But I don't have your tt app so I couldn't test for stderr vs. stdout vs. etc.; I have no idea if those matter in vim.

1 Comment

No it doesn't work. tt is simple bash script. This is its source code:#!/bin/bash FILE_OF_EX=~/tmp/to_trans echo $1 > $FILE_OF_EX

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.