Rearrange tabs with the mouse in gvim - mouse

Is there any way in gVim to rearrange tabs by dragging and dropping them with the mouse? The behavior I'm looking for is that similar to tabs in Firefox and Chrome.
I know that it's possible to change tab order using :tabm n but that requires figuring out exactly how many tabs in you'd like to move to. Using the mouse would be more useful for this spatial task.
Any methods to move tabs left/right by one position would also be useful, since one could remap keys and move tabs without thinking too hard.

Here's what's in my vimrc regarding tabs:
" Move tabs with alt + left|right
nnoremap <silent> <A-Left> :execute 'silent! tabmove ' . (tabpagenr()-2)<CR>
nnoremap <silent> <A-Right> :execute 'silent! tabmove ' . tabpagenr()<CR>

Here is a function to move a tab to the left one position. Put it in your vimrc file and set up your keys as you see fit (to call it longhand, :execute TabLeft()).
Note that these functions "roll" tabs from first to last and last to first, respectively, so moving the first tab left makes it the last tab, and moving the last tab right makes it the first tab.
function TabLeft()
let tab_number = tabpagenr() - 1
if tab_number == 0
execute "tabm" tabpagenr('$') - 1
else
execute "tabm" tab_number - 1
endif
endfunction
...and to the right
function TabRight()
let tab_number = tabpagenr() - 1
let last_tab_number = tabpagenr('$') - 1
if tab_number == last_tab_number
execute "tabm" 0
else
execute "tabm" tab_number + 1
endif
endfunction

Thanks, and I have modified your code for my vimrc :
function ShiftTab(direction)
let tab_number = tabpagenr()
if a:direction == 0
if tab_number == 1
exe 'tabm' . tabpagenr('$')
else
exe 'tabm' . (tab_number - 2)
endif
else
if tab_number == tabpagenr('$')
exe 'tabm ' . 0
else
exe 'tabm ' . tab_number
endif
endif
return ''
endfunction
Then in my GVim, I map [ctrl+shift+left] to move left, [ctrl+shift+right] to move left
inoremap <silent> <C-S-Left> <C-r>=ShiftTab(0)<CR>
inoremap <silent> <C-S-Right> <C-r>=ShiftTab(1)<CR>
noremap <silent> <C-S-Left> :call ShiftTab(0)<CR>
noremap <silent> <C-S-Right> :call ShiftTab(1)<CR>

chris.ritsen's solution stopped working for me in vim v7.4 so here's a simpler alternative:
" Move tabs left/right
nnoremap <silent> <s-left> :-tabmove<cr>
nnoremap <silent> <s-right> :+tabmove<cr>

Ken Takata wrote a patch to do this https://groups.google.com/forum/#!msg/vim_dev/LnZVZYls1yk/PHQl4WNDAgAJ . One option is to download vim source code, aply this patch and compile.

Move Tabs to the Left / Right
This doesn't involve using a mouse, but it uses very simple keymaps for gvim:
noremap <A-[> :-tabmove<cr>
noremap <A-]> :+tabmove<cr>
Now you'll be able to move the current tab:
To the left using: Alt + [
To the right using: Alt + ]

Related

how to change lines at the same time - VS Code

I want to change same lines at the same time.
for example I want to change { backgroundColor: '#fff' } at anywhere on my file.js. (I don't want to use Replace)
Select { backgroundColor: '#fff' } with your mouse and press cmd + shift + L (or ctrl + shift + L) to select all occurrences of it in your file. Then, you can change them all at the same time.
Try
Ctrl + F (backgroundColor: '#ufff')
Alt + Enter
This will select every instance and give each an active cursor. Hit Esc to exit multi cursor mode.

Use commands onto the Manage Snippets plugin from Gedit

I have gedit and the Manage Snippets plugin and I would like to create a snippets to comment a line (it's easy, just add : "# $GEDIT_CURRENT_LINE", for python code for example) but, if the line is ever commented, I would like to uncomment it.
Is there a special syntax to use, I don't know, python or c++ statements like an if with a condition on $GEDIT_CURRENT_LINE ? Because any of code write on the snippets will be only print.
Ok, actually, I just find how a way to do it.
To use bash commands onto the manage snippets plugin, just use `.
For example, in my case, to know what is the first caracter on the line : `${GEDIT_CURRENT_LINE:0:1}` and, with the if statement :
``if [ ${GEDIT_CURRENT_LINE:0:1} == "#" ]; then echo ${GEDIT_CURRENT_LINE:2}; else GEDIT_CURRENT_LINE_STR=$GEDIT_CURRENT_LINE; echo "# $GEDIT_CURRENT_LINE_STR"; fi``
this snippets will comment the line or uncomment it if it is ever commented. (Just as Notepad++ do it).
Edit : you have to create a new variable with the line to rewrite it : GEDIT_CURRENT_LINE_STR=$GEDIT_CURRENT_LINE;. Without that new variable, the current line text can be interpreted as a command and then, just erase the line because of an error. (I updated the code above)
Edit2 : here a snippets to comment/uncomment all the selected lines with python (and not just on as before) :
$<
AllLines = $GEDIT_SELECTED_TEXT.split('\n')
if AllLines == ['']:
AllLines = $GEDIT_CURRENT_LINE.split('\n')
NewLines = []
for line in AllLines:
if line[0:2] == '# ':
NewLines += [line.replace('# ', '')]
elif line[0] == '#':
NewLines += [line.replace('#', '')]
elif line[0] != '#':
NewLines += ['# ' + line]
return '\n'.join(NewLines)
>

AutoHotkey's for the arrow keys

I would like to hold
alt + spacebar + U for the up key
alt + spacebar + H for the left arrow key
alt + spacebar + J for the right arrow key
alt +spacebar + N for the down arrow
is this possible to do with AutoHotkey?
Hello and welcome to AutoHotkey,
you might want to have a look at the basic introduction to the heart of AHK, Hotkeys:
https://www.autohotkey.com/docs/Hotkeys.htm
Configuring hotkeys which do nothing but send another key is fairly simple. For example, alt + spacebar for the up key could be translated into
!Space::
send {up}
return
(note that alt is a modifier and can be written as !)
or short form:
!Space::send {up}
spacebar + U for the up key would be Space & U::send {up}.
But you are seeking for 2 keys PLUS a modifier (alt). For a hotkeylabel triggered by more than just two keys (alt + space + u), you'll need a workaround:
!Space:: ; once alt + space was pressed, ...
while(getKeyState("alt") || getKeyState("space") || getKeyState("u")) { ; ... while either of these is being pressed down, ...
hotKey, *u, altSpaceU, ON ; u should now send {up}
}
hotKey, *u, altSpaceU, OFF
return
altSpaceU: ; note: this is a label, no hotkey
send {up}
return
Please, don't be undeterred by this. AutoHotkey is actually quite powerful and easy to learn. Sadly, (afaik) this is the only working way to solve more-than-two-key-hotkeys.
EDIT
jesus why didnt anybody tell me..
#if getkeystate("alt")
!space::send {up}
#if
is obviously a way better solution
this was the solution
!Space::
send {up}
return

mapping the shift key in vim

I'm having an issue when mapping the Shift key in VIM. I want Ctrl+L to behave differently than Ctrl+Shift+L
so I have this
" for insert mode remap <c-l> to:
" Insert a hash rocket for ruby
" Insert a -> for php
" for coffee the shift key decides
function! SmartHash(...)
let shift = a:0 > 0
let ruby = &ft == 'ruby'
let php = &ft == 'php'
let coffee = &ft == 'coffee'
if php
return "\->"
end
if coffee
return shift ? "\ =>\n" : "\ ->\n"
end
if ruby
return "\ => "
end
return ""
endfunction
imap <c-l> <c-r>=SmartHash()<cr>
imap <C-S-L> <c-r>=SmartHash(1)<cr>
...but it's just triggering the second mapping whether I have the Shift key pressed or not.
Updated based on accepted answer
" for insert mode remap <c-l> to:
" Insert a hash rocket for ruby
" Insert a -> for php and coffeescript
" double tapping does alternate symbol for php and coffescript
function! SmartHash(...)
let alt = a:0 > 0
let ruby = &ft == 'ruby'
let php = &ft == 'php'
let coffee = &ft == 'coffee'
if php || coffee
return alt ? "\ =>\n" : "\ ->\n"
end
if ruby
return "\ => "
end
return ""
endfunction
imap <c-l> <c-r>=SmartHash()<cr>
imap <c-l><c-l> <c-r>=SmartHash(1)<cr>
Due to the way that the keyboard input is handled internally, this unfortunately isn't possible today, even in GVIM. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.
Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8
But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.
I usually work around this by starting my alternate mapping with g, e.g. <C-l> and g<C-l>, but that won't work in insert mode. In your case, with a little bit of additional logic, you could make a second <C-l> at the same position change the previously inserted -> to =>, so that you get the first alternative via <C-l>, and the second via <C-l><C-l>.

_Click on TabHost view is not working

On a TabHost view I found there are 3 events. Click, LongClick and TabChanged. I found that only TabChanged works and I would like to use Click since the user may tap a tab and go back to the home screen and may want to tap the same tab again.
Here is the Sub Routine I used with TabChanged, but I would like to use Click instead. Maybe I need to change something in my code other than just changing the _TabChanged to _Click. If so, could you let me know what to change?
Sub tbhPagesEventHandler_TabChanged
ToastMessageShow(tbhPages.CurrentTab,False)
' These will make the code easier to read.
'-----------------------------------------
Dim intVisitsTab As Int : intVisitsTab = 0
Dim intMaintenanceTab As Int : intMaintenanceTab = 1
' Start the activity the user wants.
'-----------------------------------
Select tbhPages.CurrentTab
Case intVisitsTab
StartActivity("Visits")
Case intMaintenanceTab
StartActivity("Maintenance")
End Select
End Sub
I see you found a solution, based on your comment, but thought I'd post this for future readers in case it was useful.
The 'TabHost.Click' event fires when the content of the TabHost tab is clicked, not the tab itself.
If you use the following for your code, you can see the difference (this uses tbPages as the TabHost variable):
' Displays the 0-based index of the tab being activated
Sub tbPages_TabChanged
Msgbox("Current tab is " & tbPages.CurrentTab, "")
End Sub
' Fires when you click inside the content of the tab page,
' not on the tab itself.
Sub tbPages_Click
Msgbox("Current tab is " & tbPages.CurrentTab, "")
End Sub
This means you can use the CurrentTab property to determine which page the user has selected, and react accordingly:
Sub tbPages_TabChanged
Dim TabIdx as Int
TabIdx = tbPages.CurrentTab ' Get the tab just activated
Select TabIdx
Case 0
' First tab is now active
Case 1
' Second tab active
Case 2
' Third tab active
Case Else
MsgBox("Something is badly wrong! We have only three tabs", "HEY")
End Select
End Sub