开发者

how can i make a bookmark with a name in visual studio 2010

开发者 https://www.devze.com 2023-02-20 16:28 出处:网络
when making a bookmark in VS 2010 it is given some default name \"Bookmark#\". and then later i have to rename it.

when making a bookmark in VS 2010 it is given some default name "Bookmark#". and then later i have to rename it. what i want is to select a text a开发者_JAVA技巧nd when i make a new bookmark this bookmark's name will be the text i have selected.

how?


If you already have the Bookmark Window open, you can right-click on the bookmark and select Rename. Then, just start typing, and your bookmark will be renamed.

If you need to open the Bookmark Window, you can use the default command Ctrl+W, B, or you can go to View -> Other Windows -> Bookmark Window.

Edit: In VS 2015, the Bookmark Windows command is Ctrl+K, Ctrl+W.


You can try using code shortcuts rather than bookmarks. If you add a comment, eg:

// place in my code I want to come back to

Then with the cursor on this line press Ctrl+K then Ctrl+h it will add a code shortcut, you'll notice the shortcut icon in the margin.

Next, press Ctrl+\+T to bring up the task list, and select Shortcuts from the dropdown. The description text will be whatever the contents of the line are where you added the shortcut, in this case the comment text. If you just add a shortcut on a line of code, the description will be the contents of that line of code.

Double click on a shortcut to go to that location in the code.


You can try to use this Visual Studio extension: NamedBookmarks.


You can install Visual Commander extension, create new command and use this code:

public class M:VisualCommanderExt.ICommand
{
    private static readonly char[] SpecialChars = new char[] { '+','^','%','~','(',')','[',']' };

    public void Run(EnvDTE80.DTE2 DTE,Microsoft.VisualStudio.Shell.Package package)
    {
        TextSelection selection = DTE.ActiveDocument.Selection as TextSelection;
        string caption = selection.Text;

        if(caption == "")
        {
            // get current line content
            selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText);
            selection.EndOfLine(true);
            selection = DTE.ActiveDocument.Selection as TextSelection;
            caption = selection.Text;
        }


        Window currentWindow = DTE.ActiveWindow;
        selection.SetBookmark();

        DTE.ExecuteCommand("View.BookmarkWindow");
        Window bookmarkWindow = null;
        foreach(Window window in DTE.Windows)
        {
            if(window.Caption == "Bookmarks")
            {
                bookmarkWindow = window;
                break;
            }
        }

        bookmarkWindow.Activate();
        DTE.ExecuteCommand("OtherContextMenus.BookmarkWindow.Rename");

        foreach(char c in caption)
        {

            if(System.Array.Exists(SpecialChars,element => element == c))
                SendKeys.SendWait("{" + c.ToString() + "}");
            else
                SendKeys.SendWait(c.ToString());
        }

        SendKeys.SendWait("{ENTER}");

    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消