SQL Server Studio 管理中重复行的快捷方式?

发布于 2024-11-07 23:12:14 字数 144 浏览 0 评论 0原文

在 Netbeans 和 Eclipse 中,您可以按 CTRL + Shift + Down (我认为这就是 netbeans),它将复制一行代码。这在 SQL Server Management Studio 中可能吗?这是与 SQL Server 2008 一起运行的

In Netbeans and Eclipse you can hit CTRL + Shift + Down (i think thats netbeans) and it will duplicate a line of code. Is that possible in SQL Server Management Studio? This is running with SQL Server 2008

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

叹梦 2024-11-14 23:12:14

我认为您可以点击 CTRL + CCTRL + V 而不选择任何文本,您可以复制该行在它下面。

编辑:适用于 SSMS18

I think you can hit CTRL + C and CTRL + V without any text selected and you can duplicate the line below it.

Edit: works in SSMS18

一曲爱恨情仇 2024-11-14 23:12:14

如果您使用 SSMS 18.0 或更高版本并且不使用 结果到网格 (当前占用CTRL+D),然后您可以更新“选项”菜单中的键绑定。

  1. 转到工具 -> 选项 -> 环境 -> 键盘
  2. 显示包含的命令下,搜索Edit.Duplicate

SSMS 中选项对话框的键盘部分显示 Edit.Duplicate

  1. 选择 < em>按快捷键键框并按CTRL+D
  2. 现在搜索Query.ResultstoGrid
  3. 删除CTRL的两个快捷键+D

当您单击“确定”离开选项时,您应该会发现可以立即使用按键绑定。

编辑:添加了确认,仅从 SSMS 18.0 开始支持此功能(h/t @Darrin 进行确认)

If you're using SSMS 18.0 or above and don't use the shortcut for Results to Grid (which currently occupies CTRL+D), then you can update the key bindings in the Options menu.

  1. Go to Tools -> Options -> Environment -> Keyboard
  2. Under Show commands containing, search for Edit.Duplicate

Keyboard section of Options dialog box in SSMS showing Edit.Duplicate

  1. Select the Press shortcut keys box and press CTRL+D
  2. Now search for Query.ResultstoGrid
  3. Remove both of the shortcuts for CTRL+D.

When you click "OK" to leave Options, you should find that you can use the key binding straight away.

Edit: Added confirmation that this is only supported from SSMS 18.0 onwards (h/t @Darrin for confirming)

辞慾 2024-11-14 23:12:14

在 SSMS 18.2 中,[edit.Duplicate] 与 [CTRL+E, V] 和 [CTRL+D] 关联。最简单的方法就是删除 [CTRL+D] 与 [Query.ResultstoGrid] 的关联。那么这将仅说明[edit.Duplicate]。之后,您可以使用 [CTRL+D] 复制行。
我认为将保存结果更改为网格或文件时并不常见。
选项

In SSMS 18.2 [edit.Duplicate] associated with [CTRL+E, V] and with [CTRL+D]. The easiest way is just remove association [CTRL+D] with [Query.ResultstoGrid]. Then this will state only for [edit.Duplicate]. After that you can use [CTRL+D] for duplicating rows.
I think it is not often case when you change saving result into grid or into file.
Option

十秒萌定你 2024-11-14 23:12:14

我使用这个 AutoHotKey 脚本来复制 CTRL + D 我习惯在 Visual Studio 中使用“重复行”功能:

; make ctrl+d duplicate line in SQL
SetTitleMatchMode, 2
#IfWinActive, Microsoft SQL Server Management Studio
^d::    
    ; save clipboard
    SavedClipboard = %clipboard%
    Send {Home}
    Send +{End}
    Send ^c
    ClipWait
    Send {End}
    Send {Enter}
    Send ^v
    clipboard = %SavedClipboard%
    return

I use this AutoHotKey script to replicate the CTRL + D "duplicate line" functionality I'm used to from Visual Studio:

; make ctrl+d duplicate line in SQL
SetTitleMatchMode, 2
#IfWinActive, Microsoft SQL Server Management Studio
^d::    
    ; save clipboard
    SavedClipboard = %clipboard%
    Send {Home}
    Send +{End}
    Send ^c
    ClipWait
    Send {End}
    Send {Enter}
    Send ^v
    clipboard = %SavedClipboard%
    return
卖梦商人 2024-11-14 23:12:14

我喜欢 @Matt Kemp 的 AutoHotKey 脚本解决方案,但我使用了这个脚本:

; make ctrl+d duplicate line in SQL
SetTitleMatchMode, 2
#IfWinActive, Microsoft SQL Server Management Studio
^d::    
    ; save clipboard
    Send ^c
    ClipWait
    Send ^v
    Send ^v
    return

I like @Matt Kemp's AutoHotKey script solution, but I used this script instead:

; make ctrl+d duplicate line in SQL
SetTitleMatchMode, 2
#IfWinActive, Microsoft SQL Server Management Studio
^d::    
    ; save clipboard
    Send ^c
    ClipWait
    Send ^v
    Send ^v
    return
染年凉城似染瑾 2024-11-14 23:12:14

这是我的 Autohotkey 脚本版本,允许 CTRL+D 复制当前行而不改变剪贴板。我第一次接触这个热键是在 Notepad++ 中,它让我着迷。一个常见的用例是想要用剪贴板中的值更改一行文本,但我首先想复制该行作为备份,我可以注释掉。

这个答案与 @Matt Kemp 的答案类似,但正如评论中所指出的,看似简单的脚本中存在一些不稳定的地方。

我的答案有以下差异:

  • 它包含睡眠延迟,从而提供更一致的结果。
  • 我已经设置了我的脚本,以便它可以支持一组应用程序,例如 SSMS、VBA、OneNote,甚至是像 JSFiddle 这样的编码网站。
  • 光标最终位于行的开头而不是结尾。如果您打算注释重复的行,这会很有帮助。
  • 我在脚本中留下了注释,以帮助调试它,并让您看到我使用它的一些历史记录。

我试图通过添加 sleep 语句来克服两个不稳定的问题。有时,当它将当前剪贴板保存到变量中时,它实际上将当前行保存到变量中,导致永远无法恢复原始剪贴板内容。在某些其他情况下,剪贴板中的值会粘贴到屏幕上,而不是复制当前行。我对脚本进行了修改,添加了一些延迟,这些延迟通常会给出我正在寻找的结果。它不像我想要的那么快,但由于结果不一致,我会稍微延迟一下。

我在 i7 计算机上使用 Windows 10 64 位。


设置标题匹配模式,2;窗口的标题可以在其中的任何位置包含 WinTitle 以进行匹配。

GroupAdd, ctrlD_group, Microsoft Visual Basic for Applications  ; VBA
GroupAdd, ctrlD_group, Microsoft SQL Server Management Studio   ; SSMS (AHK must be running as Admin for this to work)
GroupAdd, ctrlD_group, Microsoft Visual Studio                  ; Visual Studio
GroupAdd, ctrlD_group, ahk_exe notepad.exe                      ; Notepad
GroupAdd, ctrlD_group, ahk_class Framework::CFrame              ; OneNote
GroupAdd, ctrlD_group, ahk_class ENSingleNoteView               ; EverNote view
GroupAdd, ctrlD_group, JSFiddle                                 ; Website JSFiddle
GroupAdd, ctrlD_group, ahk_class OMain                          ; Access
GroupAdd, ctrlD_group, Advanced Editor                          ; Excel Power Query Advanced Editor 
GroupAdd, ctrlD_group, ahk_class XBasicDlgBox                   ; Alpha Anywhere - Edit Event dialog box
GroupAdd, ctrlD_group, [HTML Editor]                            ; Alpha Anywhere - HTML Editor
GroupAdd, ctrlD_group, [Code Editor]                            ; Alpha Anywhere - Code Editor


;=== Duplicate current line CTRL+D ===
; Applies to all application in the ctrlD_group
; Note that SetTitleMatchMode and GroupAdd have to be in the autoexecute section of the script (above first hotkey and/or return) 
#IfWinActive ahk_group ctrlD_group
^d::        ; CTRL+D
    ToolTip Duplicating current line...
    Temp:=ClipboardAll
    Clipboard = 
    SendInput {End}+{Home}
    Sleep, 50
    ;MsgBox,,, % "Selected text:" A_Tab gst() "`nClipboard:" A_Tab Clipboard
    SendInput ^c
    ClipWait, 1
    ;msgbox,,Before,% Clipboard ; This always shows the line to be duplicated even when the ^v pastes a different value.
    ;ClipWait, 2  ; This wasn't working consistently so I used Sleep instead.
    SendInput {End}{Enter}

; I tried to speed up the paste and  using ^v is faster but occasionally 
; would paste what was in the clipboard instead of the current row.  
; I decided to deal with it for now.  
; Removing SetKeyDelay, -1 may be the trick to having it work.

    ;SendRaw %Clipboard%  ; This works but is slow drawing on the screen.

    Sleep, 400
    SendInput, ^v{Home} ;paste plain text
    Sleep, 50   

    SendInput, {Home}
    Clipboard:=Temp     ; Restore the clipboard
    ;msgbox,,After,% Clipboard

    SoundBeep 300, 150 ; Let me know the ahk script is working and that the application CTRL+D has been overridden.
    ToolTip
Return
#IfWinActive

我觉得我需要经常调整这段代码,因为我注意到它在某些应用程序中表现得不稳定。如果您有可以进行测试的改进,请加入。

Here's my version of an Autohotkey script to allow CTRL+D to duplicate the current line without altering the clipboard. My first exposure to this hotkey was in Notepad++ and it grew on me. A common use case is wanting to alter a line of text with a value in my clipboard, but I first want to make a copy of the line as a backup I can comment out.

This answer is similar to the one by @Matt Kemp, but as noted in the comments, there is some flakiness in what appears to be a simple script.

My answer has these differences:

  • It contains sleep delays that give it more consistent results.
  • I have set up my script so it can support a group of applications, like SSMS, VBA, OneNote, and even a coding website like JSFiddle.
  • The cursor ends up at the beginning of the line instead of the end. This is helpful if you intend to comment the duplicated line.
  • I left comments in my script to help debug it and let you see some of the history I have toying with it.

There are two flaky issues that I am trying to overcome by adding sleep statements. On occasion, when it saves the current clipboard into a variable, it actually saves the current line into the variable, resulting in never restoring the original clipboard contents. On some other occasions, the value in the clipboard gets pasted on the screen instead of duplicating the current line. I have hacked the script to add some delays that typically give me the result I'm looking for. It's not as snappy as I'd like, but I'll take a little delay over inconsistent results.

I'm using Windows 10 64-bit on an i7 computer.


SetTitleMatchMode, 2 ; A window's title can contain WinTitle anywhere inside it to be a match.

GroupAdd, ctrlD_group, Microsoft Visual Basic for Applications  ; VBA
GroupAdd, ctrlD_group, Microsoft SQL Server Management Studio   ; SSMS (AHK must be running as Admin for this to work)
GroupAdd, ctrlD_group, Microsoft Visual Studio                  ; Visual Studio
GroupAdd, ctrlD_group, ahk_exe notepad.exe                      ; Notepad
GroupAdd, ctrlD_group, ahk_class Framework::CFrame              ; OneNote
GroupAdd, ctrlD_group, ahk_class ENSingleNoteView               ; EverNote view
GroupAdd, ctrlD_group, JSFiddle                                 ; Website JSFiddle
GroupAdd, ctrlD_group, ahk_class OMain                          ; Access
GroupAdd, ctrlD_group, Advanced Editor                          ; Excel Power Query Advanced Editor 
GroupAdd, ctrlD_group, ahk_class XBasicDlgBox                   ; Alpha Anywhere - Edit Event dialog box
GroupAdd, ctrlD_group, [HTML Editor]                            ; Alpha Anywhere - HTML Editor
GroupAdd, ctrlD_group, [Code Editor]                            ; Alpha Anywhere - Code Editor


;=== Duplicate current line CTRL+D ===
; Applies to all application in the ctrlD_group
; Note that SetTitleMatchMode and GroupAdd have to be in the autoexecute section of the script (above first hotkey and/or return) 
#IfWinActive ahk_group ctrlD_group
^d::        ; CTRL+D
    ToolTip Duplicating current line...
    Temp:=ClipboardAll
    Clipboard = 
    SendInput {End}+{Home}
    Sleep, 50
    ;MsgBox,,, % "Selected text:" A_Tab gst() "`nClipboard:" A_Tab Clipboard
    SendInput ^c
    ClipWait, 1
    ;msgbox,,Before,% Clipboard ; This always shows the line to be duplicated even when the ^v pastes a different value.
    ;ClipWait, 2  ; This wasn't working consistently so I used Sleep instead.
    SendInput {End}{Enter}

; I tried to speed up the paste and  using ^v is faster but occasionally 
; would paste what was in the clipboard instead of the current row.  
; I decided to deal with it for now.  
; Removing SetKeyDelay, -1 may be the trick to having it work.

    ;SendRaw %Clipboard%  ; This works but is slow drawing on the screen.

    Sleep, 400
    SendInput, ^v{Home} ;paste plain text
    Sleep, 50   

    SendInput, {Home}
    Clipboard:=Temp     ; Restore the clipboard
    ;msgbox,,After,% Clipboard

    SoundBeep 300, 150 ; Let me know the ahk script is working and that the application CTRL+D has been overridden.
    ToolTip
Return
#IfWinActive

I feel like I need to tweak this code every so often because I'm noticing it acting flaky in some application. Please chime in if you have a tested improvement that can be made.

吃颗糖壮壮胆 2024-11-14 23:12:14

对于 SSMS 18 按 Ctrl + E、V

默认情况下是快捷方式。
请参阅下面的屏幕截图:

在此处输入图像描述

For SSMS 18 press Ctrl + E, V

It's a shortcut by default.
See the screenshot below:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文