Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Vertical "f" and "t"

Tags:

vim

One tiny piece of functionality I find myself missing increasingly often is the ability to move vertically in a similar fashion to f and t. Usually what I want is to move to the top or bottom of a paragraph without losing my column position, and while I "could" just write a script for it, I wondered if there is any known way around this problem that you guys know of.

Example ( [ ] = current position, < > = destination ):

set tabstop=4
set shiftwidth=4

set <s>ofttabstop=4
set gfn=Source\ Code\ Pro:h14  
set encoding=utf-8
set [t]_Co=256      
set number        

Like a vertical fs, or t<space>.

Again, this is usually useful when working with blocks of code. Any ideas?

like image 593
krystah Avatar asked Jan 21 '14 16:01

krystah


2 Answers

vim regex provides \%nc (n is col idx) to match only in certain column.

so without installing plugin, what you could do is :

nnoremap <leader>f :<c-u>exe line('.').'/\%'.col('.').'c'.nr2char(getchar())<cr>

in this way, you press <leader>f, then press a key, vim will search that char in the same col. next, you press n/N

If you want to have the same but search backwards, use ?.

like image 128
Kent Avatar answered Nov 11 '22 01:11

Kent


The most basic way is to use forward search, /t_<CR> and backward search, ?so<CR>, ideally with set incsearch.

But there are quite a lot of plugins designed around that idea:

  • EasyMotion,
  • Sneak,
  • Fanfingtastic,
  • and a few others…
like image 43
romainl Avatar answered Nov 11 '22 03:11

romainl