Giter VIP home page Giter VIP logo

vim-textobj-comment's Introduction

textobj-comment

This Vim plugin provides text objects for comments.

ac selects a comment including the comment delimiters and ic selects just the comment content. (There's also a third text object, aC, which selects a comment including trailing or leading whitespace.) These mappings are available in Visual and Operator-pending mode.

This plugin uses the 'comments' and 'commentstring' settings to determine what a comment looks like for a given filetype. It works with both /* paired */ and // simple comment delimiters.

This plugin depends on the textobj-user plugin.

Usage

Comprehensive on-line documentation is included and available at :h textobj-comment.

Below is a quick demo of the 'a comment' text object. The command used is vac. The targeted area is the same for analogous commands using an operator, such as dac, cac, and gqac.

demo

The 'inner comment' text object targets the inside of a comment. Here I use cic:

demo

Requirements

  • Vim 7.3 or later
  • textobj-user Vim plugin, at least version 0.4.0

Installation

Move the files into their respective directories inside your ~/.vim directory (or your $HOME\vimfiles directory if you're on Windows).

With pathogen.vim the installation is as simple as:

git clone git://github.com/glts/vim-textobj-comment.git ~/.vim/bundle/textobj-comment

This plugin also plays well with other plugin managers.

Don't forget to install textobj-user, too, if your setup doesn't take care of dependencies automatically.

Development

The code isn't pretty. If you look closely you'll notice a lot of effort being made to cover corner cases and make the behaviour of the text objects as similar to the built-ins as possible. That said, if you are interested in working on it, use the test suite to make sure you don't break anything.

The test suite is written using vspec.

make test runs the whole suite and make t/<test>.vim runs a specific test. You may need to adapt the paths to the vspec executable and to the runtime path directories at the top of the Makefile.

vim-textobj-comment's People

Contributors

glts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-textobj-comment's Issues

Select from cursor to the end of current comment

I'm get used to gq} for usual text - previous part of paragraph is usually already formatted (and sometimes manually, a bit different from default formatting), and I need to auto-reformat only rest of current paragraph. I'd like to use same for comments, but motions you've defined didn't allow to select "to the end of comment block".

Can you please add this feature, or at least give me quick hint what to patch in your plugin for this?

Add option to split multiline comments on fold markers

How hard would be to add an option to stop the multiline comment detection on fold markers?

What I mean is this, || means the cursor location:

"}}}
" Appearance {{{
" hi link EasyMotionShade         Comment
" hi link EasyMotionTarget        IncSearch ||
" hi link EasyMotionTarget2First  MatchParen
" hi link EasyMotionTarget2Second MatchParen
"}}}
"}}}
" Visualstar {{{

This is technically a single multi-line comment, but logically (IMHO), if you run vac it should select only this:

" hi link EasyMotionShade         Comment
" hi link EasyMotionTarget        IncSearch
" hi link EasyMotionTarget2First  MatchParen
" hi link EasyMotionTarget2Second MatchParen

I understand this requirement shouldn't be the default, but there should be an option to toggle this behaviour.
I can submit a PR for this, just need a pointer for where to start.

Plugin errors out on startup

When starting Neovim v0.4.4 with this plugin from master branch, the plugin errors out (though it still works as intended, commands like gqic work just fine):

Error detected while processing /home/tdemin/.vim/plugged/vim-textobj-comment/plugin/textobj/comment.vim:
line   27:
E117: Unknown function: textobj#user#plugin
Press ENTER or type command to continue

:version says:

NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstr
ict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNV
IM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.4.4/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Default mappings conflict with textobj-word-column.vim

The default mappings ac, ic, and aC conflict with the mappings of the textobj-word-column.vim plugin.

I suggest remapping the textobj-word-column.vim mappings to av/iv and aV/iV: You can think of it as either an abbreviation for "Visual block", or as the letter right next to "w" for "word" and "W" for "WORD". At the end of the day, Visual blocks of words/WORDS is what that plugin does.

To remap, copy and paste this into your vimrc file:

let g:skip_default_textobj_word_column_mappings = 1
xnoremap <silent> av :<C-U>call TextObjWordBasedColumn("aw")<CR>
onoremap <silent> av :call TextObjWordBasedColumn("aw")<CR>
xnoremap <silent> iv :<C-U>call TextObjWordBasedColumn("iw")<CR>
onoremap <silent> iv :call TextObjWordBasedColumn("iw")<CR>
xnoremap <silent> aV :<C-U>call TextObjWordBasedColumn("aW")<CR>
onoremap <silent> aV :call TextObjWordBasedColumn("aW")<CR>
xnoremap <silent> iV :<C-U>call TextObjWordBasedColumn("iW")<CR>
onoremap <silent> iV :call TextObjWordBasedColumn("iW")<CR>

If you decide to reaccomodate the mappings for the textobj-comment plugin instead, here is how to do it:

let g:textobj_comment_no_default_key_mappings = 1
xmap ax <Plug>(textobj-comment-a)
omap ax <Plug>(textobj-comment-a)
xmap ix <Plug>(textobj-comment-i)
omap ix <Plug>(textobj-comment-i)
xmap aX <Plug>(textobj-comment-big-a)
omap aX <Plug>(textobj-comment-big-a)

Doesn't work from 'vim' filetype

For example, in .vimrc, I have the following comment, and it is not treated as a comment text object.

" toggle invisible characters

filetype is detected correctly, however, comments seems to be wrong.

:set filetype? comments? commentstring?
  filetype=vim
  comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
  commentstring=/*%s*/

Include python docstring support

Hi, I'd like to say that I really like your plugin. However I've noticed that it doesn't have a proper python support - it doesn't detect python docstrings as comments. Could you please add this functionality?

Doesn't work for OCaml

E.g.

(* try vic in this comment *)

My commentstring seems to be set correctly: (*%s*)

EDIT: I forgot to mention that it does work for other file types.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.