Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "ac" ("a comment") text object #1779

Merged
merged 2 commits into from
May 28, 2018
Merged

Add "ac" ("a comment") text object #1779

merged 2 commits into from
May 28, 2018

Conversation

arp242
Copy link
Contributor

@arp242 arp242 commented Apr 8, 2018

To select a comment block. Fixes #1508

Requires fatih/motion#4

To select a comment block. Fixes #1508

Requires fatih/motion#4
@@ -1085,6 +1085,9 @@ if "inside a function", select contents of a function,
excluding the function definition and the closing bracket. This
text-object also supports literal functions

*go-v_ac* *go-ac*
ac "a comment", select contents of the current comment block.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there way we could support ic as well? This could be handy if we want to remove the comment with leaving it intact. For example // this is a comment could be deleted via dic, so it would end up with //

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be useful, it is a little bit tricky to get it to behave intuitively in cases with multi-line comments, but I think I got it right.

@fatih
Copy link
Owner

fatih commented May 8, 2018

Just tried it out and seems like ic is not working then it's intended (groups of const, vars, imports, etc..). For example:

// Options is used to setup Kubernetes
type Options struct {
	// Client is the underlying client manager uses for core resources
	Client kubernetes.Interface
}

ic works for the first comment above, not for the second one. It deletes the whole line when you type dic

@fatih
Copy link
Owner

fatih commented May 28, 2018

The following fixes it:

$ vim-go git:(Carpetsmoker-ac) ✗ git diff
diff --git a/autoload/go/textobj.vim b/autoload/go/textobj.vim
index 2f60046..164b769 100644
--- a/autoload/go/textobj.vim
+++ b/autoload/go/textobj.vim
@@ -44,7 +44,9 @@ function! go#textobj#Comment(mode) abort
   " Adjust cursor to exclude start comment markers. Try to be a little bit
   " clever when using multi-line '/*' markers.
   if a:mode is# 'i'
-    let l:line = getline('.')
+    " trim whitespace so matching below works correctly
+    let l:line = substitute(getline('.'), '^\s*\(.\{-}\)\s*$', '\1', '')
+
     " //text
     if l:line[:2] is# '// '
       call cursor(l:info.startLine, l:info.startCol+3)

I'll merge this PR and apply the fix above.

@fatih fatih merged commit 956909d into fatih:master May 28, 2018
fatih added a commit that referenced this pull request May 28, 2018
@arp242 arp242 deleted the ac branch May 29, 2018 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants