YouCompleteMe Go: Navigating location list with a single error - vim

The problem, step-by-step.
I'm using Vim with YouCompleteMe and vim-go plugins to edit a Go source file:
package main
import "fmt"
func main() {
fmt.Println("foo")
}
I delete the import line, creating an error:
package main
func main() {
>> fmt.Println("foo")
}
I want to jump to the line where the error is detected, so I :lnext, but get a message E553: No more items. Hmm...
With :lopen I can see that location list is populated alright, with a single entry regarding missing import. The problem is, vim assumes I'm "there" already (at the first entry), and doesn't move the cursor neither forwards nor backwards. Is there a way around this annoyance?
If there are more errors than one, I can navigate the location list as expected with :lne, etc.

Using :ll does the trick in case of a single error.

Related

Vim rename variable

Most people say vim is greatest editor.
But is there any way to rename variable as fast as sublime.
Example:
function f($items) {
$items;
....
$items;
}
In sublime:
Go to items variable
click ctrl+d 2 times
rename variable
In VIM:
Search for /items
cw
write the new name
"n" for next occurrence and then "." to repeat
In vim obviously the keystrokes are more.
Does anyone knows easier and faster rename variable method?
Thank you
There are few solutions:
Change command
Go to items and then hit:
*Ncgn{new name}<Esc>
And then you can . through rest of the files.
Plugin
I have written plugin which simplifies this flow sad.vim which simplifies above to:
siw{new name}<Esc>
And then you can . through rest of the occurrences.
Substitute
Select function body by vi{ and then call:
:'<,'>s/items/{new name}/g
Language Server
If your language has Language Server that supports renames then you can use one of the many LS clients for Vim out there and use the support from there.
The point is: in vim the moviment towards the target change point happens without touching the mouse, and it can also be made via terminal through a ssh session. You should also consider this. I have the following map:
:nnoremap c* *<C-o>cgn
Once you hit the variable just type c* followed by the new name, Esc and dot

Hiding tab characters in Vim

I've just begun learning Go, and upon running go fmt, I am finding tab ^I characters appear in my code:
package main
import "fmt"
func main() {
^Ifmt.Println("Hello world!")
}
Is there a way I can configure Vim to not display these characters, while still preserving the tabs in the file itself?
Following Amadan's suggestion, I edited the file that :verbose set list? returned, which for me is ~/.vim/init/options.vim. Removing set list solved the problem for me
Just remove this line in your configuration file:
:set listchars=tab:\(whatever chracter)\
set list may be useful later for character editing. I wouldn't recommend just deleting it without knowing what you are doing.

Strange behaviour on full stop (.) whilst in insert mode vim

I am using vim with Pymode to write python source code. I have the come across some strange behaviour which is intermittent but very annoying.
If I am in insert mode and type a full stop (e.g. self.method()), whilst typing self vim prints at the bottom
-- Keyword completion (^N^P) The only match
As soon as I type the full stop vim seems to freeze momentarily, then
-- INSERT -- appears at the bottom, but my cursor is now on the full stop, so that when I write method() it actually appears behind the full stop. I keep having to go back and move the full stop.
I can't figure out when it happens and when it doesn't, when I open a new file it doesn't happen straight away.
Any ideas on what may be causing this? I have only noticed it recently.
This is a problem caused by some combination of pymode and rope. Either way putting
let g:pymode_rope_lookup_project = 0
in your vimrc solves it apparently. See here for the pymode issue.

Stop highlighted text from autofilling sublime's goto anything search

I use goto anything quite a bit, but mainly for searching for files. It goes a little something like this:
cmd p, immediately start typing file name
shit, there's a random string of junk at the beginning of my search
backspace, backspace, backsp....
type file name
receive list of file choices that I wanted to begin with
Is there a setting I can set somewhere to make the behavior a little more sane for my use-case?
Thanks.
I don't believe that's a default behavior. What plugins do you have installed? If you log the commands (sublime.log_commands(True) in the ST console), what do you see? I get command: show_overlay {"overlay": "goto", "show_files": true}. If it's not that, a plugin may be binding to super + p. If that's the case, you may either remove the plugin, or create a user key binding with the proper command/arguments.

How do you edit existing text (and move the cursor around) in the terminal?

I saw this demo once that printed out a paragraph of text (like you'd get when typing some-command --help), and it then jumped back up to a couple keywords in the text and changed the text color, after it was already printed out in the terminal.
That seems crazy to me. How did they do that?
Starting to think about it, I guess stdout and stdin are technically an "IO stream", so maybe that's a persistent variable that keeps track of the position of a cursor? I remember doing something like that when building a language parser.
The goal would be this: say you type the following into the console, and it outputs a blank array because in Node.js, it's all async and we don't want to write the async function everytime in the console:
$ node app.js
> App.User.all()
=> []
Then when the async callback executes, you go back and edit the => [] to include the result:
$ node app.js
> App.User.all()
=> [#<User id:1>, #<User id:2>...]
That would be awesome to at least know how to implement, even if there are a lot of other issues to work through (unrelated to this question. And I know you can define a global callback and do something like App.User.all(_c)).
How do you edit the terminal output after it's already been printed?
Finally found that "demo":
https://github.com/asyncly/cdir/blob/223fe0039fade4fad2bb08c2f7affac3bdcf2f89/cdir.js#L24
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html
http://ascii-table.com/ansi-escape-sequences-vt-100.php
Position the Cursor: \033[<L>;<C>H or \033[<L>;<C>f (puts the cursor at line L and column C)
Move the cursor up N lines: \033[<N>A
Move the cursor down N lines: \033[<N>B
Move the cursor forward N columns: \033[<N>C
Move the cursor backward N columns: \033[<N>D
Clear the screen, move to (0,0): \033[2J
Erase to end of line: \033[K
Save cursor position: \033[s
Restore cursor position: \033[u
If you are working in Mac OS X, I believe the program Eddie does something like "edit terminal output after it's already been printed". (see "Eddie (text editor) at Wikipedia" ).
Under the file menu, choose "New" and then under "Settings/Document Settings..." choose "Shell Window". After that try a couple of unix commands: date, ls, cal, etc. Then put your cursor and edit these.
I would have tried with Node but I could not install it (Node) under Mac OS X 10.5.8.

Resources