43

Since vim uses the percent sign to reference the current buffer, you can use it to get everything quickly. :%y will yank the entire buffer :%y+ will yank it to the + register (and presumably the clipboard, provided vim was compiled with the proper options). :%d and :%d+ will do the same for deletion. In each of these cases, the cursor remains in place.


14

Here is a crude "line" text-objects: xnoremap il g_o0 onoremap il :normal vil<CR> xnoremap al $o0 onoremap al :normal val<CR> And a crude "buffer" text-object: xnoremap i% GoggV onoremap i% :normal vi%<CR> ---EDIT--- An "operator" is a command that doesn't do anything by itself: d, y, etc. Pressing those keys put you in "operator-...


13

Another solution is to use a plugin called vim-textobj-entire. By default, this plugin provides the text object ae for the entire buffer, ie for the entire buffer except leading and trailing empty lines. This plugin depends on vim-textobj-user by the same author, which lets users define any text objects comfortably. There are many plugins that make good ...


10

There is no text object for the whole file by default, but it is possible to create them using omap. In this case, it would look something like this: onoremap f :<c-u>normal! mzggVG<cr>`z Here is a breakdown of how it works: onoremap f " make 'f' the text object name :<c-u> " use <c-u> to prevent vim from inserting visual ...


10

I've used vim-indent-object for a while with some success. It provides text objects like ii, ai, iI, and aI, each with slightly different semantics. For your sample code def some_method if @foo @bar = 42 # moooooore code... end end If the cursor is anywhere inside the if block, you could use vii to select the the bar and more lines. Or, use =...


10

I don't know LaTeX but this seems to work: vnoremap iq :<C-U>silent! normal! t'vT`<CR> omap iq :normal viq<CR> I based this off the information over here: http://vim.wikia.com/wiki/Creating_new_text_objects You can add support for aq as well: vnoremap aq :<C-U>silent! normal! f'vF`<CR> omap aq :normal vaq<CR>


7

Edit: I just discovered the vim-textobject-latex plugin, which adds the exact functionality you're looking for (in addition to a few other things). From the plugin's README: Currently supported text objects are: a i Description a\\ i\\ Inline math surrounded by ``\\(`` and ``\\)``. a$ i$ Inline math surrounded by dollar signs. aq iq Single-quoted ...


7

If you want only $ to be a text object, then do the following xnoremap i$ :<C-u> normal! T$vt$<CR> onoremap i$ :normal vi$<CR> xnoremap a$ :<C-u> normal!F$vf$<CR> onoremap a$ :normal va$<CR> This will add some more text objects in your vim config. for s:char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash&...


5

Consider if you were doing some operation in visual mode for deleting in a word, you would use the following to put the deletion in register a. viw"ad -> v [iw] ["a] d visual object register operator Similarly, placing "a in the omap after the operator ix passes it to the opfunc. Either of these ...


5

Yes, this is possible. @PeterRincker suggests the plugin textobj-word-column, which defines four text objects (ic, ac, iC, and aC) for word-based columns. The idea behind this functionality is to create a function that defines a column based motion, and then to map this function appropriately to visual/select mode mappings and operator pending mappings. To ...


5

The following example comes close to what you are asking for: onoremap <expr> w '<esc>' . v:operator . v:count1 . (v:operator ==# 'd' ? 'aw' : 'iw') It creates a textobject w that is either aw, in case it is used by the delete operator, that is, dw = daw, or iw otherwise, for example cw = ciw.


5

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

Is it possible? Absolutely! Case and point: textobj-word-column.vim. How to make your own text objects Typically visual mode is used to create a new text object. The visual mode can be line-wise, character-wise (typically), or visual-block. Here is the basics of what you will need: An unused key combination typically a{char} or i{char} where {char} is ...


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

Since i$ is a mapping itself (defined by the vimtex plug-in), you need a recursive mapping to be able to use i$ as part of the expansion of your mapping. So this should work: nmap cim ci$ But you can also create an operator-pending mode mapping for im, in which case that would work with other operations such as dim or yim and other built-in or custom ...


3

You can add your own syntax element (probably overriding existing one): syntax match quoteblock /"[^"]\+"/ contains=@NoSpell syntax match: Tells vim this is a syntax command quoteblock: The name of our match (Could be anything) /"..."/: Match things between quotes [^"]\+: Match anything that's not a quote contains=@NoSpell: Tells vim not to use spell check ...


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

I think you do not really understand what a text object is. I therefore recommend that you read :h text-objects. When you have read and understood this, you should be able to understand the vimtex text object mappings. The vimtex documentation does list all the default mappings with a mode indicator. The ac and ic mappings are indicated with xo, which ...


3

This is actually a know issue (see issues #2 and #15 in the plugin bug tracker). The author of the plugin suggested a workaround of the following form: call textobj#user#plugin('handyobjects', { \ 'underscores_a': { \ 'select': 'ar', \ '*pattern*': '%[^%]*%' \ }, \ 'underscores_i': { \ 'select': 'ir', \ '*pattern*': '%\zs[^%]\+\ze%' \ ...


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

You can try this: vip<Ctrl-v>I//<ESC> vip select paragraph <Ctrl-v> make selection blockwise I// insert // into begining of a selection block PS: I would suggest to use vim-commentary plugin from Tim Pope where it would be simple gcip.


3

UPDATE: Latest vimtex includes PR #1711 which allows you to configure vimtex to override existing mappings by setting this global variable from your vimrc: let g:vimtex_mappings_override_existing = 1 So the recommended solution for this problem is update your vimtex to latest and include this variable setting in your vimrc. OLDER UPDATE: It turns out ...


2

Recommended Solution Created by @filbranden in response to my question here " Create text-object `A` which operates on the whole buffer (i.e. All) " Keeps the cursor position in the same position function TextObjectAll() let g:restore_position = winsaveview() normal! ggVG " For delete/change ALL, we don't wish to restore cursor position. if ...


2

Here are some quick n' dirty mappings to accomplish the task: nnoremap yY :%yank <c-r>=v:register<cr><cr> nnoremap dD :%delete <c-r>=v:register<cr><cr> Now you can use yY and dD to yank/delete respectively. It's not as nice as using a full blown text object, but sometimes the simplest solutions are best. For more help ...


2

This is an old question but for the benefit of future visitors: I find its easier to change the latex quotes with: \usepackage{csquotes} % change " " into nice double quotes \MakeOuterQuote{"} And then This thing is "Foobar"! will work fine in vim and latex.


2

This could be implemented using: https://github.com/kana/vim-textobj-user Lots of existing plugins are close to this behavior, but none seems to answer the question yet.


2

Here is an example for a custom text object working with the marks a and b. " char-wise onoremap am :<c-u>execute 'normal `av`b'<cr> xnoremap am :<c-u>execute 'normal `av`b'<cr> " line-wise onoremap aM :<c-u>execute 'normal `aV`b'<cr> xnoremap aM :<c-u>execute 'normal `aV`b'<cr> To copy the characters ...


2

You can also put the following in your .vimrc: xmap dsm <plug>(vimtex-env-delete-math) xmap csm <plug>(vimtex-env-change-math) xmap am <plug>(vimtex-a$) xmap im <plug>(vimtex-i$) omap dsm <plug>(vimtex-env-delete-math) omap csm <plug>(vimtex-env-change-math) omap am <plug>(vimtex-a$) ...


2

I found that something like that is possible with the plugin tpope/vim-surround. <di█ id="foo"> <div class="bar"> </div> Or: <div id="foo"> █ <div class="bar"></div> </div> Input: cst<section | Result: <section id="foo"> █ <div class="bar"></div> </section>


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