Adding a keybind that will split Nvim window into two with vimwiki diary - neovim

As the title says.
I want to be able to open from anywhere a split window with today's diary ready to write.
I'm pretty new to NVim so excuse my naivete.
I have written in my vimrc the following:
nnoremap <leader>nd <C>wv2<leader>w<leader>w
I want to bind <leader>nd (as in new diary) to the two actions: <C>wv (a vertical window split) followed by 2<leader>w<leader>w (accessing my 2nd wikis diary)
So when the motion is complete, I should have today's diary open split from what I am presently working on, with my cursor in the diary.
Is this even the right approach to executing something like this or do I need to do something entirely different?
I hoped it would do what I wanted it to do. But instead NVim isn't recognizing what I'm inputting at all. Only recognizing that I hit n. And thus does the last-search-action that is the default action corresponding to n in vims normal mode.

Related

Copy/move rest of the current line to the end of next line

I have Googled a lot but cannot find one feature in VScode that I would appreciate greatly:
Copy (or move) rest of the current line (i.e. not the entire line) to the end of next line
Example:
What I have - note the cursor
What I need - again note the cursor
So ideally, with a single keyboard shortcut, I would copy (or move) the remainder of the current line (= "ABC1" in the example) to the end of the next line. Any ideas how to do that? Is it available within VScode, or is there a relevant extension? Thanks!
Since you're asking if there's an extension for it, the vim extensions should at least be mentioned. I have no intention or desire to start an(other) editor war, though.
What you're asking would be trivial in vim (y$, yank to end of line) and there are at least two very popular vim extensions for vscode that will bring the vim keybindings as well as the power of configurable commands and bindings in vim to vscode.
Yes, it would require some effort to learn the "vim way" of doing things, but the upside is that you'll probably never have to re-learn the bindings if you move between editors/IDEs since they are available in pretty much every editor and they make editing very fast and precise.
Drag and drop by mouse
Why are you not using mouse drag and drop text?
Select the text and drag it by mouse where you need
Otherwise, if you have multiple times then you can solve it in two steps.
Step1:
Replace all Name by Name(ctrl+enter)SecretCode
Step2:
Replace all "(ctrl+enter)SecretCode by "
Done

how to avoid creating a new line when hitting return in auto complete mode

auto-complete in my emacs works great. But there is one annoyance. If I have finished a word correctly like "abc", but in the mean time there is another matching word called "abcd". The menu showed two options with the first one "abc" selected as default. At this time, if I hit RET, it will select "abc" as well as creating a new line. This is annoying. I want it to be just complete the selection when I hit RET. And create a new line only if I hit RET again. Is there a way to set up auto-complete to behave like that

Ansi-coloured file editing

Context
Have some transcript files from terminal interaction, obtained using traditional Unix command "script".
Those transcripts contain lots of control character (like backspace when editing shell commands), and lots of color code sequences as result of running various commands. Occasionally, even colorful full-terminal (ncurses-based) applications like "emacs -nw" or "aptitude" were run.
At program runtime, TERM environment variable was set as "xterm".
Need 1: read (more or less solved)
I need to read those files again and sometimes copy-paste some small parts.
The trouble is : while one color change here and there is not so much of a problem, their actual density makes the output barely readable. Worse, edited command lines (with cursor jumps and edited words) are completely unreadable.
"Okay" solution
Browse through files using e.g. "less -r". Paging forward in the same terminal setup reproduces the various color and character style.
But many other features come out more or less broken, e.g. search backwards produces jumbled terminal output, often have to pres "Ctrl-L" to clean thing up.
Need 2: editing
My preferred editor is emacs. Some people have had a similar situation when running the shell inside emacs, e.g. Something wrong with Emacs shell.
Here is not the same situation. Examples of differences: here we don't have to run an actual shell, but we need to move cursor freely like in usual editing.
Editing here means easily open such a transcript file in editor and then:
at all times through editing, see character changes (color, attributes) as conveyed by the terminal codes
(optional) some character that are neighbour on the terminal grid but are separated in file by some control characters would have a visual hint about this
ability to insert some text,
delete sections,
use all editor features like search/replace etc.
copy & paste to & from file (including to external programs, which would receive just plain text)
in my wildest dreams, some kind of "flatten" action, like select a sequence with a heavily edited command line and replace it with a simple series of characters as if it was typed in one run. "Visual hints" mentioned above would disappear.
Type Alt-: to evaluate something in the minibuffer. Evaluate (ansi-color-apply-on-region (point-min) (point-max)) and it will convert ansi color codes to be font colors.

Elisp: Buffer Menu

Every time I hit CTRL + Left click in Emacs I get a list of all opened buffers.
How can I change the default output in order to pop up a menu customized by myself, I have something like this in mind:
Buffer Menu
-----------
dot.C > ex1.c
dot.java ex2.c
dot.lisp ex3.c
dot.?
...
-----------
For instance, every .c file would be stored inside dot.c entry as showed above.
Are you saying that you'd have one menu for .c files, and another for .h files, even though they're both using the same major mode? The standard menu categorizes based on major mode, so I think you'd need custom menu code to achieve that.
A hacky approach which springs to mind would be to define minimal derived major modes in order to associate each with a different filename extension, and then you could use the existing menus to achieve your goal.
If you didn't mean that, and grouping by major mode is fine, then the current system should already provide a solution.
In either case, the following may prove useful:
How do I set the number of items in the mouse buffer menu in Emacs?
M-x apropos-variable RET mouse-buffer-menu RET

Emacs reselect region, as Vim shortcut 'gv' does

In vim, visual block can be recall by 'gv' command so that multiple commands can be applied easily. (such as, comment out, then indent, then do_something_fun).
In Emacs, how can this be achieved?
[C-xC-x] only works when current cursor position stays where previous block ended.
If previous block was changed, the closest is to go through 'point-to-register' and 'jump-to-register'.
Just I am curious if there is an Emacs built-in command making this in one shot.
If Transient Mark mode is off, the region is always active. If it's on (which it sounds like is your situation), you can set mark-even-if-inactive to non-nil to allow region commands to work while the region isn't highlighted.
However, note you also can cycle back through previous mark positions using C-u C-SPC -- this will pop the mark ring. Once you're back to where you want to be, C-x C-x will rehighlight the region you want. (It may take a little bit of playing with this feature to get a feel for it, but it's why I can't switch away from Emacs now.)
If I understand correctly what you are asking for, then you don't need to do anything. When you select a region in emacs, it stays selected until you select a new one. So you could select the region and then perform as many actions as you want.
Sounds like you're looking for the secondary selection, which stays put even as the region might change. (It stays put until you move it.)
See:
the Emacs manual, node Secondary Selection
Emacs wiki page Secondary Selection
library second-sel.el:
Also narrow-to-region (CTRL-x n n ) applies every command from then on just to that region- you can't hurt the rest of the buffer, it doesn't even show. After done editing , widen (CTRL-x n w )to get back the whole buffer.
CMM
If you use evil-mode, just press gv like in vim.
Since the answers here and for other similar SO questions didn't help for me (CUA-mode, Emacs 24, not only indent-rigidly), I continued searching and finally found a reselect-last-region defined in this collection of custom function (starting line 670). That worked like a charm for me - and hopefully does for others still arriving here.