Neovim - Closing buffers/panes like Ag leaves trail of it behind - macos

I am using NeoVim in iTerm. Whenever I open any temporary panes like Ag to search for some text in my project, after selecting an occurrence from the list, I notice it leaving some parts of the old buffer left behind. (screenshot attached) It gets fixed when I navigate through the entire affected area of the buffer using j,k or Up,Down.
My vimrc: https://github.com/AvinashKrSharma/dotfiles/blob/master/vimrc

Related

How to scroll completely to the top of large terminal text buffers w/o adding additional dependencies?

I have a couple shell scripts which output git diffs which can get very long. When this happens, the terminal is left scrolled to the bottom of that text.
Ideally I'd like to programmatically scroll to the very top of the text buffer in a way which is as platform independent as possible, without requiring additional software installation.
The following works to move cursor to top of the currently visible text, but not to the top of the entire text buffer:
printf '\e[H'
This does basically the same thing:
printf '\e[0;d'
But neither of these scroll completely to the top, they just move the cursor to the top of the visible text.
My platform dependent (macOS) workaround is here:
https://github.com/montehurd/gitshorts/blob/main/utility#L3
Any pointers for how to scroll to the very start of the text buffer?

How to navigate back to the last cursor position with respect to *same* file in Visual Studio Code?

Alt+Left navigate backs to the last cursor position and if the last cursor position was in a different file then it navigates to that file.
But, I want to navigate to the last cursor position with respect to the currently focused file only. It is really useful when I have 2 split file editors and want to navigate back exclusive to each other.
Is it possible?
I hope you understand the question, let me know if further explanation is required.
Basic Functionality
You can use the cursor undo / cursor redo commands via the command palette.
Undo also comes with a keyboard shortcut by default (Mac: cmd+u, Windows/Linux: ctrl+u), and you can configure a keybinding for redo.
Advanced Functionality
Note, however, that the file's cursor history is only saved while it has focus in an editor group. So if you have split editors, multiple focused files can have their own cursor history saved. And if the same file is opened and focused in two different editor groups, it has two different cursor history states.
But as soon as you focus another file in an editor group, the previously focused file will lose its cursor history (in that editor group).
The VSCode team is currently working on a variety of open issues to improve local history across the board, but I don't believe that saving cursor history for blurred (or closed) files is in the plans yet. If you need that functionality, you may want to create a feature request.
Note, with VSCode 1.40 (Oct. 2019):
The Soft Undo command has been renamed to Cursor Undo
This action is useful, for example when using Ctrl+D to select the next match and going one time too far, as it undoes only the last cursor state change.
Additionally, we now have added Cursor Redo, which redoes the previously undone cursor state change.

Visual Studio - Scroll AND move cursor

As a preface I'm using ViEmu although I dont think this affects anything. I would simply like to scroll up in the Text Editor along with moving the cursor to the relative screen position.
As an example, if my text editor displays 100 lines of viewable code (1 - 100) and my cursor is on line 20, when I scroll down to the next viewable 100 lines (101 -200) I would like the cursor to be at 120.
Using the VS command Edit.ScrollDown scrolls the code down as expected but leaving the cursor at line 20 instead of moving it to 120. Is there another command to use or any way to alter this behavior?
As noted in the question you seem to be wanting to re-map Page Down to another key (due to limited keyboard).
To identify which command a key is mapped to open the keyboard customisation dialogue and type in the current key into the short key text box and then look at what it is currently mapped to.
Unfortunately this doesn't work for page down (control-page down does work, but that doesn't help here).
Entering "page" into the command filter does: Edit.PageDown is mapped to Page Down in the text editor. Map this command to another shortcut.

Can I make emacs grep windows just use the other window to open files in?

I've got emacs in front of me.
I've run a find-grep, and it's got many hits, which are displayed in a window. The file names are displayed in green as hyperlinks.
I make that the only window, with C-x 1.
If I click on a file name, the window splits vertically, and the file with the found text is displayed in the other window.
If I click on further filenames, then the new file replaces the old file, which is what I want to happen.
So far, so good...
However if I resize the windows, then emacs will periodically (when I click) split one of the two windows again, rendering the display difficult to read. It will then cycle opening new files between the two new windows. Occasionally it will open more windows and make the situation worse. If I close any of these new windows they just get reopened again.
In fact sometimes this perverse behaviour happens even if I don't resize anything. It just seems to happen more often if I do.
I would like emacs to stop buggering around and just have one find-grep window and one 'display' window, and always replace the display window with the new file. I would also like to be able to set these windows to the sizes that seem most convenient.
Is there any way to achieve this?
Or can anyone point me to an essay on how the whole (replace the contents of this window/replace the contents of a different window/create another window by splitting) thing works, so I can go and hack it sane.
Short fix:
Try doing this
(setq split-height-threshold nil
split-width-threshold nil)
This will prevent Emacs from splitting windows automatically (horizontally or vertically). This might be undesirable in other situations, but this should do the job. Try it for a week or so and see if it disrupts your flow.
Also, I found that if the point was in one of the windows, and I clicked on a link, the file opened up in the next window (if any).
So, if you want to make the file open in the right window (when you have more than one window), you can ensure that the point is in the window before the window you want.
Longer answer:
OK. I was able to reproduce the problem. The thing is the window showing the files is pretty big (wide or tall) because you resized it and Emacs sees that the width or height is greater than the respective threshold and splits it likewise. So, we have to either make the threshold higher or disallow the behaviour completely.
And, just to answer the last few questions:
To get current window - (selected-window)
To get next window - (next-window)
To select a window - (select-window foo-window)
To get the buffer of the current window - (current-buffer)
To get the buffer of some window - (window-buffer foo-window)
To set a buffer for a window - (set-window-buffer foo-window bar-buffer)
I'm sure you can hack together decent window/buffer management functions using these functions.
You can use C-h f to get more details on each of these functions.
Also check out the Elisp manual - http://www.chemie.fu-berlin.de/chemnet/use/info/elisp/elisp_26.html

Are these NotePad++ features available in TextMate?

I'm a NotePad++ user, new to TextMate.
There are some features that I really like in NP++ but couldn't figure out if TextMate support them.
Double click on a variable and have all instances highlighted
View 2 text windows side by side
Drag a file onto another opened Window
For this one, I don't know how to generate a screenshot ;-p. Basically, you can drag a file from Windows Explorer and drop it into NP++ to have it opened.
A lot of long time TextMate users are leaving TextMate land, actually. So, I'm not sure it's the right time to move to TextMate.
Emacs and Vim both do what you want and more. If you can afford the learning curve it's definitely worth it.
As for your question:
View 2 text windows side by side
You can have two or more windows for the same document. Assuming you are in a "project" right-click your file in the drawer and choose Open "foo.ext" in New Window. The two "views" contents are more or less in sync but doing cool things like columnar editing tends to break the syncing.
Due to how Mac OS X manages windows, the new window will probably be too large/too small and/or placed in a less than useful place. I use ShiftIt system wide to manage my windows and in such a case have them the same size side by side.
Double click on a variable and have all instances highlighted
What do you use this for? Is this visual highlight or non-contiguous selection?
Type ctrlw to select the word, then ⌘e to make the word your search term, then ⇧⌘f or Edit > Find > Find in Project… It will show all instances of the search term in another window. You can then "jump" to any occurence and do whatever you want.
If you only want to jump from occurence to occurence, select the word then type ⌘e then ⌘g to jump to the next occurence.
Another way is to type ctrls, a little text field appears at the bottom of your window where you can type a word and see its first occurence selected in real time. Repeatly typing ctrls will cycle through the occurences.
Drag a file onto another opened Window
You can drag & drop a file on TextMate's icon in the Dock. You can also right-click the file and choose Open with TextMate *or Open with…*. If you are in a "project" you can right-click and choose Add Existing Files…. Opening multiple files in TextMate will automatically create a "project" for you.
View 2 text windows side by side
I just tried this and it doesn't seem to recognize this functionality. the only time any sort of "add" icon came up was when I dragged the file into an open document and then released, but that resulted in adding the contents of the file into the document.
I just did a quick google search for "textmate split view" and it still doesn't seem to be supported according to some of the answers i found (one from macromates wiki).
Double click on a variable and have all instances highlighted
This also doesn't seem to be supported. This post suggests using the command + f (find), put the word into find, then command + g to jump to the next instance of that word.
There are definitely some things that can be added to textmate to make it more robust. If you are looking for something similar and are on a windows machine, you should check out e text editor. I loved that editor when I was working on a windows machine - split view is supported, but not sure about the highlighting. One thing that e also beats out textmate is the real time regular expression highlighting.

Resources