|
I've been learning Vim for a while, and one situation has been coming up a lot for me:
1) I'm scrolling through a sourcefile, and see an interesting word I'd like to edit or yank. 2) I look left at the line number of the word, and type [line number]G 3) I keep pressing w/W/b/B until I reach the word, (except if the word happens to be the first or last word of the line, or located near a unique symbol) However, this feels inefficient (especially step 2), and I'm hoping to find a better solution. Some things I think might be possible, but have no experience with: - Use H/M/L to move roughly to the line, then 0/gm/$ to move roughly to the column, then using small motions to get to the final spot. - Learn to guess [number]j/h/k/l way better (perhaps with relative line numbers) to do something like "7j33l". - Use / and type characters until it matches, then press enter. - Use the easy motion plugin. Please comment on the above or share your method. :) -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
On Tuesday, July 31, 2012 1:58:55 PM UTC-5, Daan wrote:
> I've been learning Vim for a while, and one situation has been coming up a lot for me: > > 1) I'm scrolling through a sourcefile, and see an interesting word I'd like to edit or yank. > 2) I look left at the line number of the word, and type [line number]G > 3) I keep pressing w/W/b/B until I reach the word, (except if the word happens to be the first or last word of the line, or located near a unique symbol) > > However, this feels inefficient (especially step 2), and I'm hoping to find a better solution. > > Some things I think might be possible, but have no experience with: > - Use H/M/L to move roughly to the line, then 0/gm/$ to move roughly to the column, then using small motions to get to the final spot. > - Learn to guess [number]j/h/k/l way better (perhaps with relative line numbers) to do something like "7j33l". > - Use / and type characters until it matches, then press enter. > - Use the easy motion plugin. > > Please comment on the above or share your method. :) I almost always have relative line numbering turned on, which as you mentions allows me to very quickly do 7j or 12k or whatever to get to the right line. Then I will usually use f, F, t, or T, or a / search, or w/W/b/B to get to the correct column, possibly with an initial _ or g_ to position the cursor at the beginning or end of the line (or ^ and $, but I use Dvorak making _ and g_ much faster to reach). Using f/F/t/T is nice because I can follow it up with ; or , if I didn't supply the right count, and I have a mapping which will highlight all the matching characters within the line so I can quickly get the count right on my second try if needed. I keep forgetting about gm, I should start using that one more. -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
On Tuesday, July 31, 2012 9:41:09 PM UTC+2, Ben Fritz wrote:
> > Then I will usually use f, F, t, or T, or a / search, or w/W/b/B to get to the correct column, possibly with an initial _ or g_ to position the cursor at the beginning or end of the line (or ^ and $, but I use Dvorak making _ and g_ much faster to reach). > > Using f/F/t/T is nice because I can follow it up with ; or , if I didn't supply the right count, and I have a mapping which will highlight all the matching characters within the line so I can quickly get the count right on my second try if needed. Would you care to share this mapping? It seems very interesting. > I keep forgetting about gm, I should start using that one more. First time I come across 'gm'. Very useful indeed! Thx, Jeroen -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
On Tue, Jul 31, 2012 at 01:20:14PM -0700, jeroen wrote:
> On Tuesday, July 31, 2012 9:41:09 PM UTC+2, Ben Fritz wrote: > > > > Then I will usually use f, F, t, or T, or a / search, or w/W/b/B to get to the correct column, possibly with an initial _ or g_ to position the cursor at the beginning or end of the line (or ^ and $, but I use Dvorak making _ and g_ much faster to reach). > > > > Using f/F/t/T is nice because I can follow it up with ; or , if I didn't supply the right count, and I have a mapping which will highlight all the matching characters within the line so I can quickly get the count right on my second try if needed. > Would you care to share this mapping? It seems very interesting. it isn't Ben's exclusive mapping, it's everybody's -- see: :h f f is the linewise search command -- it is famous for the fact that it searches current line only (and to the right only). -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
On Jul 31, 2012, at 3:38 PM, sc <[hidden email]> wrote: > On Tue, Jul 31, 2012 at 01:20:14PM -0700, jeroen wrote: >> On Tuesday, July 31, 2012 9:41:09 PM UTC+2, Ben Fritz wrote: >>> >>> Then I will usually use f, F, t, or T, or a / search, or w/W/b/B to get to the correct column, possibly with an initial _ or g_ to position the cursor at the beginning or end of the line (or ^ and $, but I use Dvorak making _ and g_ much faster to reach). >>> >>> Using f/F/t/T is nice because I can follow it up with ; or , if I didn't supply the right count, and I have a mapping which will highlight all the matching characters within the line so I can quickly get the count right on my second try if needed. > >> Would you care to share this mapping? It seems very interesting. > > it isn't Ben's exclusive mapping, it's everybody's -- see: > > :h f > > f is the linewise search command -- it is famous for the fact that it > searches current line only (and to the right only). > > -- > You received this message from the "vim_use" maillist. > Do not top-post! Type your reply below the text you are replying to. > For more information, visit http://www.vim.org/maillist.php -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
In reply to this post by Daan
On Tue, Jul 31, 2012 at 02:58:55PM EDT, Daan wrote:
> I've been learning Vim for a while, and one situation has been coming > up a lot for me: > > 1) I'm scrolling through a sourcefile, and see an interesting word I'd > like to edit or yank. 2) I look left at the line number of the word, > and type [line number]G 3) I keep pressing w/W/b/B until I reach the > word, (except if the word happens to be the first or last word of the > line, or located near a unique symbol) > > However, this feels inefficient (especially step 2), and I'm hoping to > find a better solution. > > Some things I think might be possible, but have no experience with: > - Use H/M/L to move roughly to the line, then 0/gm/$ to move roughly > to the column, then using small motions to get to the final spot. > - Learn to guess [number]j/h/k/l way better (perhaps with relative > line numbers) to do something like "7j33l". - Use / and type > characters until it matches, then press enter. - Use the easy motion > plugin. > > Please comment on the above¹ or share your method. :) I tend to use ‘/’ or ‘?’ extensively for cursor navigation beyond the current line and possibly a couple of lines just before or just after it.. if I use the same trick all the time, there's hope yet I might get good at it. ;-) What I do when I aim for the word ‘world’ in ‘hello world’, that I may have spotted somewhere on my screen, is to search not for ‘hello’ or ‘world’ but rather ‘lo wo’, which appears to be less likely to match as often as either ‘hello’ or ‘world’..² I have no formal explanation... but I noticed that it almost invariably weeds out a significant number of false positives.. at least in the context of the stuff I usually edit. I haven't bothered to look into it but a possible improvement might be to use a mapping and/or a function that would cause the cursor to move three columns to the right so it ends up right on top of the second word automatically. I'd rather be flexible.. Otherwise, when the target word starts in column 1 or is at the end of the line.. or follows a <Tab>, I tend to prefer using a simple regex with the usual anchors (^/$) or \t. I prefer sticking to these two related techniques for ‘long jumps’ rather than mixing in others - e.g. line numbers and such. All in all I think it makes me more efficient.. CJ ¹ Well, effectively moving moving the cursor is not trivial: it's half of the job of editing..! ² Note, that I touch-type and am therefore fairly quick at typing any sequence of letters that happens to be under my eyes without the least overhead.. And also, as a human.. I have kinda gotten used to spotting sequences of two letters+space(s)+two letters that are fairly unlikely to occur in other spots.. I don't always do it ‘by the book’.. caveat emptor.. -- Oh My God!!! Larry is back! -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
In reply to this post by scott-268
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256 On 07/31/2012 10:38 PM, sc wrote: > On Tue, Jul 31, 2012 at 01:20:14PM -0700, jeroen wrote: >> On Tuesday, July 31, 2012 9:41:09 PM UTC+2, Ben Fritz wrote: >>> >>> Then I will usually use f, F, t, or T, or a / search, or >>> w/W/b/B to get to the correct column, possibly with an initial >>> _ or g_ to position the cursor at the beginning or end of the >>> line (or ^ and $, but I use Dvorak making _ and g_ much faster >>> to reach). >>> >>> Using f/F/t/T is nice because I can follow it up with ; or , if >>> I didn't supply the right count, and I have a mapping which >>> will highlight all the matching characters within the line so I >>> can quickly get the count right on my second try if needed. > >> Would you care to share this mapping? It seems very interesting. > > it isn't Ben's exclusive mapping, it's everybody's -- see: > > :h f > > f is the linewise search command -- it is famous for the fact that > it searches current line only (and to the right only). > I know about the f/F/t/T commands. What I was referring to was the mapping to highlight all the matching characters: "...and I have a mapping which will highlight all the matching characters within the line..." Jeroen -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAEBCAAGBQJQGMv7AAoJEBrqc/v4ufiMQP4P/j2uX7cWwoGHkC3JDjGfESsz S2YuMOzoFKPjxOECTkmYkQVrfClAD+9EtdsTPsLfah2rA2zi5nFm4nUPSkOy4TOy YDR6gFBTRhzJxPPiRP/ZwvVzLGA17MNOHhPnTc6jhyc9JKtowppDNh2XAdf0UqV1 7L3asiv+HXAiSishHm/N7+lpFz/XuKPey1CweEkp+lClmiSEqjDjnKwU4j6PE1jM 3mMYJOhvO2aBVfy0pB//Nh//+YwMRzXYjpxflkntC3k2wt+Itw2umS9vdoz9a67I +x3I/EZgWNOLL4Z0aQgYFZDTQFBkikplYgxYETzP5ODrf8eyc9PhAD7//Dw1rBeL wmlCKAXMGjuU7MNHaQW87epYCLhJvix5chX03eLaAvMjWOpNSvDGPBsENefP7oZ/ QnuAz57msmb0bxXJeN485VQ8STjN8VoLVUFpTSsFx1RaYNNK/Rj23UhFrDZ3rF/f XJiizlos7vpHDz3/I18Q89UeaskAJFvYAx9Yp7CVTAEDvj8LdKVTiQufB8pMA9BH mm5ivK9inhcysc3y/0K4r1iae8HDYSF402vZHlrZ7LjBgWgH7iB5ECJLdbK0tPqe eQON4C5gbR3EzTNoKErWLYkRCn2IziCHAFbY0XTdzVzbYQAvY1dZIAPbQWkyTs1n qmkDrqU+EEAp2KhSJA+u =nCCI -----END PGP SIGNATURE----- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
In reply to this post by Daan
On 31/07/12 20:58, Daan wrote:
> I've been learning Vim for a while, and one situation has been coming up a lot for me: > > 1) I'm scrolling through a sourcefile, and see an interesting word I'd like to edit or yank. > 2) I look left at the line number of the word, and type [line number]G > 3) I keep pressing w/W/b/B until I reach the word, (except if the word happens to be the first or last word of the line, or located near a unique symbol) > > However, this feels inefficient (especially step 2), and I'm hoping to find a better solution. > > Some things I think might be possible, but have no experience with: > - Use H/M/L to move roughly to the line, then 0/gm/$ to move roughly to the column, then using small motions to get to the final spot. > - Learn to guess [number]j/h/k/l way better (perhaps with relative line numbers) to do something like "7j33l". > - Use / and type characters until it matches, then press enter. > - Use the easy motion plugin. > > Please comment on the above or share your method. :) > IMHO there isn't just one best way to go to an arbitrary location; there are several, for different people and different circumstances. One possible way is to click where you want to go. This doesn't work if you're running in Console mode in a terminal which doesn't receive mouse clicks or if Vim doesn't get this particular terminal's mouse clicks (for instance, in the Linux text console if gpm isn't installed or if running a Vim compiled without the +mouse_gpm feature). It also doesn't work, of course, if the place you want to go isn't already onscreen. Another possible way is to search, either forward with /, backward with ?, or, on the current line, right with f or t or left with F or T (both / and ? will usually wrap around from the end to the beginning of the file or vice-versa; this depends on the 'wrapscan' option). If you know on which line number you want to go (either because you have 'number' on, or because you see the same file with line numbers in some other program such as a browser), there are several ways to go to that line: for instance, to go to line 1234 you could type either 1234G or :1234<Enter> where <Enter> is one keypress, not seven. G with no count goes to the end of the file, gg goes to its top. You can also open a new editfile at a given line number, for instance :e +456 foobar.c to edit the file foobar.c, with the cursor at line 456. Or if you know how many lines to go up or down from where you are now, you can use a count with j or k (for "file" lines), or gj or gk (for "screen" lines: if 'wrap' is set you may have one file line wrapped over several screen lines). Similarly with h or l for columns. And I forgot to mention the | command: for instance 79| goes to column 79 (if there are that many on the current line). I also forgot to mention that, for instance, 75% will put you at that percentage point of the file (counting by lines). See: :help <LeftMouse> :help / :help ? :help f :help t :help F :help T :help G :help gg :help +cmd :help j :help k :help gj :help gk :help h :help l :help | :help N% There is no helptag for :1234 but it is mentioned as :[range] a few paragraphs after the help for G Best regards, Tony. -- CUSTOMER: You're not fooling anyone y'know. Look, isn't there something you can do? DEAD PERSON: I feel happy... I feel happy. [whop] CUSTOMER: Ah, thanks very much. MORTICIAN: Not at all. See you on Thursday. CUSTOMER: Right. The Quest for the Holy Grail (Monty Python) -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
In reply to this post by Jeroen Budts
On Wednesday, August 1, 2012 1:26:04 AM UTC-5, Jeroen Budts wrote:
> >>> > > >>> Using f/F/t/T is nice because I can follow it up with ; or , if > > >>> I didn't supply the right count, and I have a mapping which > > >>> will highlight all the matching characters within the line so I > > >>> can quickly get the count right on my second try if needed. > > > > > >> Would you care to share this mapping? It seems very interesting. > > > > > > it isn't Ben's exclusive mapping, it's everybody's -- see: > > > > > > :h f > > > > > > f is the linewise search command -- it is famous for the fact that > > > it searches current line only (and to the right only). > > > > > > > I know about the f/F/t/T commands. What I was referring to was the > > mapping to highlight all the matching characters: "...and I have a > > mapping which will highlight all the matching characters within the > > line..." > I think I've shared it before, but can't find it at the moment. I've been meaning to make a page on the wiki for it but want to clean it up a bit. Here is my current mapping. It also includes a Vimscript fix for the same issue fixed by patch 7.3.235, which if you only use recent versions of Vim can be stripped out. Caveat: repeating with '.' breaks slightly when using the F/f/T/t mappings, but not the ; and , mappings if I recall correctly. So if you use these as-is you'll need to (for example) dt( and use d; to repeat the first time. I've been meaning to fix this but it hasn't yet been worth the trouble. If somebody has a fix for that I'll be glad for it. " Highlight characters found by f, F, t, and T. " Unhighlights on a cursorhold. " " matchadd is needed to highlight the char " " Also map <leader>f to show the highlight, and jump over the next char for , " and ; operations if the cursor won't move normally. if exists('*matchadd') nnoremap f :<C-U>call FindChar('f', v:count1)<CR> nnoremap F :<C-U>call FindChar('F', v:count1)<CR> nnoremap t :<C-U>call FindChar('t', v:count1)<CR> nnoremap T :<C-U>call FindChar('T', v:count1)<CR> onoremap f :<C-U>call FindChar('f', v:count1, 'v')<CR> onoremap F :<C-U>call FindChar('F', v:count1, 'v')<CR> onoremap t :<C-U>call FindChar('t', v:count1, 'v')<CR> onoremap T :<C-U>call FindChar('T', v:count1, 'v')<CR> xnoremap f :<C-U>call FindChar('f', v:count1, 'gv')<CR> xnoremap F :<C-U>call FindChar('F', v:count1, 'gv')<CR> xnoremap t :<C-U>call FindChar('t', v:count1, 'gv')<CR> xnoremap T :<C-U>call FindChar('T', v:count1, 'gv')<CR> nnoremap ; :<C-U>call FindLastChar(v:count1, ';')<CR> onoremap ; v:<C-U>call FindLastChar(v:count1, ';')<CR> xnoremap ; :<C-U>call FindLastChar(v:count1, ';', 1)<CR> nnoremap , :<C-U>call FindLastChar(v:count1, ',')<CR> onoremap , v:<C-U>call FindLastChar(v:count1, ',')<CR> xnoremap , :<C-U>call FindLastChar(v:count1, ',', 1)<CR> " <C-U> in normal mode to remove any count, in visual mode to remove range " Do not provide this command in op-pending mode, it doesn't do anything nnoremap <Leader>f :<C-U>call HighlightFoundChar()<CR> xnoremap <Leader>f :<C-U>call HighlightFoundChar()<CR>gv " highlight the last found character function! HighlightFoundChar() if &hlsearch if exists('w:fFtT_command_highlight') call matchdelete(w:fFtT_command_highlight) endif let w:fFtT_line = line('.') let w:fFtT_command_highlight = matchadd( \'Search', \'\V\%' . w:fFtT_line . "l".escape(g:last_found_char,'/\'), \11) setl cursorcolumn cursorline " Set up autocmds to turn off highlighting for f, F, t, and T commands " after a period of doing nothing, or moving to a new line. The " CursorMoved one makes the cursor move slowly so remove it when not " needed. autocmd fFtT_hi CursorMoved * \ if exists('w:fFtT_command_highlight') && w:fFtT_line != line('.') | \ call matchdelete(w:fFtT_command_highlight) | \ unlet w:fFtT_command_highlight | \ setl nocursorcolumn nocursorline | \ exec 'au! fFtT_hi CursorMoved' | \ endif endif endfunction augroup fFtT_hi au! " Set up autocmds to turn off highlighting for f, F, t, and T commands after " a period of doing nothing, or moving to a new line. The CursorMoved one " makes the cursor move slowly so remove it when not needed. autocmd CursorHold,CursorHoldI * \ if exists('w:fFtT_command_highlight') | \ call matchdelete(w:fFtT_command_highlight) | \ unlet w:fFtT_command_highlight | \ setl nocursorcolumn nocursorline | \ exec 'au! fFtT_hi CursorMoved' | \ endif augroup END " Set the "last found character" and highlight it. function! FindChar(op, count, ...) echo "Enter character to find" let g:last_found_char = nr2char(getchar()) call HighlightFoundChar() " clear the echo echo '' let cmdprefix='' if a:0 let cmdprefix=a:1 endif exec 'normal! ' . cmdprefix . a:count . a:op . g:last_found_char endfunction " Highlight the "last found character" if it exists and pass on the input " operation which should be either , or ; " " Do a double-jump if a single jump doesn't move to allow ; and , to work " intelligently when t or T is used. function! FindLastChar(count, op, ...) if exists('g:last_found_char') && g:last_found_char != '' call HighlightFoundChar() endif if a:0 normal! gv endif if a:count==1 let curpos=getpos('.') exec 'normal!' a:op if curpos==getpos('.') exec 'normal! 2'.a:op endif else exec 'normal! '.a:count.a:op endif endfunction endif -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
In reply to this post by Daan
Thanks for investing the time to reply to me guys. I think that I will try to focus on relative line numbers first!
-- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
In reply to this post by Daan
On Tuesday, 31 July, 2012 at 19:58:55 BST, Daan wrote:
>I've been learning Vim for a while, and one situation has been coming up a lot for me: > >1) I'm scrolling through a sourcefile, and see an interesting word I'd like to edit or yank. >2) I look left at the line number of the word, and type [line number]G >3) I keep pressing w/W/b/B until I reach the word, (except if the word happens to be the first or last word of the line, or located near a unique symbol) > >However, this feels inefficient (especially step 2), and I'm hoping to find a better solution. I like PreciseJump: http://www.vim.org/scripts/script.php?script_id=3437 -- . -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
On Thu, Aug 2, 2012 at 6:33 AM, Paul <[hidden email]> wrote:
In my opinion it is more complete than PreciseJump; it does everything PreciseJump does and more... --
-- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
On Friday, 03 August, 2012 at 15:59:44 BST, Ethan Hereth wrote:
>> I like PreciseJump: http://www.vim.org/scripts/**script.php?script_id=3437<http://www.vim.org/scripts/script.php?script_id=3437> >> >> If you like PreciseJump, you'd probably also like EasyMotion: >> http://www.vim.org/scripts/script.php?script_id=3526 (or >> https://github.com/Lokaltog/vim-easymotion) >> > In my opinion it is more complete than PreciseJump; it does everything >PreciseJump does and more... Mine too, now! -- . -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
|
In reply to this post by scott-268
Hi sc!
On Di, 31 Jul 2012, sc wrote: > :h f > > f is the linewise search command -- it is famous for the fact that it > searches current line only (and to the right only). That's why I have made http://www.vim.org/scripts/script.php?script_id=3877 regards, Christian -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php |
| Powered by Nabble | Edit this page |
