Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sometimes I want to set a starting mark then type a word(usually a long variable name), after finishing the word I may set an ending mark. Then I can get the word stored in my register so that I can paste it without any extra movement, mode switch, etc.

How can I make that? Or there is a better "vim-way" to achieve the similar effect?

Thank you.

share|improve this question

migrated from stackoverflow.com Nov 6 '12 at 10:13

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers

up vote 2 down vote accepted

The following two mappings let you record any chunk of text you are typing in insert mode, not necessarily a single word, and save it into register o.

inoremap <C-K> <C-O>qo
inoremap <C-L> <Esc>q:let @o=@o[:-2]<CR>a

Start recording with CtrlK, end recording with CtrlL. Paste the recorded text in insert mode with CtrlR o.

share|improve this answer
    
This is exactly what I want. Thank you. The vim script seems to be so powerful. I will try to learn that. –  craftsman.don Nov 6 '12 at 15:19
add comment

Use m and y.

  1. Type Ctrl+O (exit insert mode for 1 command)
  2. Type mk to set marker k to your current location
  3. Type your word
  4. Type Ctrl+O
  5. Type y`k to yank from marker k to your current location

http://www.marksanborn.net/software/using-markers-in-vim/

share|improve this answer
1  
This requires dropping out of insert mode though. Using Ctrl-O before steps one and three almost get you there; using a backtick instead of the single quote will do a part-line yank. –  dash-tom-bang Nov 6 '12 at 1:27
    
Whoops, that was a typo (the backtick). I'll update the post with both suggestions –  durron597 Nov 6 '12 at 1:30
add comment

In INSERT mode, you can use Ctrl-N or Ctrl-P to trigger auto-completion.
It's very useful when you're re-typing long words.

share|improve this answer
    
See :help i_ctrl-n for more info. You may need to tune you complete option too; for me I had to strip i out of it because it's too slow with thousands of files all circularly included... –  dash-tom-bang Nov 6 '12 at 1:28
    
I like the supertab plugin. We're so used to pressing tab in bash/zsh to autocomplete, it feels natural in a Vim buffer too. –  d11wtq Nov 6 '12 at 2:01
add comment

With <C-o>, you can temporarily leave insert mode for a single command. You can then issue a yiw command (yank inner word), and have the last word you've been typing in the default (or any other you specify with "x) register.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.