Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive f key in vim?

Tags:

vim

Does anyone know of any way to get the 'f' key in vim normal command mode to operate case insensitive

Example

function! OpenCurrentFileInMarked()

In the above line, if I am at the start of the line I want to be able to type 'fi'and get the first 'i' and then ';' to toggle to the capital 'I' in the middle of the function name. I would prefer that the 'f' key is always bound to case insensitivity. Would work much better for me as a default.

like image 315
toomey8 Avatar asked Jun 24 '13 16:06

toomey8


People also ask

What does F do in Vim?

If you press "F", Vim will move the cursor backwards instead of forward. Given the previous sentence, if pressed "Fq", and the cursor was at the end of the line, it would move to the "q" in "quick".

How do I enable search ignoring case in Vim?

By default, all searches in vi are case-sensitive. To do a case-insensitive search, go into command mode (press Escape), and type :set ignorecase . You can also type :set ic as an abbreviation. To change back to case-sensitive mode, type :set noignorecase or :set noic in command mode.


2 Answers

The easy answer here is: use a plugin. Others have had the idea before.

  • Fanf,ingTastic;: Find a char across lines

    The main purpose of this plugin is to make f and t cross the line boundary.

    To make them ignore case you need to let g:fanfingtastic_ignorecase = 1 in your vimrc.

  • ft_improved: improved f/t command

    Same here.

    To make it ignore case you again need to set a variable in your vimrc, this time let g:ft_improved_ignorecase = 1.

like image 189
glts Avatar answered Oct 16 '22 10:10

glts


The first part of this (case insensitive f) is actually in the reference manual as an example of how to use the getchar() function:

This example redefines "f" to ignore case:

:nmap f :call FindChar()<CR>
:function FindChar()
:  let c = nr2char(getchar())
:  while col('.') < col('$') - 1
:    normal l
:    if getline('.')[col('.') - 1] ==? c
:      break
:    endif
:  endwhile
:endfunction

See :help getchar().

You'll need to save the character returned and write a similar map for ; if you want that to work too.

like image 42
Rich Avatar answered Oct 16 '22 10:10

Rich