29

Because t takes a character, so it looking for a literal $ character, not a motion like end of line


7

You can do: gnc gn will do a visual selection of the search result, then c is, as you know, change. Also, cgn works (change the next occurence of the search result).


6

If you start with this normal mode mapping: nnoremap <buffer> $ f\|ge The visual-mode mapping is identical: vnoremap <buffer> $ f\|ge Then, for operator-pending mode (like after d, y, and so on), you need a different kind of mapping. :help omap-info tells us: To ignore the starting cursor position and select different text, you can have ...


5

This comes down to the iskeyword setting. When I run :set iskeyword? in a bash file, I get this: iskeyword=@,48-57,_,192-255,. When I run the same command with a python file, I get this: iskeyword=@,48-57,_,192-255 If you have the filetype plugin set up, you could add this to your python file: set iskeyword+=. or this to your bash file (depending on ...


5

t (and its variants T, f and F) take a single character afterwards to denote the target of motion within the line. So the effects of the two commands are: d$ - delete to end of current line dt$ - delete up-to-but-not-including a literal $ on the current line


5

The wellle/targets.vim plugin should do what you're looking for (and much more). This allows you to explicitly tell vim to go to the next parenthesis (with cin(, n for next parenthesis), or the last parenthesis (with cil(), but it also overrides the default so that you jump to the next or last if you don't specify. From the README: This overrides Vim's ...


4

If you tried reedes/vim-textobj-sentence, that (hopefully) means you have kana/vim-textobj-user installed. You can (mostly) trivially use this to define your own sentence. Treat this as a starting point for experimentation - it seems to work well enough, but clobbers search etc; I'm sure it can be handled more cleanly: function! LinewiseSentenceI() let ...


4

To delete the current fold, you simply have zd for instance Otherwise, you could also define an operator-pending mode mapping with for instance: :onoremap iz :<c-u>normal! [zV]z<cr> Which will permit stuff like diz, ciz, yiz, =iz and so on. BTW, the related visual mode mapping would be: :xnoremap iz [zo]z


4

There is no text object for folds in vim, but there is a plugin which provides them, az/iz: https://github.com/kana/vim-textobj-fold Here are vanilla alternatives: vi{/va{. This may or may not select what you want, depending on whether your markers are in comments or not. [zV]z. Alternatively you can replace V with any operator. make your own: xnoremap ...


4

This doesn't answer your more general question about text objects, but you can achieve the behaviour in your specific indentation-based example with folds: setlocal foldmethod=indent setlocal shiftwidth=2 setlocal foldlevel=99 Setting 'foldmethod' tells Vim that you want to use indentation based folding. Setting 'shiftwidth' tells Vim the size of each ...


4

This is called "a motion". Even though linewise motions result in a line range. Normally, it's enough to do 5J and there's no need for "join" operator. However, if you really want it, you can make use of :h g@ and :h 'opfunc' A simplified example: " very basic "join" operator nnoremap <silent>J :set opfunc=OperJoin<CR>g@ function! OperJoin(type)...


4

The answer is simple: gJip doesn't work, because gJ is not an operator. See :h operator for which operators exist. The easy workaround is to use visual mode, and then join all the lines, e.g. use vipgJ, because in visual mode gJ will join all those selected lines (see :h v_gJ). If you want to know the reason, why gJ and also J has not been implemented as an ...


3

For the general case, you can try creating new operators, gs and ge: function! GoStart(type) abort normal! `[ endfunction function! GoEnd(type) abort normal! `] endfunction nnoremap <silent> gs :set opfunc=GoStart<CR>g@ nnoremap <silent> ge :set opfunc=GoEnd<CR>g@ When Vim invokes the operator functions after you type your ...


3

Define syntax match gitcommitBody for the custom text object syntax Install vim-textobj-user and vim-textobj-syntax. The default syntax file for gitcommit does not define gitcommitBody. Place following line syn match gitcommitBody "\%>2l[^#].*" contains=@Spell into the file ~/.vim/after/ftplugin/gitcommit.vim. This defines for all lines except the ...


3

Actually. There is no reason, apart from things being as they are, that would be against an r operator. The simple fact that viwra works means that riwa could work. The reason is simply a historical one, but there is nothing against an alternative implementation. It can help 'filling' some area defined by a motion/text-object with a single character. I ...


3

This works for me: :function! Foo() call feedkeys("\<esc>") return :endfunction This works since you can hit esc in operator pending mode (for example, c<esc>), and it will not complete the operator.


3

If using plug-ins is acceptable to you, then the vim-commentary plug-in can help you. It defines a gc text object to select a comment, which you can use in operator pending mode. Use gqgc anywhere in the comment block to format the comment. Note that if you are using C or C++ you may need to tell Vim to use // comments instead of /**/ comments. You can ...


2

Have you looked at Quick search, limited to a C++ function all the techniques presented in this discussion shall apply to your question. I'm not sure my solution is checking the cursor is within a function definition. To check for improper uses, you have to define a function. There, first record the current line, and then check the first and last line you ...


2

As @romainl said, you can use the [ and ] marks for this purpose, e.g.: nnoremap gc `[v`] Pressing gc visually select the previous change. :'[,']s/var_name/varName/g Replace in the last modified lines every var_name with varName If you want to use it in your function you can get informations about the last changed lines like so: let firstline = line("'[...


2

Not an answer, but a piece of code I used to "simulate" the functionality of an operator with r: function! ROperator() call inputsave() let l:replace_pattern = input('Replace > ') call inputrestore() if len(l:replace_pattern) != 3 throw "Bad pattern size (expected 3)" endif let l:motion = strpart(replace_pattern, 0, 2) let l:char = ...


2

Replace is a specific type of situation, that I don't believe is equivalent to the others you listed that take motions. r can take an optional count, but the action is the same. 3ra replaces 3 characters with the letter "a". In its current state, adding a motion would only allow for the repetition of the replace action. You could "replace word with the ...


2

Update: Well, I made a plugin. Get it from ctholho/vim-textobj-sentence-line. The plugin supports is and as motions. I didn't test all possible conditions but it does the job reliably. It also remaps the ) and ( motion to behave in the same way. Thanks to brhfl whose answer provided the building blocks for this. Based on the answer of brhfl I cobbled ...


2

The answer from @RubenWesterberg is a correct sequence of Normal mode commands to do what you want. But I read your request to not move the cursor a little more literally. Also, if you need to make substitutions like this frequently you probably want something a bit less manual. You can use standard substitution in a mapping like this: :nnoremap <expr&...


2

That's a great opportunity to leverage text objects (see :help text-objects). The following code extends the normal behavior of the it text object (see :help it and :help tag-blocks) to make it consider multi-line HTML tags content as described in your post. In that way, you could also type in vit>, >it, dit, cit, yit and so on, with the extended ...


2

All of the text-objects are documented under :help text-objects. Excerpted from :help objects: |v_iquote| i" double quoted string without the quotes |v_i'| i' single quoted string without the quotes |v_i(| i( same as ib |v_i)| i) same as ib |v_i<| i< "inner <>" from '<' to the ...


2

You can control that with the 'selection' option. To disable the "past line" cursor behavior, use the following command: set selection=old Beware that using a non-default setting for this option is possibly likely to break behavior of some plug-ins, so it might not be a great idea to change it. There's also a motion that might be close to what you ...


1

The commandline command you're looking for is 'j': :1,5j


1

Plugin vim-ninja-feet by tommcdo Currently, this plugin provides following square bracket mappings (do not overlook the square in the definition): {operator}[{text object} Perform {operator} from the cursor to the beginning of the text object defined by {text object}. {operator}]{text object} ...


1

It's in the docs, but you need to jump around a bit. :h i) says it's like [(, which in turn is like %, which is affected by 'cpoptions': When the '%' character is not present in 'cpoptions' |cpo-%|, parens and braces inside double quotes are ignored, unless the number of parens/braces in a line is uneven and this line and the previous one does not ...


Only top voted, non community-wiki answers of a minimum length are eligible